} while (p != end);
+ h2c->total_bytes += n;
+
+ if (h2c->total_bytes / 8 > h2c->payload_bytes + 1048576) {
+ ngx_log_error(NGX_LOG_INFO, c->log, 0, "http2 flood detected");
+ ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_NO_ERROR);
+ return;
+ }
+
} while (rev->ready);
if (ngx_handle_read_event(rev, 0) != NGX_OK) {
stream->in_closed = h2c->state.flags & NGX_HTTP_V2_END_STREAM_FLAG;
}
+ h2c->payload_bytes += size;
+
if (r->request_body) {
rc = ngx_http_v2_process_request_body(r, pos, size, stream->in_closed);
"requested control frame is too large: %uz", length);
return NULL;
}
+#endif
frame->length = length;
-#endif
buf->last = ngx_http_v2_write_len_and_type(buf->pos, length, type);
frame->next = h2c->free_frames;
h2c->free_frames = frame;
+ h2c->total_bytes += NGX_HTTP_V2_FRAME_HEADER_SIZE + frame->length;
+
return NGX_OK;
}
static void
ngx_http_v2_run_request(ngx_http_request_t *r)
{
- ngx_connection_t *fc;
+ ngx_connection_t *fc;
+ ngx_http_v2_connection_t *h2c;
fc = r->connection;
r->headers_in.chunked = 1;
}
+ h2c = r->stream->connection;
+
+ h2c->payload_bytes += r->request_length;
+
ngx_http_process_request(r);
failed:
stream->request->header_size += NGX_HTTP_V2_FRAME_HEADER_SIZE
+ frame->length;
+ h2c->payload_bytes += frame->length;
+
ngx_http_v2_handle_frame(stream, frame);
ngx_http_v2_handle_stream(h2c, stream);
stream->request->header_size += NGX_HTTP_V2_FRAME_HEADER_SIZE
+ frame->length;
+ h2c->payload_bytes += frame->length;
+
ngx_http_v2_handle_frame(stream, frame);
ngx_http_v2_handle_stream(h2c, stream);
stream->request->header_size += NGX_HTTP_V2_FRAME_HEADER_SIZE;
+ h2c->payload_bytes += frame->length;
+
ngx_http_v2_handle_frame(stream, frame);
ngx_http_v2_handle_stream(h2c, stream);
ngx_http_v2_handle_frame(ngx_http_v2_stream_t *stream,
ngx_http_v2_out_frame_t *frame)
{
- ngx_http_request_t *r;
+ ngx_http_request_t *r;
+ ngx_http_v2_connection_t *h2c;
r = stream->request;
r->connection->sent += NGX_HTTP_V2_FRAME_HEADER_SIZE + frame->length;
+ h2c = stream->connection;
+
+ h2c->total_bytes += NGX_HTTP_V2_FRAME_HEADER_SIZE + frame->length;
+
if (frame->fin) {
stream->out_closed = 1;
}