summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiao Tonglang <liaotonglang@gmail.com>2023-03-05 23:59:21 +0800
committerGitHub <noreply@github.com>2023-03-05 16:59:21 +0100
commit6bfa58055919a12acec070cdecef1bfb69f4e4d2 (patch)
tree8d831e0f74e2cd609879e8e8f6d89fb03d947386
parent185e2f009bbffff9bfa2f4d633ddbea777ab111b (diff)
downloadlibevent-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.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/http.c b/http.c
index 43879f39..22a794f1 100644
--- a/http.c
+++ b/http.c
@@ -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) {