diff options
author | Liao Tonglang <liaotonglang@gmail.com> | 2023-03-05 23:59:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-05 16:59:21 +0100 |
commit | 6bfa58055919a12acec070cdecef1bfb69f4e4d2 (patch) | |
tree | 8d831e0f74e2cd609879e8e8f6d89fb03d947386 | |
parent | 185e2f009bbffff9bfa2f4d633ddbea777ab111b (diff) | |
download | libevent-6bfa58055919a12acec070cdecef1bfb69f4e4d2.tar.gz |
http: Reduce times of checking if response has body (#1395)
Use a variable 'need_body' to store the result of
evhttp_response_needs_body(), then use the variable instead of call the function again.
-rw-r--r-- | http.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -599,6 +599,8 @@ evhttp_make_header_response(struct evhttp_connection *evcon, struct evhttp_request *req) { int is_keepalive = evhttp_is_connection_keepalive(req->input_headers); + int need_body = evhttp_response_needs_body(req); + evbuffer_add_printf(bufferevent_get_output(evcon->bufev), "HTTP/%d.%d %d %s\r\n", req->major, req->minor, req->response_code, @@ -616,8 +618,7 @@ evhttp_make_header_response(struct evhttp_connection *evcon, evhttp_add_header(req->output_headers, "Connection", "keep-alive"); - if ((req->minor >= 1 || is_keepalive) && - evhttp_response_needs_body(req)) { + if ((req->minor >= 1 || is_keepalive) && need_body) { /* * we need to add the content length if the * user did not give it, this is required for @@ -630,7 +631,7 @@ evhttp_make_header_response(struct evhttp_connection *evcon, } /* Potentially add headers for unidentified content. */ - if (evhttp_response_needs_body(req)) { + if (need_body) { if (evhttp_find_header(req->output_headers, "Content-Type") == NULL && evcon->http_server->default_content_type) { |