Apply PIE to nghttpx
[platform/upstream/nghttp2.git] / src / shrpx_http.h
1 /*
2  * nghttp2 - HTTP/2 C Library
3  *
4  * Copyright (c) 2012 Tatsuhiro Tsujikawa
5  *
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:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
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.
24  */
25 #ifndef SHRPX_HTTP_H
26 #define SHRPX_HTTP_H
27
28 #include "shrpx.h"
29
30 #include <string>
31
32 #include <nghttp2/nghttp2.h>
33
34 #include "shrpx_config.h"
35 #include "util.h"
36 #include "allocator.h"
37
38 using namespace nghttp2;
39
40 namespace shrpx {
41
42 namespace http {
43
44 StringRef create_error_html(BlockAllocator &balloc, unsigned int status_code);
45
46 template <typename OutputIt>
47 OutputIt create_via_header_value(OutputIt dst, int major, int minor) {
48   *dst++ = static_cast<char>(major + '0');
49   if (major < 2) {
50     *dst++ = '.';
51     *dst++ = static_cast<char>(minor + '0');
52   }
53   return util::copy_lit(dst, " nghttpx");
54 }
55
56 // Returns generated RFC 7239 Forwarded header field value.  The
57 // |params| is bitwise-OR of zero or more of shrpx_forwarded_param
58 // defined in shrpx_config.h.
59 StringRef create_forwarded(BlockAllocator &balloc, int params,
60                            const StringRef &node_by, const StringRef &node_for,
61                            const StringRef &host, const StringRef &proto);
62
63 // Adds ANSI color codes to HTTP headers |hdrs|.
64 std::string colorizeHeaders(const char *hdrs);
65
66 ssize_t select_padding_callback(nghttp2_session *session,
67                                 const nghttp2_frame *frame, size_t max_payload,
68                                 void *user_data);
69
70 // Creates set-cookie-string for cookie based affinity.  If |path| is
71 // not empty, "; <path>" is added.  If |secure| is true, "; Secure" is
72 // added.
73 StringRef create_affinity_cookie(BlockAllocator &balloc, const StringRef &name,
74                                  uint32_t affinity_cookie,
75                                  const StringRef &path, bool secure);
76
77 // Returns true if |secure| indicates that Secure attribute should be
78 // set.
79 bool require_cookie_secure_attribute(SessionAffinityCookieSecure secure,
80                                      const StringRef &scheme);
81
82 } // namespace http
83
84 } // namespace shrpx
85
86 #endif // SHRPX_HTTP_H