You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by wr...@apache.org on 2018/09/12 13:56:21 UTC
svn commit: r1840688 [14/37] - in /httpd/sandbox/httpd-2.4.x-trunk-delta: ./
build/ build/rpm/ build/win32/ docs/ docs/conf/ docs/conf/extra/
docs/log-message-tags/ docs/man/ docs/man/tr/ include/ modules/
modules/aaa/ modules/apreq/ modules/arch/unix/...
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_filters.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_filters.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_filters.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_filters.c Wed Sep 12 13:56:17 2018
@@ -80,50 +80,8 @@ typedef struct http_filter_ctx
BODY_CHUNK_TRAILER /* trailers */
} state;
unsigned int eos_sent :1;
- apr_bucket_brigade *bb;
} http_ctx_t;
-/* bail out if some error in the HTTP input filter happens */
-static apr_status_t bail_out_on_error(http_ctx_t *ctx,
- ap_filter_t *f,
- int http_error)
-{
- apr_bucket *e;
- apr_bucket_brigade *bb = ctx->bb;
-
- apr_brigade_cleanup(bb);
-
- if (f->r->proxyreq == PROXYREQ_RESPONSE) {
- switch (http_error) {
- case HTTP_REQUEST_ENTITY_TOO_LARGE:
- return APR_ENOSPC;
-
- case HTTP_REQUEST_TIME_OUT:
- return APR_INCOMPLETE;
-
- case HTTP_NOT_IMPLEMENTED:
- return APR_ENOTIMPL;
-
- default:
- return APR_EGENERAL;
- }
- }
-
- e = ap_bucket_error_create(http_error,
- NULL, f->r->pool,
- f->c->bucket_alloc);
- APR_BRIGADE_INSERT_TAIL(bb, e);
- e = apr_bucket_eos_create(f->c->bucket_alloc);
- APR_BRIGADE_INSERT_TAIL(bb, e);
- ctx->eos_sent = 1;
- /* If chunked encoding / content-length are corrupt, we may treat parts
- * of this request's body as the next one's headers.
- * To be safe, disable keep-alive.
- */
- f->r->connection->keepalive = AP_CONN_CLOSE;
- return ap_pass_brigade(f->r->output_filters, bb);
-}
-
/**
* Parse a chunk line with optional extension, detect overflow.
* There are several error cases:
@@ -347,8 +305,6 @@ apr_status_t ap_http_filter(ap_filter_t
apr_bucket *e;
http_ctx_t *ctx = f->ctx;
apr_status_t rv;
- int http_error = HTTP_REQUEST_ENTITY_TOO_LARGE;
- apr_bucket_brigade *bb;
int again;
/* just get out of the way of things we don't want. */
@@ -360,15 +316,13 @@ apr_status_t ap_http_filter(ap_filter_t
const char *tenc, *lenp;
f->ctx = ctx = apr_pcalloc(f->r->pool, sizeof(*ctx));
ctx->state = BODY_NONE;
- ctx->bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);
- bb = ctx->bb;
/* LimitRequestBody does not apply to proxied responses.
* Consider implementing this check in its own filter.
* Would adding a directive to limit the size of proxied
* responses be useful?
*/
- if (!f->r->proxyreq) {
+ if (f->r->proxyreq != PROXYREQ_RESPONSE) {
ctx->limit = ap_get_limit_req_body(f->r);
}
else {
@@ -379,7 +333,7 @@ apr_status_t ap_http_filter(ap_filter_t
lenp = apr_table_get(f->r->headers_in, "Content-Length");
if (tenc) {
- if (strcasecmp(tenc, "chunked") == 0 /* fast path */
+ if (ap_cstr_casecmp(tenc, "chunked") == 0 /* fast path */
|| ap_find_last_token(f->r->pool, tenc, "chunked")) {
ctx->state = BODY_CHUNK;
}
@@ -401,7 +355,7 @@ apr_status_t ap_http_filter(ap_filter_t
*/
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, f->r, APLOGNO(01585)
"Unknown Transfer-Encoding: %s", tenc);
- return bail_out_on_error(ctx, f, HTTP_BAD_REQUEST);
+ return APR_EGENERAL;
}
lenp = NULL;
}
@@ -420,7 +374,7 @@ apr_status_t ap_http_filter(ap_filter_t
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, f->r, APLOGNO(01587)
"Invalid Content-Length");
- return bail_out_on_error(ctx, f, HTTP_BAD_REQUEST);
+ return APR_EINVAL;
}
/* If we have a limit in effect and we know the C-L ahead of
@@ -431,7 +385,7 @@ apr_status_t ap_http_filter(ap_filter_t
"Requested content-length of %" APR_OFF_T_FMT
" is larger than the configured limit"
" of %" APR_OFF_T_FMT, ctx->remaining, ctx->limit);
- return bail_out_on_error(ctx, f, HTTP_REQUEST_ENTITY_TOO_LARGE);
+ return APR_ENOSPC;
}
}
@@ -455,10 +409,10 @@ apr_status_t ap_http_filter(ap_filter_t
/* Since we're about to read data, send 100-Continue if needed.
* Only valid on chunked and C-L bodies where the C-L is > 0. */
- if ((ctx->state == BODY_CHUNK ||
- (ctx->state == BODY_LENGTH && ctx->remaining > 0)) &&
- f->r->expecting_100 && f->r->proto_num >= HTTP_VERSION(1,1) &&
- !(f->r->eos_sent || f->r->bytes_sent)) {
+ if ((ctx->state == BODY_CHUNK
+ || (ctx->state == BODY_LENGTH && ctx->remaining > 0))
+ && f->r->expecting_100 && f->r->proto_num >= HTTP_VERSION(1,1)
+ && !(f->r->eos_sent || f->r->bytes_sent)) {
if (!ap_is_HTTP_SUCCESS(f->r->status)) {
ctx->state = BODY_NONE;
ctx->eos_sent = 1;
@@ -466,17 +420,18 @@ apr_status_t ap_http_filter(ap_filter_t
else {
char *tmp;
int len;
+ apr_bucket_brigade *bb;
+
+ bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);
/* if we send an interim response, we're no longer
* in a state of expecting one.
*/
f->r->expecting_100 = 0;
tmp = apr_pstrcat(f->r->pool, AP_SERVER_PROTOCOL " ",
- ap_get_status_line(HTTP_CONTINUE), CRLF CRLF,
- NULL);
+ ap_get_status_line(HTTP_CONTINUE), CRLF CRLF, NULL);
len = strlen(tmp);
ap_xlate_proto_to_ascii(tmp, len);
- apr_brigade_cleanup(bb);
e = apr_bucket_pool_create(tmp, len, f->r->pool,
f->c->bucket_alloc);
APR_BRIGADE_INSERT_HEAD(bb, e);
@@ -535,12 +490,9 @@ apr_status_t ap_http_filter(ap_filter_t
apr_size_t len;
if (!APR_BUCKET_IS_METADATA(e)) {
- int parsing = 0;
-
rv = apr_bucket_read(e, &buffer, &len, APR_BLOCK_READ);
if (rv == APR_SUCCESS) {
- parsing = 1;
rv = parse_chunk_size(ctx, buffer, len,
f->r->server->limit_req_fieldsize, strict);
}
@@ -548,12 +500,6 @@ apr_status_t ap_http_filter(ap_filter_t
ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, f->r, APLOGNO(01590)
"Error reading/parsing chunk %s ",
(APR_ENOSPC == rv) ? "(overflow)" : "");
- if (parsing) {
- if (rv != APR_ENOSPC) {
- http_error = HTTP_BAD_REQUEST;
- }
- return bail_out_on_error(ctx, f, http_error);
- }
return rv;
}
}
@@ -637,8 +583,7 @@ apr_status_t ap_http_filter(ap_filter_t
"%" APR_OFF_T_FMT " is larger than the "
"configured limit of %" APR_OFF_T_FMT,
ctx->limit_used, ctx->limit);
- return bail_out_on_error(ctx, f,
- HTTP_REQUEST_ENTITY_TOO_LARGE);
+ return APR_ENOSPC;
}
}
}
@@ -872,7 +817,7 @@ static int uniq_field_values(void *d, co
*/
for (i = 0, strpp = (char **) values->elts; i < values->nelts;
++i, ++strpp) {
- if (*strpp && strcasecmp(*strpp, start) == 0) {
+ if (*strpp && ap_cstr_casecmp(*strpp, start) == 0) {
break;
}
}
@@ -1289,7 +1234,6 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_
{
request_rec *r = f->r;
conn_rec *c = r->connection;
- const char *clheader;
const char *protocol = NULL;
apr_bucket *e;
apr_bucket_brigade *b2;
@@ -1453,7 +1397,7 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_
while (field && (token = ap_get_list_item(r->pool, &field)) != NULL) {
for (i = 0; i < r->content_languages->nelts; ++i) {
- if (!strcasecmp(token, languages[i]))
+ if (!ap_cstr_casecmp(token, languages[i]))
break;
}
if (i == r->content_languages->nelts) {
@@ -1475,24 +1419,6 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_
apr_table_addn(r->headers_out, "Expires", date);
}
- /* This is a hack, but I can't find anyway around it. The idea is that
- * we don't want to send out 0 Content-Lengths if it is a head request.
- * This happens when modules try to outsmart the server, and return
- * if they see a HEAD request. Apache 1.3 handlers were supposed to
- * just return in that situation, and the core handled the HEAD. In
- * 2.0, if a handler returns, then the core sends an EOS bucket down
- * the filter stack, and the content-length filter computes a C-L of
- * zero and that gets put in the headers, and we end up sending a
- * zero C-L to the client. We can't just remove the C-L filter,
- * because well behaved 2.0 handlers will send their data down the stack,
- * and we will compute a real C-L for the head request. RBB
- */
- if (r->header_only
- && (clheader = apr_table_get(r->headers_out, "Content-Length"))
- && !strcmp(clheader, "0")) {
- apr_table_unset(r->headers_out, "Content-Length");
- }
-
b2 = apr_brigade_create(r->pool, c->bucket_alloc);
basic_http_header(r, b2, protocol);
@@ -1574,6 +1500,9 @@ AP_DECLARE(int) ap_map_http_request_erro
case AP_FILTER_ERROR:
return AP_FILTER_ERROR;
+ case APR_EGENERAL:
+ return HTTP_BAD_REQUEST;
+
case APR_ENOSPC:
return HTTP_REQUEST_ENTITY_TOO_LARGE;
@@ -1713,7 +1642,7 @@ AP_DECLARE(int) ap_setup_client_block(re
r->remaining = 0;
if (tenc) {
- if (strcasecmp(tenc, "chunked")) {
+ if (ap_cstr_casecmp(tenc, "chunked")) {
ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(01592)
"Unknown Transfer-Encoding %s", tenc);
return HTTP_NOT_IMPLEMENTED;
@@ -1808,6 +1737,28 @@ AP_DECLARE(long) ap_get_client_block(req
return -1;
}
if (rv != APR_SUCCESS) {
+ apr_bucket *e;
+
+ /* work around our silent swallowing of error messages by mapping
+ * error codes at this point, and sending an error bucket back
+ * upstream.
+ */
+ apr_brigade_cleanup(bb);
+
+ e = ap_bucket_error_create(
+ ap_map_http_request_error(rv, HTTP_BAD_REQUEST), NULL, r->pool,
+ r->connection->bucket_alloc);
+ APR_BRIGADE_INSERT_TAIL(bb, e);
+
+ e = apr_bucket_eos_create(r->connection->bucket_alloc);
+ APR_BRIGADE_INSERT_TAIL(bb, e);
+
+ rv = ap_pass_brigade(r->output_filters, bb);
+ if (APR_SUCCESS != rv) {
+ ap_log_rerror(APLOG_MARK, APLOG_INFO, rv, r, APLOGNO(02484)
+ "Error while writing error response");
+ }
+
/* if we actually fail here, we want to just return and
* stop trying to read data from the client.
*/
@@ -1876,7 +1827,8 @@ apr_status_t ap_http_outerror_filter(ap_
* Start of error handling state tree. Just one condition
* right now :)
*/
- if (((ap_bucket_error *)(e->data))->status == HTTP_BAD_GATEWAY) {
+ if (((ap_bucket_error *)(e->data))->status == HTTP_BAD_GATEWAY ||
+ ((ap_bucket_error *)(e->data))->status == HTTP_GATEWAY_TIME_OUT) {
/* stream aborted and we have not ended it yet */
r->connection->keepalive = AP_CONN_CLOSE;
}
@@ -1907,12 +1859,12 @@ apr_status_t ap_http_outerror_filter(ap_
* EOS bucket.
*/
if (ctx->seen_eoc) {
- for (e = APR_BRIGADE_FIRST(b);
- e != APR_BRIGADE_SENTINEL(b);
- e = APR_BUCKET_NEXT(e))
- {
- if (!APR_BUCKET_IS_METADATA(e)) {
- APR_BUCKET_REMOVE(e);
+ e = APR_BRIGADE_FIRST(b);
+ while (e != APR_BRIGADE_SENTINEL(b)) {
+ apr_bucket *c = e;
+ e = APR_BUCKET_NEXT(e);
+ if (!APR_BUCKET_IS_METADATA(c)) {
+ apr_bucket_delete(c);
}
}
}
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_protocol.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_protocol.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_protocol.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_protocol.c Wed Sep 12 13:56:17 2018
@@ -132,7 +132,7 @@ static const char * const status_lines[R
"415 Unsupported Media Type",
"416 Requested Range Not Satisfiable",
"417 Expectation Failed",
- NULL, /* 418 */
+ "418 I'm A Teapot",
NULL, /* 419 */
NULL, /* 420 */
"421 Misdirected Request",
@@ -723,10 +723,6 @@ AP_DECLARE(int) ap_method_register(apr_p
{
int *methnum;
- if (methods_registry == NULL) {
- ap_method_registry_init(p);
- }
-
if (methname == NULL) {
return M_INVALID;
}
@@ -754,183 +750,6 @@ AP_DECLARE(int) ap_method_register(apr_p
return cur_method_number++;
}
-#define UNKNOWN_METHOD (-1)
-
-static int lookup_builtin_method(const char *method, apr_size_t len)
-{
- /* Note: the following code was generated by the "shilka" tool from
- the "cocom" parsing/compilation toolkit. It is an optimized lookup
- based on analysis of the input keywords. Postprocessing was done
- on the shilka output, but the basic structure and analysis is
- from there. Should new HTTP methods be added, then manual insertion
- into this code is fine, or simply re-running the shilka tool on
- the appropriate input. */
-
- /* Note: it is also quite reasonable to just use our method_registry,
- but I'm assuming (probably incorrectly) we want more speed here
- (based on the optimizations the previous code was doing). */
-
- switch (len)
- {
- case 3:
- switch (method[0])
- {
- case 'P':
- return (method[1] == 'U'
- && method[2] == 'T'
- ? M_PUT : UNKNOWN_METHOD);
- case 'G':
- return (method[1] == 'E'
- && method[2] == 'T'
- ? M_GET : UNKNOWN_METHOD);
- default:
- return UNKNOWN_METHOD;
- }
-
- case 4:
- switch (method[0])
- {
- case 'H':
- return (method[1] == 'E'
- && method[2] == 'A'
- && method[3] == 'D'
- ? M_GET : UNKNOWN_METHOD);
- case 'P':
- return (method[1] == 'O'
- && method[2] == 'S'
- && method[3] == 'T'
- ? M_POST : UNKNOWN_METHOD);
- case 'M':
- return (method[1] == 'O'
- && method[2] == 'V'
- && method[3] == 'E'
- ? M_MOVE : UNKNOWN_METHOD);
- case 'L':
- return (method[1] == 'O'
- && method[2] == 'C'
- && method[3] == 'K'
- ? M_LOCK : UNKNOWN_METHOD);
- case 'C':
- return (method[1] == 'O'
- && method[2] == 'P'
- && method[3] == 'Y'
- ? M_COPY : UNKNOWN_METHOD);
- default:
- return UNKNOWN_METHOD;
- }
-
- case 5:
- switch (method[2])
- {
- case 'T':
- return (memcmp(method, "PATCH", 5) == 0
- ? M_PATCH : UNKNOWN_METHOD);
- case 'R':
- return (memcmp(method, "MERGE", 5) == 0
- ? M_MERGE : UNKNOWN_METHOD);
- case 'C':
- return (memcmp(method, "MKCOL", 5) == 0
- ? M_MKCOL : UNKNOWN_METHOD);
- case 'B':
- return (memcmp(method, "LABEL", 5) == 0
- ? M_LABEL : UNKNOWN_METHOD);
- case 'A':
- return (memcmp(method, "TRACE", 5) == 0
- ? M_TRACE : UNKNOWN_METHOD);
- default:
- return UNKNOWN_METHOD;
- }
-
- case 6:
- switch (method[0])
- {
- case 'U':
- switch (method[5])
- {
- case 'K':
- return (memcmp(method, "UNLOCK", 6) == 0
- ? M_UNLOCK : UNKNOWN_METHOD);
- case 'E':
- return (memcmp(method, "UPDATE", 6) == 0
- ? M_UPDATE : UNKNOWN_METHOD);
- default:
- return UNKNOWN_METHOD;
- }
- case 'R':
- return (memcmp(method, "REPORT", 6) == 0
- ? M_REPORT : UNKNOWN_METHOD);
- case 'D':
- return (memcmp(method, "DELETE", 6) == 0
- ? M_DELETE : UNKNOWN_METHOD);
- default:
- return UNKNOWN_METHOD;
- }
-
- case 7:
- switch (method[1])
- {
- case 'P':
- return (memcmp(method, "OPTIONS", 7) == 0
- ? M_OPTIONS : UNKNOWN_METHOD);
- case 'O':
- return (memcmp(method, "CONNECT", 7) == 0
- ? M_CONNECT : UNKNOWN_METHOD);
- case 'H':
- return (memcmp(method, "CHECKIN", 7) == 0
- ? M_CHECKIN : UNKNOWN_METHOD);
- default:
- return UNKNOWN_METHOD;
- }
-
- case 8:
- switch (method[0])
- {
- case 'P':
- return (memcmp(method, "PROPFIND", 8) == 0
- ? M_PROPFIND : UNKNOWN_METHOD);
- case 'C':
- return (memcmp(method, "CHECKOUT", 8) == 0
- ? M_CHECKOUT : UNKNOWN_METHOD);
- default:
- return UNKNOWN_METHOD;
- }
-
- case 9:
- return (memcmp(method, "PROPPATCH", 9) == 0
- ? M_PROPPATCH : UNKNOWN_METHOD);
-
- case 10:
- switch (method[0])
- {
- case 'U':
- return (memcmp(method, "UNCHECKOUT", 10) == 0
- ? M_UNCHECKOUT : UNKNOWN_METHOD);
- case 'M':
- return (memcmp(method, "MKACTIVITY", 10) == 0
- ? M_MKACTIVITY : UNKNOWN_METHOD);
- default:
- return UNKNOWN_METHOD;
- }
-
- case 11:
- return (memcmp(method, "MKWORKSPACE", 11) == 0
- ? M_MKWORKSPACE : UNKNOWN_METHOD);
-
- case 15:
- return (memcmp(method, "VERSION-CONTROL", 15) == 0
- ? M_VERSION_CONTROL : UNKNOWN_METHOD);
-
- case 16:
- return (memcmp(method, "BASELINE-CONTROL", 16) == 0
- ? M_BASELINE_CONTROL : UNKNOWN_METHOD);
-
- default:
- return UNKNOWN_METHOD;
- }
-
- /* NOTREACHED */
-}
-
/* Get the method number associated with the given string, assumed to
* contain an HTTP method. Returns M_INVALID if not recognized.
*
@@ -941,19 +760,13 @@ static int lookup_builtin_method(const c
AP_DECLARE(int) ap_method_number_of(const char *method)
{
int len = strlen(method);
- int which = lookup_builtin_method(method, len);
-
- if (which != UNKNOWN_METHOD)
- return which;
/* check if the method has been dynamically registered */
- if (methods_registry != NULL) {
int *methnum = apr_hash_get(methods_registry, method, len);
if (methnum != NULL) {
return *methnum;
}
- }
return M_INVALID;
}
@@ -987,14 +800,17 @@ AP_DECLARE(const char *) ap_method_name_
* from status_lines[shortcut[i]] to status_lines[shortcut[i+1]-1];
* or use NULL to fill the gaps.
*/
-AP_DECLARE(int) ap_index_of_response(int status)
+static int index_of_response(int status)
{
- static int shortcut[6] = {0, LEVEL_200, LEVEL_300, LEVEL_400,
- LEVEL_500, RESPONSE_CODES};
+ static int shortcut[6] = {0, LEVEL_200, LEVEL_300, LEVEL_400, LEVEL_500,
+ RESPONSE_CODES};
int i, pos;
if (status < 100) { /* Below 100 is illegal for HTTP status */
- return LEVEL_500;
+ return -1;
+ }
+ if (status > 999) { /* Above 999 is also illegal for HTTP status */
+ return -1;
}
for (i = 0; i < 5; i++) {
@@ -1005,11 +821,29 @@ AP_DECLARE(int) ap_index_of_response(int
return pos;
}
else {
- return LEVEL_500; /* status unknown (falls in gap) */
+ break;
}
}
}
- return LEVEL_500; /* 600 or above is also illegal */
+ return -2; /* Status unknown (falls in gap) or above 600 */
+}
+
+AP_DECLARE(int) ap_index_of_response(int status)
+{
+ int index = index_of_response(status);
+ return (index < 0) ? LEVEL_500 : index;
+}
+
+AP_DECLARE(const char *) ap_get_status_line_ex(apr_pool_t *p, int status)
+{
+ int index = index_of_response(status);
+ if (index >= 0) {
+ return status_lines[index];
+ }
+ else if (index == -2) {
+ return apr_psprintf(p, "%i Status %i", status, status);
+ }
+ return status_lines[LEVEL_500];
}
AP_DECLARE(const char *) ap_get_status_line(int status)
@@ -1311,6 +1145,9 @@ static const char *get_canned_error_stri
case HTTP_NETWORK_AUTHENTICATION_REQUIRED:
return("<p>The client needs to authenticate to gain\n"
"network access.</p>\n");
+ case HTTP_IM_A_TEAPOT:
+ return("<p>The resulting entity body MAY be short and\n"
+ "stout.</p>\n");
case HTTP_MISDIRECTED_REQUEST:
return("<p>The client needs a new connection for this\n"
"request as the requested host name does not match\n"
@@ -1420,16 +1257,13 @@ AP_DECLARE(void) ap_send_error_response(
}
if (!r->assbackwards) {
- apr_table_t *tmp = r->headers_out;
/* For all HTTP/1.x responses for which we generate the message,
* we need to avoid inheriting the "normal status" header fields
* that may have been set by the request handler before the
* error or redirect, except for Location on external redirects.
*/
- r->headers_out = r->err_headers_out;
- r->err_headers_out = tmp;
- apr_table_clear(r->err_headers_out);
+ apr_table_clear(r->headers_out);
if (ap_is_HTTP_REDIRECT(status) || (status == HTTP_CREATED)) {
if ((location != NULL) && *location) {
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_request.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_request.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_request.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/http_request.c Wed Sep 12 13:56:17 2018
@@ -39,6 +39,7 @@
#include "http_protocol.h"
#include "http_log.h"
#include "http_main.h"
+#include "mpm_common.h"
#include "util_filter.h"
#include "util_charset.h"
#include "scoreboard.h"
@@ -249,7 +250,7 @@ AP_DECLARE(apr_status_t) ap_check_pipeli
apr_brigade_cleanup(bb);
rv = ap_get_brigade(c->input_filters, bb, mode,
APR_NONBLOCK_READ, len);
- if (rv != APR_SUCCESS || APR_BRIGADE_EMPTY(bb) || !max_blank_lines) {
+ if (rv != APR_SUCCESS || APR_BRIGADE_EMPTY(bb)) {
if (mode == AP_MODE_READBYTES) {
/* Unexpected error, stop with this connection */
ap_log_cerror(APLOG_MARK, APLOG_ERR, rv, c, APLOGNO(02967)
@@ -257,8 +258,7 @@ AP_DECLARE(apr_status_t) ap_check_pipeli
c->keepalive = AP_CONN_CLOSE;
rv = APR_EGENERAL;
}
- else if (rv != APR_SUCCESS || APR_BRIGADE_EMPTY(bb)) {
- if (rv != APR_SUCCESS && !APR_STATUS_IS_EAGAIN(rv)) {
+ else if (rv != APR_SUCCESS && !APR_STATUS_IS_EAGAIN(rv)) {
/* Pipe is dead */
c->keepalive = AP_CONN_CLOSE;
}
@@ -266,15 +266,15 @@ AP_DECLARE(apr_status_t) ap_check_pipeli
/* Pipe is up and empty */
rv = APR_EAGAIN;
}
+ break;
}
- else {
+ if (!max_blank_lines) {
apr_off_t n = 0;
/* Single read asked, (non-meta-)data available? */
rv = apr_brigade_length(bb, 0, &n);
if (rv == APR_SUCCESS && n <= 0) {
rv = APR_EAGAIN;
}
- }
break;
}
@@ -345,38 +345,45 @@ AP_DECLARE(apr_status_t) ap_check_pipeli
return rv;
}
-#define RETRIEVE_BRIGADE_FROM_POOL(bb, key, pool, allocator) do { \
- apr_pool_userdata_get((void **)&bb, key, pool); \
- if (bb == NULL) { \
- bb = apr_brigade_create(pool, allocator); \
- apr_pool_userdata_setn((const void *)bb, key, NULL, pool); \
- } \
- else { \
- apr_brigade_cleanup(bb); \
- } \
-} while(0)
-
AP_DECLARE(void) ap_process_request_after_handler(request_rec *r)
{
apr_bucket_brigade *bb;
apr_bucket *b;
conn_rec *c = r->connection;
- apr_status_t rv;
+ ap_filter_t *f;
+
+ bb = ap_acquire_brigade(c);
/* Send an EOR bucket through the output filter chain. When
* this bucket is destroyed, the request will be logged and
* its pool will be freed
*/
- RETRIEVE_BRIGADE_FROM_POOL(bb, "ap_process_request_after_handler_brigade",
- c->pool, c->bucket_alloc);
b = ap_bucket_eor_create(c->bucket_alloc, r);
APR_BRIGADE_INSERT_HEAD(bb, b);
- ap_pass_brigade(c->output_filters, bb);
+ /* Find the last request, taking into account internal
+ * redirects. We want to send the EOR bucket at the end of
+ * all the buckets so it does not jump the queue.
+ */
+ while (r->next) {
+ r = r->next;
+ }
+ /* All the request filters should have bailed out on EOS, and in any
+ * case they shouldn't have to handle this EOR which will destroy the
+ * request underneath them. So go straight to the core request filter
+ * which (if any) will take care of the setaside buckets.
+ */
+ for (f = r->output_filters; f; f = f->next) {
+ if (f->frec == ap_request_core_filter_handle) {
+ break;
+ }
+ }
+ ap_pass_brigade(f ? f : c->output_filters, bb);
+
/* The EOR bucket has either been handled by an output filter (eg.
* deleted or moved to a buffered_bb => no more in bb), or an error
- * occured before that (eg. c->aborted => still in bb) and we ought
+ * occurred before that (eg. c->aborted => still in bb) and we ought
* to destroy it now. So cleanup any remaining bucket along with
* the orphan request (if any).
*/
@@ -392,13 +399,23 @@ AP_DECLARE(void) ap_process_request_afte
* without flushing data, and hence possibly delay pending response(s)
* until the next/real request comes in or the keepalive timeout expires.
*/
- rv = ap_check_pipeline(c, bb, DEFAULT_LIMIT_BLANK_LINES);
- c->data_in_input_filters = (rv == APR_SUCCESS);
- apr_brigade_cleanup(bb);
+ (void)ap_check_pipeline(c, bb, DEFAULT_LIMIT_BLANK_LINES);
+
+ ap_release_brigade(c, bb);
- if (c->cs)
- c->cs->state = (c->aborted) ? CONN_STATE_LINGER
- : CONN_STATE_WRITE_COMPLETION;
+ if (c->cs) {
+ if (c->aborted) {
+ c->cs->state = CONN_STATE_LINGER;
+ }
+ else {
+ /* If we have still data in the output filters here it means that
+ * the last (recent) nonblocking write was EAGAIN, so tell the MPM
+ * to not try another useless/stressful one but to go straight to
+ * POLLOUT.
+ */
+ c->cs->state = CONN_STATE_WRITE_COMPLETION;
+ }
+ }
AP_PROCESS_REQUEST_RETURN((uintptr_t)r, r->uri, r->status);
if (ap_extended_status) {
ap_time_process_request(c->sbh, STOP_PREQUEST);
@@ -487,9 +504,8 @@ AP_DECLARE(void) ap_process_request(requ
ap_process_async_request(r);
- if (!c->data_in_input_filters) {
- RETRIEVE_BRIGADE_FROM_POOL(bb, "ap_process_request_brigade",
- c->pool, c->bucket_alloc);
+ if (ap_run_input_pending(c) != OK) {
+ bb = ap_acquire_brigade(c);
b = apr_bucket_flush_create(c->bucket_alloc);
APR_BRIGADE_INSERT_HEAD(bb, b);
rv = ap_pass_brigade(c->output_filters, bb);
@@ -502,7 +518,7 @@ AP_DECLARE(void) ap_process_request(requ
ap_log_cerror(APLOG_MARK, APLOG_INFO, rv, c, APLOGNO(01581)
"flushing data to the client");
}
- apr_brigade_cleanup(bb);
+ ap_release_brigade(c, bb);
}
if (ap_extended_status) {
ap_time_process_request(c->sbh, STOP_PREQUEST);
@@ -779,7 +795,7 @@ AP_DECLARE(void) ap_internal_redirect(co
AP_INTERNAL_REDIRECT(r->uri, new_uri);
- /* ap_die was already called, if an error occured */
+ /* ap_die was already called, if an error occurred */
if (!new) {
return;
}
@@ -803,7 +819,7 @@ AP_DECLARE(void) ap_internal_redirect_ha
int access_status;
request_rec *new = internal_internal_redirect(new_uri, r);
- /* ap_die was already called, if an error occured */
+ /* ap_die was already called, if an error occurred */
if (!new) {
return;
}
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/mod_mime.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/mod_mime.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/mod_mime.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http/mod_mime.c Wed Sep 12 13:56:17 2018
@@ -989,9 +989,7 @@ static int find_ct(request_rec *r)
if (!r->content_languages && conf->default_language) {
const char **new;
- if (!r->content_languages) {
r->content_languages = apr_array_make(r->pool, 2, sizeof(char *));
- }
new = (const char **)apr_array_push(r->content_languages);
*new = conf->default_language;
}
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/NWGNUproxyht2
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/NWGNUproxyht2?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/NWGNUproxyht2 (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/NWGNUproxyht2 Wed Sep 12 13:56:17 2018
@@ -232,6 +232,7 @@ FILES_nlm_Ximports = \
ap_proxy_canonenc \
ap_proxy_connect_backend \
ap_proxy_connection_create \
+ ap_proxy_connection_create_ex \
ap_proxy_cookie_reverse_map \
ap_proxy_determine_connection \
ap_proxy_location_reverse_map \
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_bucket_beam.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_bucket_beam.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_bucket_beam.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_bucket_beam.c Wed Sep 12 13:56:17 2018
@@ -775,7 +775,7 @@ static apr_status_t append_bucket(h2_buc
const char *data;
apr_size_t len;
apr_status_t status;
- int can_beam, check_len;
+ int can_beam = 0, check_len;
if (beam->aborted) {
return APR_ECONNABORTED;
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_bucket_eos.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_bucket_eos.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_bucket_eos.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_bucket_eos.c Wed Sep 12 13:56:17 2018
@@ -14,22 +14,6 @@
* limitations under the License.
*/
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
#include <assert.h>
#include <stddef.h>
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_config.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_config.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_config.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_config.c Wed Sep 12 13:56:17 2018
@@ -419,7 +419,7 @@ static const char *h2_conf_add_push_prio
else if (!strcasecmp("BEFORE", sdependency)) {
dependency = H2_DEPENDANT_BEFORE;
if (sweight) {
- return "dependecy 'Before' does not allow a weight";
+ return "dependency 'Before' does not allow a weight";
}
}
else if (!strcasecmp("INTERLEAVED", sdependency)) {
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_conn.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_conn.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_conn.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_conn.c Wed Sep 12 13:56:17 2018
@@ -257,6 +257,13 @@ apr_status_t h2_conn_pre_close(struct h2
return DONE;
}
+/* APR callback invoked if allocation fails. */
+static int abort_on_oom(int retcode)
+{
+ ap_abort_on_oom();
+ return retcode; /* unreachable, hopefully. */
+}
+
conn_rec *h2_slave_create(conn_rec *master, int slave_id, apr_pool_t *parent)
{
apr_allocator_t *allocator;
@@ -286,6 +293,7 @@ conn_rec *h2_slave_create(conn_rec *mast
return NULL;
}
apr_allocator_owner_set(allocator, pool);
+ apr_pool_abort_set(abort_on_oom, pool);
apr_pool_tag(pool, "h2_slave_conn");
c = (conn_rec *) apr_palloc(pool, sizeof(conn_rec));
@@ -305,9 +313,8 @@ conn_rec *h2_slave_create(conn_rec *mast
c->notes = apr_table_make(pool, 5);
c->input_filters = NULL;
c->output_filters = NULL;
+ c->filter_conn_ctx = NULL;
c->bucket_alloc = apr_bucket_alloc_create(pool);
- c->data_in_input_filters = 0;
- c->data_in_output_filters = 0;
/* prevent mpm_event from making wrong assumptions about this connection,
* like e.g. using its socket for an async read check. */
c->clogging_input_filters = 1;
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_filter.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_filter.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_filter.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_filter.c Wed Sep 12 13:56:17 2018
@@ -431,41 +431,38 @@ static void add_stats(apr_bucket_brigade
static apr_status_t h2_status_insert(h2_task *task, apr_bucket *b)
{
- conn_rec *c = task->c->master;
- h2_ctx *h2ctx = h2_ctx_get(c, 0);
- h2_session *session;
- h2_stream *stream;
+ h2_mplx *m = task->mplx;
+ h2_stream *stream = h2_mplx_stream_get(m, task->stream_id);
+ h2_session *s;
+ conn_rec *c;
+
apr_bucket_brigade *bb;
apr_bucket *e;
int32_t connFlowIn, connFlowOut;
-
- if (!h2ctx || (session = h2_ctx_session_get(h2ctx)) == NULL) {
- return APR_SUCCESS;
- }
-
- stream = h2_session_stream_get(session, task->stream_id);
if (!stream) {
/* stream already done */
return APR_SUCCESS;
}
+ s = stream->session;
+ c = s->c;
bb = apr_brigade_create(stream->pool, c->bucket_alloc);
- connFlowIn = nghttp2_session_get_effective_local_window_size(session->ngh2);
- connFlowOut = nghttp2_session_get_remote_window_size(session->ngh2);
+ connFlowIn = nghttp2_session_get_effective_local_window_size(s->ngh2);
+ connFlowOut = nghttp2_session_get_remote_window_size(s->ngh2);
bbout(bb, "{\n");
bbout(bb, " \"version\": \"draft-01\",\n");
- add_settings(bb, session, 0);
- add_peer_settings(bb, session, 0);
+ add_settings(bb, s, 0);
+ add_peer_settings(bb, s, 0);
bbout(bb, " \"connFlowIn\": %d,\n", connFlowIn);
bbout(bb, " \"connFlowOut\": %d,\n", connFlowOut);
- bbout(bb, " \"sentGoAway\": %d,\n", session->local.shutdown);
+ bbout(bb, " \"sentGoAway\": %d,\n", s->local.shutdown);
- add_streams(bb, session, 0);
+ add_streams(bb, s, 0);
- add_stats(bb, session, stream, 1);
+ add_stats(bb, s, stream, 1);
bbout(bb, "}\n");
while ((e = APR_BRIGADE_FIRST(bb)) != APR_BRIGADE_SENTINEL(bb)) {
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_from_h1.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_from_h1.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_from_h1.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_from_h1.c Wed Sep 12 13:56:17 2018
@@ -164,7 +164,7 @@ static int copy_header(void *ctx, const
{
apr_table_t *headers = ctx;
- apr_table_addn(headers, name, value);
+ apr_table_add(headers, name, value);
return 1;
}
@@ -258,7 +258,7 @@ static h2_headers *create_response(h2_ta
if (r->no_cache && !apr_table_get(r->headers_out, "Expires")) {
char *date = apr_palloc(r->pool, APR_RFC822_DATE_LEN);
ap_recent_rfc822_date(date, r->request_time);
- apr_table_addn(r->headers_out, "Expires", date);
+ apr_table_add(r->headers_out, "Expires", date);
}
/* This is a hack, but I can't find anyway around it. The idea is that
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_h2.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_h2.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_h2.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_h2.c Wed Sep 12 13:56:17 2018
@@ -60,6 +60,7 @@ const char *H2_MAGIC_TOKEN = "PRI * HTTP
/*******************************************************************************
* The optional mod_ssl functions we need.
*/
+static APR_OPTIONAL_FN_TYPE(ssl_engine_disable) *opt_ssl_engine_disable;
static APR_OPTIONAL_FN_TYPE(ssl_is_https) *opt_ssl_is_https;
static APR_OPTIONAL_FN_TYPE(ssl_var_lookup) *opt_ssl_var_lookup;
@@ -445,6 +446,7 @@ apr_status_t h2_h2_init(apr_pool_t *pool
{
(void)pool;
ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, s, "h2_h2, child_init");
+ opt_ssl_engine_disable = APR_RETRIEVE_OPTIONAL_FN(ssl_engine_disable);
opt_ssl_is_https = APR_RETRIEVE_OPTIONAL_FN(ssl_is_https);
opt_ssl_var_lookup = APR_RETRIEVE_OPTIONAL_FN(ssl_var_lookup);
@@ -694,7 +696,7 @@ static void check_push(request_rec *r, c
tag, conf->push_list->nelts);
for (i = 0; i < conf->push_list->nelts; ++i) {
h2_push_res *push = &APR_ARRAY_IDX(conf->push_list, i, h2_push_res);
- apr_table_addn(r->headers_out, "Link",
+ apr_table_add(r->headers_out, "Link",
apr_psprintf(r->pool, "<%s>; rel=preload%s",
push->uri_ref, push->critical? "; critical" : ""));
}
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_headers.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_headers.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_headers.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_headers.c Wed Sep 12 13:56:17 2018
@@ -116,9 +116,9 @@ h2_headers *h2_headers_create(int status
{
h2_headers *headers = apr_pcalloc(pool, sizeof(h2_headers));
headers->status = status;
- headers->headers = (headers_in? apr_table_copy(pool, headers_in)
+ headers->headers = (headers_in? apr_table_clone(pool, headers_in)
: apr_table_make(pool, 5));
- headers->notes = (notes? apr_table_copy(pool, notes)
+ headers->notes = (notes? apr_table_clone(pool, notes)
: apr_table_make(pool, 5));
return headers;
}
@@ -149,8 +149,7 @@ h2_headers *h2_headers_rcreate(request_r
h2_headers *h2_headers_copy(apr_pool_t *pool, h2_headers *h)
{
- return h2_headers_create(h->status, apr_table_copy(pool, h->headers),
- apr_table_copy(pool, h->notes), h->raw_bytes, pool);
+ return h2_headers_create(h->status, h->headers, h->notes, h->raw_bytes, pool);
}
h2_headers *h2_headers_die(apr_status_t type,
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_headers.h
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_headers.h?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_headers.h (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_headers.h Wed Sep 12 13:56:17 2018
@@ -66,7 +66,6 @@ h2_headers *h2_headers_copy(apr_pool_t *
/**
* Create the headers for the given error.
- * @param stream_id id of the stream to create the headers for
* @param type the error code
* @param req the original h2_request
* @param pool the memory pool to use
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_mplx.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_mplx.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_mplx.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_mplx.c Wed Sep 12 13:56:17 2018
@@ -473,6 +473,7 @@ void h2_mplx_release_and_join(h2_mplx *m
h2_ihash_iter(m->shold, report_stream_iter, m);
}
}
+ ap_assert(m->tasks_active == 0);
m->join_wait = NULL;
/* 4. close the h2_req_enginge shed */
@@ -762,6 +763,9 @@ apr_status_t h2_mplx_pop_task(h2_mplx *m
apr_status_t rv = APR_EOF;
*ptask = NULL;
+ ap_assert(m);
+ ap_assert(m->lock);
+
if (APR_SUCCESS != (rv = apr_thread_mutex_lock(m->lock))) {
return rv;
}
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_ngn_shed.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_ngn_shed.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_ngn_shed.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_ngn_shed.c Wed Sep 12 13:56:17 2018
@@ -281,7 +281,7 @@ apr_status_t h2_ngn_shed_pull_request(h2
if (H2_REQ_ENTRIES_EMPTY(&ngn->entries)) {
if (want_shutdown) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, shed->c,
- "h2_ngn_shed(%ld): emtpy queue, shutdown engine %s",
+ "h2_ngn_shed(%ld): empty queue, shutdown engine %s",
shed->c->id, ngn->id);
ngn->shutdown = 1;
}
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_proxy_session.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_proxy_session.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_proxy_session.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_proxy_session.c Wed Sep 12 13:56:17 2018
@@ -237,7 +237,7 @@ static int before_frame_send(nghttp2_ses
static int add_header(void *table, const char *n, const char *v)
{
- apr_table_addn(table, n, v);
+ apr_table_add(table, n, v);
return 1;
}
@@ -361,7 +361,7 @@ static void h2_proxy_stream_end_headers_
}
/* create a "Via:" response header entry and merge it */
- apr_table_addn(r->headers_out, "Via",
+ apr_table_add(r->headers_out, "Via",
(session->conf->viaopt == via_full)
? apr_psprintf(p, "%d.%d %s%s (%s)",
HTTP_VERSION_MAJOR(r->proto_num),
@@ -493,8 +493,8 @@ static ssize_t stream_request_data(nghtt
stream = nghttp2_session_get_stream_user_data(ngh2, stream_id);
if (!stream) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(03361)
- "h2_proxy_stream(%s): data_read, stream %d not found",
- stream->session->id, stream_id);
+ "h2_proxy_stream(NULL): data_read, stream %d not found",
+ stream_id);
return NGHTTP2_ERR_CALLBACK_FAILURE;
}
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_proxy_util.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_proxy_util.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_proxy_util.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_proxy_util.c Wed Sep 12 13:56:17 2018
@@ -915,12 +915,12 @@ static size_t subst_str(link_ctx *ctx, i
nlen = (int)strlen(ns);
delta = nlen - olen;
plen = ctx->slen + delta + 1;
- p = apr_pcalloc(ctx->pool, plen);
+ p = apr_palloc(ctx->pool, plen);
memcpy(p, ctx->s, start);
memcpy(p + start, ns, nlen);
strcpy(p + start + nlen, ctx->s + end);
ctx->s = p;
- ctx->slen = (int)strlen(p);
+ ctx->slen = plen - 1; /* (int)strlen(p) */
if (ctx->i >= end) {
ctx->i += delta;
}
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_request.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_request.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_request.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_request.c Wed Sep 12 13:56:17 2018
@@ -210,57 +210,11 @@ request_rec *h2_request_create_rec(const
{
int access_status = HTTP_OK;
const char *rpath;
- apr_pool_t *p;
- request_rec *r;
const char *s;
- apr_pool_create(&p, c->pool);
- apr_pool_tag(p, "request");
- r = apr_pcalloc(p, sizeof(request_rec));
- AP_READ_REQUEST_ENTRY((intptr_t)r, (uintptr_t)c);
- r->pool = p;
- r->connection = c;
- r->server = c->base_server;
-
- r->user = NULL;
- r->ap_auth_type = NULL;
-
- r->allowed_methods = ap_make_method_list(p, 2);
+ request_rec *r = ap_create_request(c);
r->headers_in = apr_table_clone(r->pool, req->headers);
- r->trailers_in = apr_table_make(r->pool, 5);
- r->subprocess_env = apr_table_make(r->pool, 25);
- r->headers_out = apr_table_make(r->pool, 12);
- r->err_headers_out = apr_table_make(r->pool, 5);
- r->trailers_out = apr_table_make(r->pool, 5);
- r->notes = apr_table_make(r->pool, 5);
-
- r->request_config = ap_create_request_config(r->pool);
- /* Must be set before we run create request hook */
-
- r->proto_output_filters = c->output_filters;
- r->output_filters = r->proto_output_filters;
- r->proto_input_filters = c->input_filters;
- r->input_filters = r->proto_input_filters;
- ap_run_create_request(r);
- r->per_dir_config = r->server->lookup_defaults;
-
- r->sent_bodyct = 0; /* bytect isn't for body */
-
- r->read_length = 0;
- r->read_body = REQUEST_NO_BODY;
-
- r->status = HTTP_OK; /* Until further notice */
- r->header_only = 0;
- r->the_request = NULL;
-
- /* Begin by presuming any module can make its own path_info assumptions,
- * until some module interjects and changes the value.
- */
- r->used_path_info = AP_REQ_DEFAULT_PATH_INFO;
-
- r->useragent_addr = c->client_addr;
- r->useragent_ip = c->client_ip;
ap_run_pre_read_request(r, c);
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_session.c
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_session.c?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_session.c (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_session.c Wed Sep 12 13:56:17 2018
@@ -73,7 +73,7 @@ static int h2_session_status_from_apr_st
return NGHTTP2_ERR_PROTO;
}
-h2_stream *h2_session_stream_get(h2_session *session, int stream_id)
+static h2_stream *get_stream(h2_session *session, int stream_id)
{
return nghttp2_session_get_stream_user_data(session->ngh2, stream_id);
}
@@ -232,9 +232,10 @@ static int on_data_chunk_recv_cb(nghttp2
h2_stream * stream;
int rv = 0;
- stream = h2_session_stream_get(session, stream_id);
+ stream = get_stream(session, stream_id);
if (stream) {
status = h2_stream_recv_DATA(stream, flags, data, len);
+ dispatch_event(session, H2_SESSION_EV_STREAM_CHANGE, 0, "stream data rcvd");
}
else {
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c, APLOGNO(03064)
@@ -257,7 +258,7 @@ static int on_stream_close_cb(nghttp2_se
h2_stream *stream;
(void)ngh2;
- stream = h2_session_stream_get(session, stream_id);
+ stream = get_stream(session, stream_id);
if (stream) {
if (error_code) {
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
@@ -279,7 +280,7 @@ static int on_begin_headers_cb(nghttp2_s
/* We may see HEADERs at the start of a stream or after all DATA
* streams to carry trailers. */
(void)ngh2;
- s = h2_session_stream_get(session, frame->hd.stream_id);
+ s = get_stream(session, frame->hd.stream_id);
if (s) {
/* nop */
}
@@ -300,7 +301,7 @@ static int on_header_cb(nghttp2_session
apr_status_t status;
(void)flags;
- stream = h2_session_stream_get(session, frame->hd.stream_id);
+ stream = get_stream(session, frame->hd.stream_id);
if (!stream) {
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c, APLOGNO(02920)
"h2_stream(%ld-%d): on_header unknown stream",
@@ -317,9 +318,9 @@ static int on_header_cb(nghttp2_session
}
/**
- * nghttp2 session has received a complete frame. Most, it uses
- * for processing of internal state. HEADER and DATA frames however
- * we need to handle ourself.
+ * nghttp2 session has received a complete frame. Most are used by nghttp2
+ * for processing of internal state. Some, like HEADER and DATA frames,
+ * we need to act on.
*/
static int on_frame_recv_cb(nghttp2_session *ng2s,
const nghttp2_frame *frame,
@@ -346,14 +347,14 @@ static int on_frame_recv_cb(nghttp2_sess
/* This can be HEADERS for a new stream, defining the request,
* or HEADER may come after DATA at the end of a stream as in
* trailers */
- stream = h2_session_stream_get(session, frame->hd.stream_id);
+ stream = get_stream(session, frame->hd.stream_id);
if (stream) {
rv = h2_stream_recv_frame(stream, NGHTTP2_HEADERS, frame->hd.flags,
frame->hd.length + H2_FRAME_HDR_LEN);
}
break;
case NGHTTP2_DATA:
- stream = h2_session_stream_get(session, frame->hd.stream_id);
+ stream = get_stream(session, frame->hd.stream_id);
if (stream) {
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
H2_STRM_LOG(APLOGNO(02923), stream,
@@ -378,13 +379,16 @@ static int on_frame_recv_cb(nghttp2_sess
"h2_stream(%ld-%d): WINDOW_UPDATE incr=%d",
session->id, (int)frame->hd.stream_id,
frame->window_update.window_size_increment);
+ if (nghttp2_session_want_write(session->ngh2)) {
+ dispatch_event(session, H2_SESSION_EV_FRAME_RCVD, 0, "window update");
+ }
break;
case NGHTTP2_RST_STREAM:
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c, APLOGNO(03067)
"h2_stream(%ld-%d): RST_STREAM by client, errror=%d",
session->id, (int)frame->hd.stream_id,
(int)frame->rst_stream.error_code);
- stream = h2_session_stream_get(session, frame->hd.stream_id);
+ stream = get_stream(session, frame->hd.stream_id);
if (stream && stream->initiated_on) {
++session->pushes_reset;
}
@@ -404,6 +408,12 @@ static int on_frame_recv_cb(nghttp2_sess
frame->goaway.error_code, NULL);
}
break;
+ case NGHTTP2_SETTINGS:
+ if (APLOGctrace2(session->c)) {
+ ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, session->c,
+ H2_SSSN_MSG(session, "SETTINGS, len=%ld"), (long)frame->hd.length);
+ }
+ break;
default:
if (APLOGctrace2(session->c)) {
char buffer[256];
@@ -415,7 +425,40 @@ static int on_frame_recv_cb(nghttp2_sess
}
break;
}
- return (APR_SUCCESS == rv)? 0 : NGHTTP2_ERR_PROTO;
+
+ if (session->state == H2_SESSION_ST_IDLE) {
+ /* We received a frame, but session is in state IDLE. That means the frame
+ * did not really progress any of the (possibly) open streams. It was a meta
+ * frame, e.g. SETTINGS/WINDOW_UPDATE/unknown/etc.
+ * Remember: IDLE means we cannot send because either there are no streams open or
+ * all open streams are blocked on exhausted WINDOWs for outgoing data.
+ * The more frames we receive that do not change this, the less interested we
+ * become in serving this connection. This is expressed in increasing "idle_delays".
+ * Eventually, the connection will timeout and we'll close it. */
+ session->idle_frames = H2MIN(session->idle_frames + 1, session->frames_received);
+ ap_log_cerror( APLOG_MARK, APLOG_TRACE2, 0, session->c,
+ H2_SSSN_MSG(session, "session has %ld idle frames"),
+ (long)session->idle_frames);
+ if (session->idle_frames > 10) {
+ apr_size_t busy_frames = H2MAX(session->frames_received - session->idle_frames, 1);
+ int idle_ratio = (int)(session->idle_frames / busy_frames);
+ if (idle_ratio > 100) {
+ session->idle_delay = apr_time_from_msec(H2MIN(1000, idle_ratio));
+}
+ else if (idle_ratio > 10) {
+ session->idle_delay = apr_time_from_msec(10);
+ }
+ else if (idle_ratio > 1) {
+ session->idle_delay = apr_time_from_msec(1);
+ }
+ else {
+ session->idle_delay = 0;
+ }
+ }
+ }
+
+ if (APR_SUCCESS != rv) return NGHTTP2_ERR_PROTO;
+ return 0;
}
static int h2_session_continue_data(h2_session *session) {
@@ -457,7 +500,7 @@ static int on_send_data_cb(nghttp2_sessi
}
padlen = (unsigned char)frame->data.padlen;
- stream = h2_session_stream_get(session, stream_id);
+ stream = get_stream(session, stream_id);
if (!stream) {
ap_log_cerror(APLOG_MARK, APLOG_ERR, APR_NOTFOUND, session->c,
APLOGNO(02924)
@@ -546,7 +589,7 @@ static int on_frame_send_cb(nghttp2_sess
(long)session->frames_sent);
}
- stream = h2_session_stream_get(session, stream_id);
+ stream = get_stream(session, stream_id);
if (stream) {
h2_stream_send_frame(stream, frame->hd.type, frame->hd.flags,
frame->hd.length + H2_FRAME_HDR_LEN);
@@ -571,7 +614,7 @@ static int on_invalid_header_cb(nghttp2_
apr_pstrndup(session->pool, (const char *)name, namelen),
apr_pstrndup(session->pool, (const char *)value, valuelen));
}
- stream = h2_session_stream_get(session, frame->hd.stream_id);
+ stream = get_stream(session, frame->hd.stream_id);
if (stream) {
h2_stream_rst(stream, NGHTTP2_PROTOCOL_ERROR);
}
@@ -1033,7 +1076,7 @@ static ssize_t stream_data_cb(nghttp2_se
(void)ng2s;
(void)buf;
(void)source;
- stream = h2_session_stream_get(session, stream_id);
+ stream = get_stream(session, stream_id);
if (!stream) {
ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, session->c,
APLOGNO(02937)
@@ -1215,7 +1258,7 @@ apr_status_t h2_session_set_prio(h2_sess
rv = nghttp2_session_change_stream_priority(session->ngh2, stream->id, &ps);
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
- ""H2_STRM_LOG(APLOGNO(03203), stream,
+ H2_STRM_LOG(APLOGNO(03203), stream,
"PUSH %s, weight=%d, depends=%d, returned=%d"),
ptype, ps.weight, ps.stream_id, rv);
status = (rv < 0)? APR_EGENERAL : APR_SUCCESS;
@@ -1473,7 +1516,7 @@ static void h2_session_in_flush(h2_sessi
int id;
while ((id = h2_iq_shift(session->in_process)) > 0) {
- h2_stream *stream = h2_session_stream_get(session, id);
+ h2_stream *stream = get_stream(session, id);
if (stream) {
ap_assert(!stream->scheduled);
if (h2_stream_prep_processing(stream) == APR_SUCCESS) {
@@ -1486,7 +1529,7 @@ static void h2_session_in_flush(h2_sessi
}
while ((id = h2_iq_shift(session->in_pending)) > 0) {
- h2_stream *stream = h2_session_stream_get(session, id);
+ h2_stream *stream = get_stream(session, id);
if (stream) {
h2_stream_flush_input(stream);
}
@@ -1603,23 +1646,57 @@ static void update_child_status(h2_sessi
static void transit(h2_session *session, const char *action, h2_session_state nstate)
{
+ apr_time_t timeout;
+ int ostate, loglvl;
+ const char *s;
+
if (session->state != nstate) {
- int loglvl = APLOG_DEBUG;
- if ((session->state == H2_SESSION_ST_BUSY && nstate == H2_SESSION_ST_WAIT)
- || (session->state == H2_SESSION_ST_WAIT && nstate == H2_SESSION_ST_BUSY)){
+ ostate = session->state;
+ session->state = nstate;
+
+ loglvl = APLOG_DEBUG;
+ if ((ostate == H2_SESSION_ST_BUSY && nstate == H2_SESSION_ST_WAIT)
+ || (ostate == H2_SESSION_ST_WAIT && nstate == H2_SESSION_ST_BUSY)){
loglvl = APLOG_TRACE1;
}
ap_log_cerror(APLOG_MARK, loglvl, 0, session->c,
H2_SSSN_LOG(APLOGNO(03078), session,
"transit [%s] -- %s --> [%s]"),
- h2_session_state_str(session->state), action,
+ h2_session_state_str(ostate), action,
h2_session_state_str(nstate));
- session->state = nstate;
+
switch (session->state) {
case H2_SESSION_ST_IDLE:
- update_child_status(session, (session->open_streams == 0?
- SERVER_BUSY_KEEPALIVE
- : SERVER_BUSY_READ), "idle");
+ if (!session->remote.emitted_count) {
+ /* on fresh connections, with async mpm, do not return
+ * to mpm for a second. This gives the first request a better
+ * chance to arrive (und connection leaving IDLE state).
+ * If we return to mpm right away, this connection has the
+ * same chance of being cleaned up by the mpm as connections
+ * that already served requests - not fair. */
+ session->idle_sync_until = apr_time_now() + apr_time_from_sec(1);
+ s = "timeout";
+ timeout = H2MAX(session->s->timeout, session->s->keep_alive_timeout);
+ update_child_status(session, SERVER_BUSY_READ, "idle");
+ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c,
+ H2_SSSN_LOG("", session, "enter idle, timeout = %d sec"),
+ (int)apr_time_sec(H2MAX(session->s->timeout, session->s->keep_alive_timeout)));
+ }
+ else if (session->open_streams) {
+ s = "timeout";
+ timeout = session->s->keep_alive_timeout;
+ update_child_status(session, SERVER_BUSY_KEEPALIVE, "idle");
+ }
+ else {
+ /* normal keepalive setup */
+ s = "keepalive";
+ timeout = session->s->keep_alive_timeout;
+ update_child_status(session, SERVER_BUSY_KEEPALIVE, "idle");
+ }
+ session->idle_until = apr_time_now() + timeout;
+ ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c,
+ H2_SSSN_LOG("", session, "enter idle, %s = %d sec"),
+ s, (int)apr_time_sec(timeout));
break;
case H2_SESSION_ST_DONE:
update_child_status(session, SERVER_CLOSING, "done");
@@ -1726,8 +1803,6 @@ static void h2_session_ev_no_io(h2_sessi
* This means we only wait for WINDOW_UPDATE from the
* client and can block on READ. */
transit(session, "no io (flow wait)", H2_SESSION_ST_IDLE);
- session->idle_until = apr_time_now() + session->s->timeout;
- session->keep_sync_until = session->idle_until;
/* Make sure we have flushed all previously written output
* so that the client will react. */
if (h2_conn_io_flush(&session->io) != APR_SUCCESS) {
@@ -1738,12 +1813,7 @@ static void h2_session_ev_no_io(h2_sessi
}
else if (session->local.accepting) {
/* When we have no streams, but accept new, switch to idle */
- apr_time_t now = apr_time_now();
transit(session, "no io (keepalive)", H2_SESSION_ST_IDLE);
- session->idle_until = (session->remote.emitted_count?
- session->s->keep_alive_timeout :
- session->s->timeout) + now;
- session->keep_sync_until = now + apr_time_from_sec(1);
}
else {
/* We are no longer accepting new streams and there are
@@ -1758,12 +1828,25 @@ static void h2_session_ev_no_io(h2_sessi
}
}
-static void h2_session_ev_data_read(h2_session *session, int arg, const char *msg)
+static void h2_session_ev_frame_rcvd(h2_session *session, int arg, const char *msg)
{
switch (session->state) {
case H2_SESSION_ST_IDLE:
case H2_SESSION_ST_WAIT:
- transit(session, "data read", H2_SESSION_ST_BUSY);
+ transit(session, "frame received", H2_SESSION_ST_BUSY);
+ break;
+ default:
+ /* nop */
+ break;
+ }
+}
+
+static void h2_session_ev_stream_change(h2_session *session, int arg, const char *msg)
+{
+ switch (session->state) {
+ case H2_SESSION_ST_IDLE:
+ case H2_SESSION_ST_WAIT:
+ transit(session, "stream change", H2_SESSION_ST_BUSY);
break;
default:
/* nop */
@@ -1803,17 +1886,7 @@ static void h2_session_ev_pre_close(h2_s
static void ev_stream_open(h2_session *session, h2_stream *stream)
{
h2_iq_append(session->in_process, stream->id);
- switch (session->state) {
- case H2_SESSION_ST_IDLE:
- if (session->open_streams == 1) {
- /* enter timeout, since we have a stream again */
- session->idle_until = (session->s->timeout + apr_time_now());
}
- break;
- default:
- break;
- }
-}
static void ev_stream_closed(h2_session *session, h2_stream *stream)
{
@@ -1825,11 +1898,6 @@ static void ev_stream_closed(h2_session
}
switch (session->state) {
case H2_SESSION_ST_IDLE:
- if (session->open_streams == 0) {
- /* enter keepalive timeout, since we no longer have streams */
- session->idle_until = (session->s->keep_alive_timeout
- + apr_time_now());
- }
break;
default:
break;
@@ -1887,6 +1955,7 @@ static void on_stream_state_enter(void *
default:
break;
}
+ dispatch_event(session, H2_SESSION_EV_STREAM_CHANGE, 0, "stream state change");
}
static void on_stream_event(void *ctx, h2_stream *stream,
@@ -1945,8 +2014,8 @@ static void dispatch_event(h2_session *s
case H2_SESSION_EV_NO_IO:
h2_session_ev_no_io(session, arg, msg);
break;
- case H2_SESSION_EV_DATA_READ:
- h2_session_ev_data_read(session, arg, msg);
+ case H2_SESSION_EV_FRAME_RCVD:
+ h2_session_ev_frame_rcvd(session, arg, msg);
break;
case H2_SESSION_EV_NGH2_DONE:
h2_session_ev_ngh2_done(session, arg, msg);
@@ -1957,6 +2026,9 @@ static void dispatch_event(h2_session *s
case H2_SESSION_EV_PRE_CLOSE:
h2_session_ev_pre_close(session, arg, msg);
break;
+ case H2_SESSION_EV_STREAM_CHANGE:
+ h2_session_ev_stream_change(session, arg, msg);
+ break;
default:
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c,
H2_SSSN_MSG(session, "unknown event %d"), ev);
@@ -1990,6 +2062,7 @@ apr_status_t h2_session_process(h2_sessi
apr_status_t status = APR_SUCCESS;
conn_rec *c = session->c;
int rv, mpm_state, trace = APLOGctrace3(c);
+ apr_time_t now;
if (trace) {
ap_log_cerror( APLOG_MARK, APLOG_TRACE3, status, c,
@@ -1997,6 +2070,7 @@ apr_status_t h2_session_process(h2_sessi
}
while (session->state != H2_SESSION_ST_DONE) {
+ now = apr_time_now();
session->have_read = session->have_written = 0;
if (session->local.accepting
@@ -2034,40 +2108,43 @@ apr_status_t h2_session_process(h2_sessi
break;
case H2_SESSION_ST_IDLE:
- /* We trust our connection into the default timeout/keepalive
- * handling of the core filters/mpm iff:
- * - keep_sync_until is not set
- * - we have an async mpm
- * - we have no open streams to process
- * - we are not sitting on a Upgrade: request
- * - we already have seen at least one request
- */
- if (!session->keep_sync_until && async && !session->open_streams
- && !session->r && session->remote.emitted_count) {
+ if (session->idle_until && (apr_time_now() + session->idle_delay) > session->idle_until) {
+ ap_log_cerror( APLOG_MARK, APLOG_TRACE1, status, c,
+ H2_SSSN_MSG(session, "idle, timeout reached, closing"));
+ if (session->idle_delay) {
+ apr_table_setn(session->c->notes, "short-lingering-close", "1");
+ }
+ dispatch_event(session, H2_SESSION_EV_CONN_TIMEOUT, 0, "timeout");
+ goto out;
+ }
+
+ if (session->idle_delay) {
+ /* we are less interested in spending time on this connection */
+ ap_log_cerror( APLOG_MARK, APLOG_TRACE2, status, c,
+ H2_SSSN_MSG(session, "session is idle (%ld ms), idle wait %ld sec left"),
+ (long)apr_time_as_msec(session->idle_delay),
+ (long)apr_time_sec(session->idle_until - now));
+ apr_sleep(session->idle_delay);
+ session->idle_delay = 0;
+ }
+
+ h2_conn_io_flush(&session->io);
+ if (async && !session->r && (now > session->idle_sync_until)) {
if (trace) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE3, status, c,
H2_SSSN_MSG(session,
"nonblock read, %d streams open"),
session->open_streams);
}
- h2_conn_io_flush(&session->io);
status = h2_session_read(session, 0);
if (status == APR_SUCCESS) {
session->have_read = 1;
- dispatch_event(session, H2_SESSION_EV_DATA_READ, 0, NULL);
}
- else if (APR_STATUS_IS_EAGAIN(status)
- || APR_STATUS_IS_TIMEUP(status)) {
- if (apr_time_now() > session->idle_until) {
- dispatch_event(session,
- H2_SESSION_EV_CONN_TIMEOUT, 0, NULL);
- }
- else {
+ else if (APR_STATUS_IS_EAGAIN(status) || APR_STATUS_IS_TIMEUP(status)) {
status = APR_EAGAIN;
goto out;
}
- }
else {
ap_log_cerror(APLOG_MARK, APLOG_DEBUG, status, c,
H2_SSSN_LOG(APLOGNO(03403), session,
@@ -2078,7 +2155,6 @@ apr_status_t h2_session_process(h2_sessi
}
else {
/* make certain, we send everything before we idle */
- h2_conn_io_flush(&session->io);
if (trace) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE3, status, c,
H2_SSSN_MSG(session,
@@ -2090,7 +2166,6 @@ apr_status_t h2_session_process(h2_sessi
*/
status = h2_mplx_idle(session->mplx);
if (status == APR_EAGAIN) {
- dispatch_event(session, H2_SESSION_EV_DATA_READ, 0, NULL);
break;
}
else if (status != APR_SUCCESS) {
@@ -2101,33 +2176,11 @@ apr_status_t h2_session_process(h2_sessi
status = h2_session_read(session, 1);
if (status == APR_SUCCESS) {
session->have_read = 1;
- dispatch_event(session, H2_SESSION_EV_DATA_READ, 0, NULL);
}
else if (status == APR_EAGAIN) {
/* nothing to read */
}
else if (APR_STATUS_IS_TIMEUP(status)) {
- apr_time_t now = apr_time_now();
- if (now > session->keep_sync_until) {
- /* if we are on an async mpm, now is the time that
- * we may dare to pass control to it. */
- session->keep_sync_until = 0;
- }
- if (now > session->idle_until) {
- if (trace) {
- ap_log_cerror(APLOG_MARK, APLOG_TRACE3, status, c,
- H2_SSSN_MSG(session,
- "keepalive timeout"));
- }
- dispatch_event(session,
- H2_SESSION_EV_CONN_TIMEOUT, 0, "timeout");
- }
- else if (trace) {
- ap_log_cerror(APLOG_MARK, APLOG_TRACE3, status, c,
- H2_SSSN_MSG(session,
- "keepalive, %f sec left"),
- (session->idle_until - now) / 1000000.0f);
- }
/* continue reading handling */
}
else if (APR_STATUS_IS_ECONNABORTED(status)
@@ -2145,6 +2198,18 @@ apr_status_t h2_session_process(h2_sessi
dispatch_event(session, H2_SESSION_EV_CONN_ERROR, 0, "error");
}
}
+ if (nghttp2_session_want_write(session->ngh2)) {
+ ap_update_child_status(session->c->sbh, SERVER_BUSY_WRITE, NULL);
+ status = h2_session_send(session);
+ if (status == APR_SUCCESS) {
+ status = h2_conn_io_flush(&session->io);
+ }
+ if (status != APR_SUCCESS) {
+ dispatch_event(session, H2_SESSION_EV_CONN_ERROR,
+ H2_ERR_INTERNAL_ERROR, "writing");
+ break;
+ }
+ }
break;
case H2_SESSION_ST_BUSY:
@@ -2154,7 +2219,6 @@ apr_status_t h2_session_process(h2_sessi
status = h2_session_read(session, 0);
if (status == APR_SUCCESS) {
session->have_read = 1;
- dispatch_event(session, H2_SESSION_EV_DATA_READ, 0, NULL);
}
else if (status == APR_EAGAIN) {
/* nothing to read */
@@ -2218,7 +2282,7 @@ apr_status_t h2_session_process(h2_sessi
session->iowait);
if (status == APR_SUCCESS) {
session->wait_us = 0;
- dispatch_event(session, H2_SESSION_EV_DATA_READ, 0, NULL);
+ dispatch_event(session, H2_SESSION_EV_STREAM_CHANGE, 0, NULL);
}
else if (APR_STATUS_IS_TIMEUP(status)) {
/* go back to checking all inputs again */
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_session.h
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_session.h?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_session.h (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_session.h Wed Sep 12 13:56:17 2018
@@ -66,10 +66,11 @@ typedef enum {
H2_SESSION_EV_PROTO_ERROR, /* protocol error */
H2_SESSION_EV_CONN_TIMEOUT, /* connection timeout */
H2_SESSION_EV_NO_IO, /* nothing has been read or written */
- H2_SESSION_EV_DATA_READ, /* connection data has been read */
+ H2_SESSION_EV_FRAME_RCVD, /* a frame has been received */
H2_SESSION_EV_NGH2_DONE, /* nghttp2 wants neither read nor write anything */
H2_SESSION_EV_MPM_STOPPING, /* the process is stopping */
H2_SESSION_EV_PRE_CLOSE, /* connection will close after this */
+ H2_SESSION_EV_STREAM_CHANGE, /* a stream (state/input/output) changed */
} h2_session_event_t;
typedef struct h2_session {
@@ -118,7 +119,9 @@ typedef struct h2_session {
apr_size_t max_stream_mem; /* max buffer memory for a single stream */
apr_time_t idle_until; /* Time we shut down due to sheer boredom */
- apr_time_t keep_sync_until; /* Time we sync wait until passing to async mpm */
+ apr_time_t idle_sync_until; /* Time we sync wait until keepalive handling kicks in */
+ apr_size_t idle_frames; /* number of rcvd frames that kept session in idle state */
+ apr_interval_time_t idle_delay; /* Time we delay processing rcvd frames in idle state */
apr_bucket_brigade *bbtmp; /* brigade for keeping temporary data */
struct apr_thread_cond_t *iowait; /* our cond when trywaiting for data */
@@ -196,11 +199,6 @@ void h2_session_close(h2_session *sessio
int h2_session_push_enabled(h2_session *session);
/**
- * Look up the stream in this session with the given id.
- */
-struct h2_stream *h2_session_stream_get(h2_session *session, int stream_id);
-
-/**
* Submit a push promise on the stream and schedule the new steam for
* processing..
*
Modified: httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_task.h
URL: http://svn.apache.org/viewvc/httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_task.h?rev=1840688&r1=1840687&r2=1840688&view=diff
==============================================================================
--- httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_task.h (original)
+++ httpd/sandbox/httpd-2.4.x-trunk-delta/modules/http2/h2_task.h Wed Sep 12 13:56:17 2018
@@ -21,7 +21,7 @@
/**
* A h2_task fakes a HTTP/1.1 request from the data in a HTTP/2 stream
- * (HEADER+CONT.+DATA) the module recieves.
+ * (HEADER+CONT.+DATA) the module receives.
*
* In order to answer a HTTP/2 stream, we want all Apache httpd infrastructure
* to be involved as usual, as if this stream can as a separate HTTP/1.1
@@ -113,7 +113,7 @@ void h2_task_rst(h2_task *task, int erro
void h2_task_register_hooks(void);
/*
- * One time, post config intialization.
+ * One time, post config initialization.
*/
apr_status_t h2_task_init(apr_pool_t *pool, server_rec *s);