Browse Source

[core] rename content_length to reqbody_length

rename content_length to reqbody_length in request,
to more easily differentiate request body length
from response content_length
personal/stbuehler/ci-build
Glenn Strauss 2 years ago
parent
commit
af5df35275
  1. 14
      src/connections-glue.c
  2. 18
      src/connections.c
  3. 8
      src/gw_backend.c
  4. 10
      src/http-header-glue.c
  5. 16
      src/mod_cgi.c
  6. 8
      src/mod_fastcgi.c
  7. 12
      src/mod_proxy.c
  8. 6
      src/mod_scgi.c
  9. 4
      src/mod_status.c
  10. 2
      src/mod_uploadprogress.c
  11. 14
      src/mod_webdav.c
  12. 2
      src/mod_wstunnel.c
  13. 12
      src/request.c
  14. 2
      src/request.h
  15. 8
      src/response.c
  16. 2
      src/t/test_request.c

14
src/connections-glue.c

@ -203,7 +203,7 @@ static handler_t connection_handle_read_post_chunked(connection *con, chunkqueue
* making trailers available to CGI and other backends*/
}
chunkqueue_mark_written(cq, (size_t)hsz);
con->request.content_length = dst_cq->bytes_in;
con->request.reqbody_length = dst_cq->bytes_in;
break; /* done reading HTTP chunked request body */
}
@ -449,25 +449,25 @@ handler_t connection_handle_read_post_state(connection *con) {
}
}
if (con->request.content_length < 0) {
if (con->request.reqbody_length < 0) {
/*(-1: Transfer-Encoding: chunked, -2: unspecified length)*/
handler_t rc = (-1 == con->request.content_length)
handler_t rc = (-1 == con->request.reqbody_length)
? connection_handle_read_post_chunked(con, cq, dst_cq)
: connection_handle_read_body_unknown(con, cq, dst_cq);
if (HANDLER_GO_ON != rc) return rc;
}
else if (con->request.content_length <= 64*1024) {
else if (con->request.reqbody_length <= 64*1024) {
/* don't buffer request bodies <= 64k on disk */
chunkqueue_steal(dst_cq, cq, (off_t)con->request.content_length - dst_cq->bytes_in);
chunkqueue_steal(dst_cq, cq, (off_t)con->request.reqbody_length - dst_cq->bytes_in);
}
else if (0 != chunkqueue_steal_with_tempfiles(dst_cq, cq, (off_t)con->request.content_length - dst_cq->bytes_in, con->conf.errh)) {
else if (0 != chunkqueue_steal_with_tempfiles(dst_cq, cq, (off_t)con->request.reqbody_length - dst_cq->bytes_in, con->conf.errh)) {
/* writing to temp file failed */
return connection_handle_read_post_error(con, 500); /* Internal Server Error */
}
chunkqueue_remove_finished_chunks(cq);
if (dst_cq->bytes_in == (off_t)con->request.content_length) {
if (dst_cq->bytes_in == (off_t)con->request.reqbody_length) {
/* Content is ready */
con->conf.stream_request_body &= ~FDEVENT_STREAM_REQUEST_POLLIN;
if (con->state == CON_STATE_READ_POST) {

18
src/connections.c

@ -229,7 +229,7 @@ static void connection_handle_response_end_state(connection *con) {
if (con->state != CON_STATE_ERROR) ++con->srv->con_written;
if (con->request.content_length != con->request_content_queue->bytes_in
if (con->request.reqbody_length != con->request_content_queue->bytes_in
|| con->state == CON_STATE_ERROR) {
/* request body is present and has not been read completely */
con->request.keep_alive = 0;
@ -674,7 +674,7 @@ static int connection_reset(connection *con) {
/*con->proto_default_port = 80;*//*set to default in connection_accepted()*/
con->request.http_host = NULL;
con->request.content_length = 0;
con->request.reqbody_length = 0;
con->request.te_chunked = 0;
con->request.htags = 0;
@ -849,7 +849,7 @@ static int connection_handle_read_state(connection * const con) {
http_request_parse(&con->request, hdrs, hoff, con->proto_default_port);
if (0 != con->http_status) {
con->request.keep_alive = 0;
con->request.content_length = 0;
con->request.reqbody_length = 0;
if (con->conf.log_request_header_on_error) {
/*(http_request_parse() modifies hdrs only to
@ -917,8 +917,8 @@ static handler_t connection_handle_fdevent(void *context, int revents) {
con->conf.stream_request_body |= FDEVENT_STREAM_REQUEST_POLLRDHUP;
con->is_readable = 1; /*(can read 0 for end-of-stream)*/
if (chunkqueue_is_empty(con->read_queue)) con->request.keep_alive = 0;
if (con->request.content_length < -1) { /*(transparent proxy mode; no more data to read)*/
con->request.content_length = con->request_content_queue->bytes_in;
if (con->request.reqbody_length < -1) { /*(transparent proxy mode; no more data to read)*/
con->request.reqbody_length = con->request_content_queue->bytes_in;
}
if (sock_addr_get_family(&con->dst_addr) == AF_UNIX) {
/* future: will getpeername() on AF_UNIX properly check if still connected? */
@ -1185,11 +1185,11 @@ static int connection_handle_request(connection *con) {
if (error_handler == con->conf.error_handler) {
plugins_call_connection_reset(con);
if (con->request.content_length) {
if (con->request.content_length != con->request_content_queue->bytes_in) {
if (con->request.reqbody_length) {
if (con->request.reqbody_length != con->request_content_queue->bytes_in) {
con->request.keep_alive = 0;
}
con->request.content_length = 0;
con->request.reqbody_length = 0;
chunkqueue_reset(con->request_content_queue);
}
@ -1272,7 +1272,7 @@ int connection_state_machine(connection *con) {
/*if (con->state != CON_STATE_REQUEST_END) break;*/
/* fall through */
case CON_STATE_REQUEST_END: /* transient */
ostate = (0 == con->request.content_length)
ostate = (0 == con->request.reqbody_length)
? CON_STATE_HANDLE_REQUEST
: CON_STATE_READ_POST;
connection_set_state(con, ostate);

8
src/gw_backend.c

@ -1893,7 +1893,7 @@ static handler_t gw_write_request(gw_handler_ctx *hctx, connection *con) {
/*(disable Nagle algorithm if streaming and content-length unknown)*/
if (AF_UNIX != hctx->host->family) {
if (con->request.content_length < 0) {
if (con->request.reqbody_length < 0) {
if (-1 == fdevent_set_tcp_nodelay(hctx->fd, 1)) {
/*(error, but not critical)*/
}
@ -2047,9 +2047,9 @@ handler_t gw_handle_subrequest(connection *con, void *p_d) {
handler_t rc = connection_handle_read_post_state(con);
chunkqueue *req_cq = con->request_content_queue;
#if 0 /*(not reached since we send 411 Length Required below)*/
if (hctx->wb_reqlen < -1 && con->request.content_length >= 0) {
if (hctx->wb_reqlen < -1 && con->request.reqbody_length >= 0) {
/* (completed receiving Transfer-Encoding: chunked) */
hctx->wb_reqlen= -hctx->wb_reqlen + con->request.content_length;
hctx->wb_reqlen= -hctx->wb_reqlen + con->request.reqbody_length;
if (hctx->stdin_append) {
handler_t rca = hctx->stdin_append(hctx);
if (HANDLER_GO_ON != rca) return rca;
@ -2079,7 +2079,7 @@ handler_t gw_handle_subrequest(connection *con, void *p_d) {
/* proxy currently sends HTTP/1.0 request and ideally should send
* Content-Length with request if request body is present, so
* send 411 Length Required if Content-Length missing. */
if (-1 == con->request.content_length) {
if (-1 == con->request.reqbody_length) {
return connection_handle_read_post_error(con, 411);
}
}

10
src/http-header-glue.c

@ -855,7 +855,7 @@ void http_response_upgrade_read_body_unknown(connection *con) {
con->conf.stream_response_body |=
(FDEVENT_STREAM_RESPONSE_BUFMIN | FDEVENT_STREAM_RESPONSE);
con->conf.stream_request_body |= FDEVENT_STREAM_REQUEST_POLLIN;
con->request.content_length = -2;
con->request.reqbody_length = -2;
con->request.keep_alive = 0;
}
@ -907,12 +907,12 @@ static handler_t http_response_process_local_redir(connection *con, size_t blen)
buffer_copy_buffer(con->request.uri, vb);
if (con->request.content_length) {
if (con->request.content_length
if (con->request.reqbody_length) {
if (con->request.reqbody_length
!= con->request_content_queue->bytes_in) {
con->request.keep_alive = 0;
}
con->request.content_length = 0;
con->request.reqbody_length = 0;
chunkqueue_reset(con->request_content_queue);
}
@ -1361,7 +1361,7 @@ int http_cgi_headers (connection *con, http_cgi_opts *opts, http_cgi_header_appe
/* (CONTENT_LENGTH must be first for SCGI) */
if (!opts->authorizer) {
rc |= cb(vdata, CONST_STR_LEN("CONTENT_LENGTH"),
buf, li_itostrn(buf,sizeof(buf),con->request.content_length));
buf, li_itostrn(buf,sizeof(buf),con->request.reqbody_length));
}
if (!buffer_string_is_empty(con->uri.query)) {

16
src/mod_cgi.c

@ -368,10 +368,10 @@ static handler_t cgi_handle_fdevent_send (void *ctx, int revents) {
if (revents & FDEVENT_HUP) {
/* skip sending remaining data to CGI */
if (con->request.content_length) {
if (con->request.reqbody_length) {
chunkqueue *cq = con->request_content_queue;
chunkqueue_mark_written(cq, chunkqueue_length(cq));
if (cq->bytes_in != (off_t)con->request.content_length) {
if (cq->bytes_in != (off_t)con->request.reqbody_length) {
con->request.keep_alive = 0;
}
}
@ -414,7 +414,7 @@ static handler_t cgi_response_headers(connection *con, struct http_response_opts
if (hctx->conf.upgrade && !(con->response.htags & HTTP_HEADER_UPGRADE)) {
chunkqueue *cq = con->request_content_queue;
hctx->conf.upgrade = 0;
if (cq->bytes_out == (off_t)con->request.content_length) {
if (cq->bytes_out == (off_t)con->request.reqbody_length) {
cgi_connection_close_fdtocgi(con, hctx); /*(closes hctx->fdtocgi)*/
}
}
@ -698,7 +698,7 @@ static int cgi_write_request(handler_ctx *hctx, int fd) {
}
}
if (cq->bytes_out == (off_t)con->request.content_length && !hctx->conf.upgrade) {
if (cq->bytes_out == (off_t)con->request.reqbody_length && !hctx->conf.upgrade) {
/* sent all request body input */
/* close connection to the cgi-script */
if (-1 == hctx->fdtocgi) { /*(received request body sent in initial send to pipe buffer)*/
@ -711,7 +711,7 @@ static int cgi_write_request(handler_ctx *hctx, int fd) {
}
} else {
off_t cqlen = cq->bytes_in - cq->bytes_out;
if (cq->bytes_in != con->request.content_length && cqlen < 65536 - 16384) {
if (cq->bytes_in != con->request.reqbody_length && cqlen < 65536 - 16384) {
/*(con->conf.stream_request_body & FDEVENT_STREAM_REQUEST)*/
if (!(con->conf.stream_request_body & FDEVENT_STREAM_REQUEST_POLLIN)) {
con->conf.stream_request_body |= FDEVENT_STREAM_REQUEST_POLLIN;
@ -843,7 +843,7 @@ static int cgi_create_env(connection *con, plugin_data *p, handler_ctx *hctx, bu
++con->srv->cur_fds;
if (0 == con->request.content_length) {
if (0 == con->request.reqbody_length) {
close(to_cgi_fds[1]);
} else {
/* there is content to send */
@ -947,7 +947,7 @@ SUBREQUEST_FUNC(mod_cgi_handle_subrequest) {
chunkqueue * const cq = con->request_content_queue;
if (cq->bytes_in != (off_t)con->request.content_length) {
if (cq->bytes_in != (off_t)con->request.reqbody_length) {
/*(64k - 4k to attempt to avoid temporary files
* in conjunction with FDEVENT_STREAM_REQUEST_BUFMIN)*/
if (cq->bytes_in - cq->bytes_out > 65536 - 4096
@ -967,7 +967,7 @@ SUBREQUEST_FUNC(mod_cgi_handle_subrequest) {
* Send 411 Length Required if Content-Length missing.
* (occurs here if client sends Transfer-Encoding: chunked
* and module is flagged to stream request body to backend) */
if (-1 == con->request.content_length) {
if (-1 == con->request.reqbody_length) {
return connection_handle_read_post_error(con, 411);
}
}

8
src/mod_fastcgi.c

@ -242,7 +242,7 @@ static handler_t fcgi_stdin_append(handler_ctx *hctx) {
? chunkqueue_append_mem(hctx->wb, (const char *)&header, sizeof(header))
: chunkqueue_append_mem_min(hctx->wb, (const char *)&header, sizeof(header));
chunkqueue_steal(hctx->wb, req_cq, weWant);
/*(hctx->wb_reqlen already includes content_length)*/
/*(hctx->wb_reqlen already includes reqbody_length)*/
}
if (hctx->wb->bytes_in == hctx->wb_reqlen) {
@ -316,10 +316,10 @@ static handler_t fcgi_create_env(handler_ctx *hctx) {
chunkqueue_prepend_buffer_commit(hctx->wb);
}
if (con->request.content_length) {
if (con->request.reqbody_length) {
/*chunkqueue_append_chunkqueue(hctx->wb, con->request_content_queue);*/
if (con->request.content_length > 0)
hctx->wb_reqlen += con->request.content_length;/* (eventual) (minimal) total request size, not necessarily including all fcgi_headers around content length yet */
if (con->request.reqbody_length > 0)
hctx->wb_reqlen += con->request.reqbody_length;/* (eventual) (minimal) total request size, not necessarily including all fcgi_headers around content length yet */
else /* as-yet-unknown total request size (Transfer-Encoding: chunked)*/
hctx->wb_reqlen = -hctx->wb_reqlen;
}

12
src/mod_proxy.c

@ -857,8 +857,8 @@ static handler_t proxy_create_env(gw_handler_ctx *gwhctx) {
/* "Forwarded" and legacy X- headers */
proxy_set_Forwarded(con, hctx->conf.forwarded);
if (con->request.content_length > 0
|| (0 == con->request.content_length
if (con->request.reqbody_length > 0
|| (0 == con->request.reqbody_length
&& !http_method_get_or_head(con->request.http_method))) {
/* set Content-Length if client sent Transfer-Encoding: chunked
* and not streaming to backend (request body has been fully received) */
@ -866,7 +866,7 @@ static handler_t proxy_create_env(gw_handler_ctx *gwhctx) {
if (NULL == vb) {
char buf[LI_ITOSTRING_LENGTH];
http_header_request_set(con, HTTP_HEADER_CONTENT_LENGTH, CONST_STR_LEN("Content-Length"),
buf, li_itostrn(buf, sizeof(buf), con->request.content_length));
buf, li_itostrn(buf, sizeof(buf), con->request.reqbody_length));
}
}
@ -948,10 +948,10 @@ static handler_t proxy_create_env(gw_handler_ctx *gwhctx) {
hctx->gw.wb_reqlen = buffer_string_length(b);
chunkqueue_prepend_buffer_commit(hctx->gw.wb);
if (con->request.content_length) {
if (con->request.reqbody_length) {
chunkqueue_append_chunkqueue(hctx->gw.wb, con->request_content_queue);
if (con->request.content_length > 0)
hctx->gw.wb_reqlen += con->request.content_length; /* total req size */
if (con->request.reqbody_length > 0)
hctx->gw.wb_reqlen += con->request.reqbody_length; /* total req size */
else /* as-yet-unknown total request size (Transfer-Encoding: chunked)*/
hctx->gw.wb_reqlen = -hctx->gw.wb_reqlen;
}

6
src/mod_scgi.c

@ -266,10 +266,10 @@ static handler_t scgi_create_env(handler_ctx *hctx) {
chunkqueue_mark_written(hctx->wb, offset);
#endif
if (con->request.content_length) {
if (con->request.reqbody_length) {
chunkqueue_append_chunkqueue(hctx->wb, con->request_content_queue);
if (con->request.content_length > 0)
hctx->wb_reqlen += con->request.content_length; /* total req size */
if (con->request.reqbody_length > 0)
hctx->wb_reqlen += con->request.reqbody_length; /* total req size */
else /* as-yet-unknown total request size (Transfer-Encoding: chunked)*/
hctx->wb_reqlen = -hctx->wb_reqlen;
}

4
src/mod_status.c

@ -493,10 +493,10 @@ static handler_t mod_status_handle_server_status_html(server *srv, connection *c
buffer_append_string_len(b, CONST_STR_LEN("</td><td class=\"int\">"));
if (c->request.content_length) {
if (c->request.reqbody_length) {
buffer_append_int(b, c->request_content_queue->bytes_in);
buffer_append_string_len(b, CONST_STR_LEN("/"));
buffer_append_int(b, c->request.content_length);
buffer_append_int(b, c->request.reqbody_length);
} else {
buffer_append_string_len(b, CONST_STR_LEN("0/0"));
}

2
src/mod_uploadprogress.c

@ -288,7 +288,7 @@ URIHANDLER_FUNC(mod_uploadprogress_uri_handler) {
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>"
"<upload>"
"<size>"));
buffer_append_int(b, post_con->request.content_length);
buffer_append_int(b, post_con->request.reqbody_length);
buffer_append_string_len(b, CONST_STR_LEN(
"</size>"
"<received>"));

14
src/mod_webdav.c

@ -3737,7 +3737,7 @@ webdav_has_lock (connection * const con,
static handler_t
mod_webdav_propfind (connection * const con, const plugin_config * const pconf)
{
if (con->request.content_length) {
if (con->request.reqbody_length) {
#ifdef USE_PROPPATCH
if (con->state == CON_STATE_READ_POST) {
handler_t rc = connection_handle_read_post_state(con);
@ -3819,7 +3819,7 @@ mod_webdav_propfind (connection * const con, const plugin_config * const pconf)
#ifdef USE_PROPPATCH
xmlDocPtr xml = NULL;
const xmlNode *rootnode = NULL;
if (con->request.content_length) {
if (con->request.reqbody_length) {
if (NULL == (xml = webdav_parse_chunkqueue(con, pconf))) {
http_status_set_error(con, 400); /* Bad Request */
return HANDLER_FINISHED;
@ -4244,7 +4244,7 @@ mod_webdav_put_prep (connection * const con, const plugin_config * const pconf)
}
/* special-case PUT 0-length file */
if (0 == con->request.content_length)
if (0 == con->request.reqbody_length)
return mod_webdav_put_0(con, pconf);
/* Create temporary file in target directory (to store reqbody as received)
@ -4973,7 +4973,7 @@ mod_webdav_proppatch (connection * const con, const plugin_config * const pconf)
return HANDLER_FINISHED;
}
if (0 == con->request.content_length) {
if (0 == con->request.reqbody_length) {
http_status_set_error(con, 400); /* Bad Request */
return HANDLER_FINISHED;
}
@ -5193,7 +5193,7 @@ mod_webdav_lock (connection * const con, const plugin_config * const pconf)
* </D:lockinfo>\n
*/
if (con->request.content_length) {
if (con->request.reqbody_length) {
if (con->state == CON_STATE_READ_POST) {
handler_t rc = connection_handle_read_post_state(con);
if (rc != HANDLER_GO_ON) return rc;
@ -5259,7 +5259,7 @@ mod_webdav_lock (connection * const con, const plugin_config * const pconf)
} while (*p != '\0');
}
if (con->request.content_length) {
if (con->request.reqbody_length) {
lockdata.depth = webdav_parse_Depth(con);
if (1 == lockdata.depth) {
/* [RFC4918] 9.10.3 Depth and Locking
@ -5615,7 +5615,7 @@ PHYSICALPATH_FUNC(mod_webdav_physical_handler)
return HANDLER_FINISHED;
}
if (reject_reqbody && con->request.content_length) {
if (reject_reqbody && con->request.reqbody_length) {
/* [RFC4918] 8.4 Required Bodies in Requests
* Servers MUST examine all requests for a body, even when a
* body was not expected. In cases where a request body is

2
src/mod_wstunnel.c

@ -351,7 +351,7 @@ static handler_t wstunnel_create_env(gw_handler_ctx *gwhctx) {
handler_ctx *hctx = (handler_ctx *)gwhctx;
connection *con = hctx->gw.remote_conn;
handler_t rc;
if (0 == con->request.content_length) {
if (0 == con->request.reqbody_length) {
http_response_upgrade_read_body_unknown(con);
chunkqueue_append_chunkqueue(con->request_content_queue,
con->read_queue);

12
src/request.c

@ -432,7 +432,7 @@ static int http_request_parse_single_header(request_st * const r, const enum htt
off_t clen = strtoll(v, &err, 10);
if (clen >= 0 && err == v+vlen) {
/* (set only if not set to -1 by Transfer-Encoding: chunked) */
if (0 == r->content_length) r->content_length = clen;
if (0 == r->reqbody_length) r->reqbody_length = clen;
}
else {
return http_request_header_line_invalid(r, 400, "invalid Content-Length header -> 400");
@ -469,7 +469,7 @@ static int http_request_parse_single_header(request_st * const r, const enum htt
* which are not currently supported by lighttpd */
return http_request_header_line_invalid(r, 501, NULL); /* Not Implemented */
}
r->content_length = -1;
r->reqbody_length = -1;
/* Transfer-Encoding is a hop-by-hop header,
* which must not be blindly forwarded to backends */
@ -819,17 +819,17 @@ int http_request_parse(request_st * const r, char * const hdrs, const unsigned s
return http_request_header_line_invalid(r, 400, "HTTP/1.1 but Host missing -> 400");
}
if (0 == r->content_length) {
if (0 == r->reqbody_length) {
/* POST requires Content-Length (or Transfer-Encoding)
* (-1 == r->content_length when Transfer-Encoding: chunked)*/
* (-1 == r->reqbody_length when Transfer-Encoding: chunked)*/
if (HTTP_METHOD_POST == r->http_method
&& !(r->htags & HTTP_HEADER_CONTENT_LENGTH)) {
return http_request_header_line_invalid(r, 411, "POST-request, but content-length missing -> 411");
}
}
else {
/* (-1 == r->content_length when Transfer-Encoding: chunked)*/
if (-1 == r->content_length
/* (-1 == r->reqbody_length when Transfer-Encoding: chunked)*/
if (-1 == r->reqbody_length
&& (r->htags & HTTP_HEADER_CONTENT_LENGTH)) {
/* RFC7230 Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing
* 3.3.3. Message Body Length

2
src/request.h

@ -89,7 +89,7 @@ struct request_st {
array headers;
/* CONTENT */
off_t content_length; /* returned by strtoll() */
off_t reqbody_length; /* request Content-Length */
off_t te_chunked;
int keep_alive; /* only request.c can enable it, all other just disable */

8
src/response.c

@ -59,8 +59,8 @@ int http_response_write_header(connection *con) {
if (con->request_count > con->conf.max_keep_alive_requests || 0 == con->conf.max_keep_alive_idle) {
con->request.keep_alive = 0;
} else if (0 != con->request.content_length
&& con->request.content_length != con->request_content_queue->bytes_in
} else if (0 != con->request.reqbody_length
&& con->request.reqbody_length != con->request_content_queue->bytes_in
&& (con->mode == DIRECT || 0 == con->conf.stream_request_body)) {
con->request.keep_alive = 0;
} else {
@ -476,9 +476,9 @@ handler_t http_response_prepare(connection *con) {
/* con->conf.max_request_size is in kBytes */
if (0 != con->conf.max_request_size &&
(off_t)con->request.content_length > ((off_t)con->conf.max_request_size << 10)) {
(off_t)con->request.reqbody_length > ((off_t)con->conf.max_request_size << 10)) {
log_error(con->conf.errh, __FILE__, __LINE__,
"request-size too long: %lld -> 413", (long long) con->request.content_length);
"request-size too long: %lld -> 413", (long long) con->request.reqbody_length);
return /* 413 Payload Too Large */
http_status_set_error_close(con, 413);
}

2
src/t/test_request.c

@ -17,7 +17,7 @@ static void test_request_connection_reset(connection *con)
con->request.http_version = HTTP_VERSION_UNSET;
con->request.http_host = NULL;
con->request.htags = 0;
con->request.content_length = 0;
con->request.reqbody_length = 0;
con->header_len = 0;
con->http_status = 0;
con->proto_default_port = 80;

Loading…
Cancel
Save