Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
add content-length for client requests
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFrench committed Jul 26, 2018
1 parent 1454b6c commit fb1e594
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions evhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -5358,6 +5358,7 @@ evhtp_make_request(evhtp_connection_t * c, evhtp_request_t * r,

obuf = bufferevent_get_output(c->bev);
r->conn = c;
r->method = meth;
c->request = r;

switch (r->proto) {
Expand All @@ -5373,15 +5374,27 @@ evhtp_make_request(evhtp_connection_t * c, evhtp_request_t * r,
evbuffer_add_printf(obuf, "%s %s HTTP/%s\r\n",
htparser_get_methodstr_m(meth), uri, proto);

evhtp_headers_for_each(r->headers_out, htp__create_headers_, obuf);
evbuffer_add_reference(obuf, "\r\n", 2, NULL, NULL);

if (evbuffer_get_length(r->buffer_out)) {
if (evhtp_header_find(r->headers_out, "content-length") == NULL) {
char out_buf[64] = { 0 };
size_t out_len = evbuffer_get_length(r->buffer_out);

evhtp_modp_sizetoa(out_len, out_buf);

evhtp_headers_add_header(r->headers_out,
evhtp_header_new("Content-Length", out_buf, 0, 1));
}


evbuffer_add_buffer(obuf, r->buffer_out);
}

evhtp_headers_for_each(r->headers_out, htp__create_headers_, obuf);
evbuffer_add_reference(obuf, "\r\n", 2, NULL, NULL);


return 0;
}
} /* evhtp_make_request */

unsigned int
evhtp_request_status(evhtp_request_t * r)
Expand Down

0 comments on commit fb1e594

Please sign in to comment.