Welcome! Log In Create A New Profile

Advanced

Re: [PATCH 2 of 3] HTTP/2: "http2" directive

Sergey Kandaurov
February 09, 2023 10:58AM
> On 9 Feb 2023, at 16:33, Roman Arutyunyan <arut@nginx.com> wrote:
>
> Hi,
>
> On Thu, Feb 09, 2023 at 04:02:34PM +0400, Roman Arutyunyan wrote:
>
> [..]
>
>> diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
>> --- a/src/http/ngx_http_request.c
>> +++ b/src/http/ngx_http_request.c
>> @@ -318,12 +318,6 @@ ngx_http_init_connection(ngx_connection_
>> rev->handler = ngx_http_wait_request_handler;
>> c->write->handler = ngx_http_empty_handler;
>>
>> -#if (NGX_HTTP_V2)
>> - if (hc->addr_conf->http2) {
>> - rev->handler = ngx_http_v2_init;
>> - }
>> -#endif
>> -
>> #if (NGX_HTTP_V3)
>> if (hc->addr_conf->quic) {
>> ngx_http_v3_init_stream(c);
>> @@ -383,6 +377,9 @@ ngx_http_wait_request_handler(ngx_event_
>> ngx_buf_t *b;
>> ngx_connection_t *c;
>> ngx_http_connection_t *hc;
>> +#if (NGX_HTTP_V2)
>> + ngx_http_v2_srv_conf_t *h2scf;
>> +#endif
>> ngx_http_core_srv_conf_t *cscf;
>>
>> c = rev->data;
>> @@ -429,6 +426,8 @@ ngx_http_wait_request_handler(ngx_event_
>> b->end = b->last + size;
>> }
>>
>> + size = b->end - b->last;
>> +
>> n = c->recv(c, b->last, size);
>>
>> if (n == NGX_AGAIN) {
>> @@ -443,12 +442,16 @@ ngx_http_wait_request_handler(ngx_event_
>> return;
>> }
>>
>> - /*
>> - * We are trying to not hold c->buffer's memory for an idle connection.
>> - */
>> -
>> - if (ngx_pfree(c->pool, b->start) == NGX_OK) {
>> - b->start = NULL;
>> + if (b->pos == b->last) {
>> +
>> + /*
>> + * We are trying to not hold c->buffer's memory for an
>> + * idle connection.
>> + */
>> +
>> + if (ngx_pfree(c->pool, b->start) == NGX_OK) {
>> + b->start = NULL;
>> + }
>> }
>>
>> return;
>> @@ -489,10 +492,34 @@ ngx_http_wait_request_handler(ngx_event_
>> }
>> }
>>
>> + ngx_reusable_connection(c, 0);
>> +
>> +#if (NGX_HTTP_V2)
>> +
>> + h2scf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_v2_module);
>> +
>> + if (!c->ssl && (h2scf->enable || hc->addr_conf->http2)) {
>
> And one more fix for compilation with HTTP/2, but without SSL:
>
> diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
> --- a/src/http/ngx_http_request.c
> +++ b/src/http/ngx_http_request.c
> @@ -498,8 +498,12 @@ ngx_http_wait_request_handler(ngx_event_
>
> h2scf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_v2_module);
>
> - if (!c->ssl && (h2scf->enable || hc->addr_conf->http2)) {
> -
> + if ((h2scf->enable || hc->addr_conf->http2)
> +#if (NGX_HTTP_SSL)
> + && !c->ssl
> +#endif
> + )
> + {
> size = ngx_min(sizeof(NGX_HTTP_V2_PREFACE) - 1,
> (size_t) (b->last - b->pos));
>

I think this test needs to be replaced with !hc->ssl.
Otherwise, it would allow to establish (and keep) h2c on ssl-enabled
sockets, which we likely do not want to allow.

>
>> +
>> + size = ngx_min(sizeof(NGX_HTTP_V2_PREFACE) - 1,
>> + (size_t) (b->last - b->pos));
>> +
>> + if (ngx_memcmp(b->pos, NGX_HTTP_V2_PREFACE, size) == 0) {
>> +
>> + if (size == sizeof(NGX_HTTP_V2_PREFACE) - 1) {
>> + ngx_http_v2_init(rev);
>> + return;
>> + }
>> +
>> + c->log->action = "waiting for request";
>> + ngx_post_event(rev, &ngx_posted_events);
>> + return;
>> + }
>> + }
>> +
>> +#endif
>> +
>> c->log->action = "reading client request line";
>>
>> - ngx_reusable_connection(c, 0);
>> -
>> c->data = ngx_http_create_request(c);
>> if (c->data == NULL) {
>> ngx_http_close_connection(c);
>
> [..]
>

--
Sergey Kandaurov
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH 0 of 3] Directives for enabling http2 and http3

Roman Arutyunyan 871 January 26, 2023 06:52AM

[PATCH 1 of 3] HTTP/3: "quic" parameter of "listen" directive

Roman Arutyunyan 237 January 26, 2023 06:52AM

Re: [PATCH 1 of 3] HTTP/3: "quic" parameter of "listen" directive

Maxim Dounin 204 January 29, 2023 08:28PM

[PATCH 2 of 3] HTTP/3: trigger more compatibility errors for "listen quic"

Roman Arutyunyan 197 January 26, 2023 06:52AM

Re: [PATCH 2 of 3] HTTP/3: trigger more compatibility errors for "listen quic"

Maxim Dounin 151 January 29, 2023 08:28PM

[PATCH 3 of 3] HTTP/2: "http2" directive

Roman Arutyunyan 396 January 26, 2023 06:52AM

Re: [PATCH 3 of 3] HTTP/2: "http2" directive

Maxim Dounin 152 January 29, 2023 08:30PM

[PATCH 0 of 3] Directives for enabling http2 and http3

Roman Arutyunyan 146 February 01, 2023 09:02AM

[PATCH 1 of 3] HTTP/3: "quic" parameter of "listen" directive

Roman Arutyunyan 138 February 01, 2023 09:02AM

Re: [PATCH 1 of 3] HTTP/3: "quic" parameter of "listen" directive

Liam Crilly via nginx-devel 209 February 01, 2023 09:20AM

Re: [PATCH 1 of 3] HTTP/3: "quic" parameter of "listen" directive

Roman Arutyunyan 256 February 01, 2023 09:26AM

Re: [PATCH 1 of 3] HTTP/3: "quic" parameter of "listen" directive

Sergey Kandaurov 165 February 06, 2023 10:28AM

Re: [PATCH 1 of 3] HTTP/3: "quic" parameter of "listen" directive

Maxim Dounin 187 February 06, 2023 10:14PM

Re: [PATCH 1 of 3] HTTP/3: "quic" parameter of "listen" directive

Roman Arutyunyan 140 February 07, 2023 08:40AM

[PATCH 2 of 3] HTTP/2: "http2" directive

Roman Arutyunyan 139 February 01, 2023 09:02AM

Re: [PATCH 2 of 3] HTTP/2: "http2" directive

Maxim Dounin 195 February 06, 2023 10:14PM

Re: [PATCH 2 of 3] HTTP/2: "http2" directive

Roman Arutyunyan 170 February 07, 2023 09:06AM

Re: [PATCH 2 of 3] HTTP/2: "http2" directive

Sergey Kandaurov 142 February 07, 2023 05:26AM

Re: [PATCH 2 of 3] HTTP/2: "http2" directive

Roman Arutyunyan 210 February 07, 2023 08:46AM

[PATCH 3 of 3] HTTP/3: trigger more compatibility errors for "listen quic"

Roman Arutyunyan 159 February 01, 2023 09:02AM

[PATCH 0 of 3] Directives for enabling http2 and http3

Roman Arutyunyan 142 February 07, 2023 09:52AM

[PATCH 1 of 3] HTTP/3: "quic" parameter of "listen" directive

Roman Arutyunyan 282 February 07, 2023 09:52AM

[PATCH 2 of 3] HTTP/2: "http2" directive

Roman Arutyunyan 486 February 07, 2023 09:52AM

Re: [PATCH 2 of 3] HTTP/2: "http2" directive

Sergey Kandaurov 148 February 09, 2023 06:30AM

Re: [PATCH 2 of 3] HTTP/2: "http2" directive

Roman Arutyunyan 165 February 09, 2023 07:04AM

Re: [PATCH 2 of 3] HTTP/2: "http2" directive

Roman Arutyunyan 145 February 09, 2023 07:34AM

Re: [PATCH 2 of 3] HTTP/2: "http2" directive

Sergey Kandaurov 167 February 09, 2023 10:58AM

Re: [PATCH 2 of 3] HTTP/2: "http2" directive

Roman Arutyunyan 111 May 16, 2023 08:40AM

Re: [PATCH 2 of 3] HTTP/2: "http2" directive

Sergey Kandaurov 110 May 30, 2023 09:56AM

Re: [PATCH 2 of 3] HTTP/2: "http2" directive

Maxim Dounin 114 June 02, 2023 05:38PM

Re: [PATCH 2 of 3] HTTP/2: "http2" directive

Roman Arutyunyan 95 June 05, 2023 10:20AM

Re: [PATCH 2 of 3] HTTP/2: "http2" directive

Maxim Dounin 112 June 07, 2023 11:52AM

[PATCH 3 of 3] HTTP/3: trigger more compatibility errors for "listen quic"

Roman Arutyunyan 188 February 07, 2023 09:52AM

Re: [PATCH 0 of 3] Directives for enabling http2 and http3

Sergey Kandaurov 153 February 08, 2023 10:24AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 291
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready