HTTP/3: introduced ngx_http_v3_filter.

The filter is responsible for creating HTTP/3 response header and body.

The change removes differences to the default branch for
ngx_http_chunked_filter_module and ngx_http_header_filter_module.
This commit is contained in:
Roman Arutyunyan 2020-11-27 17:46:21 +00:00
parent 8402a8068a
commit dc5ab4196f
6 changed files with 1382 additions and 1204 deletions

View file

@ -119,6 +119,7 @@ if [ $HTTP = YES ]; then
# ngx_http_header_filter
# ngx_http_chunked_filter
# ngx_http_v2_filter
# ngx_http_v3_filter
# ngx_http_range_header_filter
# ngx_http_gzip_filter
# ngx_http_postpone_filter
@ -151,6 +152,7 @@ if [ $HTTP = YES ]; then
ngx_http_header_filter_module \
ngx_http_chunked_filter_module \
ngx_http_v2_filter_module \
ngx_http_v3_filter_module \
ngx_http_range_header_filter_module \
ngx_http_gzip_filter_module \
ngx_http_postpone_filter_module \
@ -212,6 +214,17 @@ if [ $HTTP = YES ]; then
. auto/module
fi
if [ $HTTP_V3 = YES ]; then
ngx_module_name=ngx_http_v3_filter_module
ngx_module_incs=
ngx_module_deps=
ngx_module_srcs=src/http/v3/ngx_http_v3_filter_module.c
ngx_module_libs=
ngx_module_link=$HTTP_V3
. auto/module
fi
if :; then
ngx_module_name=ngx_http_range_header_filter_module
ngx_module_incs=

View file

@ -106,7 +106,6 @@ ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
{
u_char *chunk;
off_t size;
size_t n;
ngx_int_t rc;
ngx_buf_t *b;
ngx_chain_t *out, *cl, *tl, **ll;
@ -162,68 +161,27 @@ ngx_http_chunked_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
chunk = b->start;
if (chunk == NULL) {
/* the "0000000000000000" is 64-bit hexadecimal string */
#if (NGX_HTTP_V3)
if (r->http_version == NGX_HTTP_VERSION_30) {
n = NGX_HTTP_V3_VARLEN_INT_LEN * 2;
} else
#endif
{
/* the "0000000000000000" is 64-bit hexadecimal string */
n = sizeof("0000000000000000" CRLF) - 1;
}
chunk = ngx_palloc(r->pool, n);
chunk = ngx_palloc(r->pool, sizeof("0000000000000000" CRLF) - 1);
if (chunk == NULL) {
return NGX_ERROR;
}
b->start = chunk;
b->end = chunk + n;
b->end = chunk + sizeof("0000000000000000" CRLF) - 1;
}
b->tag = (ngx_buf_tag_t) &ngx_http_chunked_filter_module;
b->memory = 0;
b->temporary = 1;
b->pos = chunk;
#if (NGX_HTTP_V3)
if (r->http_version == NGX_HTTP_VERSION_30) {
b->last = (u_char *) ngx_http_v3_encode_varlen_int(chunk,
NGX_HTTP_V3_FRAME_DATA);
b->last = (u_char *) ngx_http_v3_encode_varlen_int(b->last, size);
} else
#endif
{
b->last = ngx_sprintf(chunk, "%xO" CRLF, size);
}
b->last = ngx_sprintf(chunk, "%xO" CRLF, size);
tl->next = out;
out = tl;
}
#if (NGX_HTTP_V3)
if (r->http_version == NGX_HTTP_VERSION_30) {
if (cl->buf->last_buf) {
tl = ngx_http_v3_create_trailers(r);
if (tl == NULL) {
return NGX_ERROR;
}
cl->buf->last_buf = 0;
*ll = tl;
} else {
*ll = NULL;
}
} else
#endif
if (cl->buf->last_buf) {
tl = ngx_http_chunked_create_trailers(r, ctx);
if (tl == NULL) {

View file

@ -187,29 +187,6 @@ ngx_http_header_filter(ngx_http_request_t *r)
r->header_only = 1;
}
if (r->headers_out.status_line.len == 0) {
if (r->headers_out.status == NGX_HTTP_NO_CONTENT
|| r->headers_out.status == NGX_HTTP_NOT_MODIFIED)
{
r->header_only = 1;
}
}
#if (NGX_HTTP_V3)
if (r->http_version == NGX_HTTP_VERSION_30) {
ngx_chain_t *cl;
cl = ngx_http_v3_create_header(r);
if (cl == NULL) {
return NGX_ERROR;
}
return ngx_http_write_filter(r, cl);
}
#endif
if (r->headers_out.last_modified_time != -1) {
if (r->headers_out.status != NGX_HTTP_OK
&& r->headers_out.status != NGX_HTTP_PARTIAL_CONTENT
@ -243,6 +220,7 @@ ngx_http_header_filter(ngx_http_request_t *r)
/* 2XX */
if (status == NGX_HTTP_NO_CONTENT) {
r->header_only = 1;
ngx_str_null(&r->headers_out.content_type);
r->headers_out.last_modified_time = -1;
r->headers_out.last_modified = NULL;
@ -259,6 +237,10 @@ ngx_http_header_filter(ngx_http_request_t *r)
{
/* 3XX */
if (status == NGX_HTTP_NOT_MODIFIED) {
r->header_only = 1;
}
status = status - NGX_HTTP_MOVED_PERMANENTLY + NGX_HTTP_OFF_3XX;
status_line = &ngx_http_status_lines[status];
len += ngx_http_status_lines[status].len;

View file

@ -140,8 +140,6 @@ ngx_int_t ngx_http_v3_parse_header(ngx_http_request_t *r, ngx_buf_t *b,
ngx_uint_t allow_underscores);
ngx_int_t ngx_http_v3_parse_request_body(ngx_http_request_t *r, ngx_buf_t *b,
ngx_http_chunked_t *ctx);
ngx_chain_t *ngx_http_v3_create_header(ngx_http_request_t *r);
ngx_chain_t *ngx_http_v3_create_trailers(ngx_http_request_t *r);
uintptr_t ngx_http_v3_encode_varlen_int(u_char *p, uint64_t value);
uintptr_t ngx_http_v3_encode_prefix_int(u_char *p, uint64_t value,

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff