CCF
Loading...
Searching...
No Matches
http_configuration.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include "ccf/ds/json.h"
7
8#include <optional>
9
10namespace ccf::http
11{
12 // Default parser limits, used as a DoS protection against
13 // requests that are too large.
14 static const ccf::ds::SizeString default_max_body_size = {"1MB"};
15 static const ccf::ds::SizeString default_max_header_size = {"16KB"};
16 static const uint32_t default_max_headers_count = 256;
17
18 // HTTP/2 only, as per nghttp2 defaults
19 static const size_t default_max_concurrent_streams_count = 100;
20 static const ccf::ds::SizeString default_initial_window_size = {"64KB"};
21 static const ccf::ds::SizeString default_max_frame_size = {"16KB"};
22
24 {
25 std::optional<ccf::ds::SizeString> max_body_size = std::nullopt;
26 std::optional<ccf::ds::SizeString> max_header_size = std::nullopt;
27 std::optional<uint32_t> max_headers_count = std::nullopt;
28
29 // HTTP/2 only
30 std::optional<size_t> max_concurrent_streams_count = std::nullopt;
31 std::optional<ccf::ds::SizeString> initial_window_size = std::nullopt;
32 // Must be between 16KB and 16MB
33 // https://www.rfc-editor.org/rfc/rfc7540#section-4.2
34 std::optional<ccf::ds::SizeString> max_frame_size = std::nullopt;
35
36 bool operator==(const ParserConfiguration& other) const = default;
37 };
42 max_body_size,
43 max_header_size,
44 max_headers_count,
45 max_concurrent_streams_count,
46 initial_window_size,
47 max_frame_size);
48
49 // A permissive configuration, used for internally forwarded requests
50 // that have already been through application-defined limits.
51 static ParserConfiguration permissive_configuration()
52 {
54 config.max_body_size = "1GB";
55 config.max_header_size = "100MB";
56 config.max_headers_count = 1024;
58 config.initial_window_size = "64KB";
59 config.max_frame_size = "16MB";
60 return config;
61 }
62}
#define DECLARE_JSON_REQUIRED_FIELDS(TYPE,...)
Definition json.h:714
#define DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(TYPE)
Definition json.h:690
#define DECLARE_JSON_OPTIONAL_FIELDS(TYPE,...)
Definition json.h:786
Definition http_accept.h:13
Definition unit_strings.h:122
Definition http_configuration.h:24
std::optional< ccf::ds::SizeString > max_header_size
Definition http_configuration.h:26
std::optional< size_t > max_concurrent_streams_count
Definition http_configuration.h:30
std::optional< ccf::ds::SizeString > max_body_size
Definition http_configuration.h:25
std::optional< ccf::ds::SizeString > initial_window_size
Definition http_configuration.h:31
std::optional< uint32_t > max_headers_count
Definition http_configuration.h:27
bool operator==(const ParserConfiguration &other) const =default
std::optional< ccf::ds::SizeString > max_frame_size
Definition http_configuration.h:34