2 * nghttp2 - HTTP/2 C Library
4 * Copyright (c) 2012 Tatsuhiro Tsujikawa
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "shrpx_http.h"
27 #include "shrpx_config.h"
28 #include "shrpx_log.h"
32 using namespace nghttp2;
38 std::string create_error_html(unsigned int status_code) {
41 auto status = http2::get_status_string(status_code);
42 res += R"(<!DOCTYPE html><html lang="en"><title>)";
44 res += "</title><body><h1>";
46 res += "</h1><footer>";
47 res += get_config()->server_name;
49 res += util::utos(get_config()->port);
50 res += "</footer></body></html>";
54 std::string create_via_header_value(int major, int minor) {
56 hdrs += static_cast<char>(major + '0');
59 hdrs += static_cast<char>(minor + '0');
65 std::string colorizeHeaders(const char *hdrs) {
67 const char *p = strchr(hdrs, '\n');
69 // Not valid HTTP header
72 nhdrs.append(hdrs, p + 1);
75 const char *np = strchr(p, ':');
89 nhdrs.append(p, np + 1);
95 ssize_t select_padding_callback(nghttp2_session *session,
96 const nghttp2_frame *frame, size_t max_payload,
98 return std::min(max_payload, frame->hd.length + get_config()->padding);