From 4651cd8b7c10d18bc745b84ebc7a55aad07d6077 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 10 Jun 2009 16:00:08 -0700 Subject: Optimize body-less GET/HEAD requests (again) No point in making syscalls to deal with empty bodies. Reinstate usage of the NULL_IO object which allows us to avoid allocating new objects. --- ext/unicorn/http11/http11.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'ext') diff --git a/ext/unicorn/http11/http11.c b/ext/unicorn/http11/http11.c index cd7a8f7..f640a08 100644 --- a/ext/unicorn/http11/http11.c +++ b/ext/unicorn/http11/http11.c @@ -324,10 +324,17 @@ static void header_done(void *data, const char *at, size_t length) } rb_hash_aset(req, global_server_name, server_name); rb_hash_aset(req, global_server_port, server_port); + rb_hash_aset(req, global_server_protocol, global_server_protocol_value); /* grab the initial body and stuff it into the hash */ - rb_hash_aset(req, sym_http_body, rb_str_new(at, length)); - rb_hash_aset(req, global_server_protocol, global_server_protocol_value); + temp = rb_hash_aref(req, global_request_method); + if (temp != Qnil) { + long len = RSTRING_LEN(temp); + char *ptr = RSTRING_PTR(temp); + + if (memcmp(ptr, "HEAD", len) && memcmp(ptr, "GET", len)) + rb_hash_aset(req, sym_http_body, rb_str_new(at, length)); + } } static void HttpParser_free(void *data) { -- cgit v1.2.3-24-ge0c7