• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * nghttp2 - HTTP/2 C Library
3  *
4  * Copyright (c) 2021 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 HTTP3_H
26 #define HTTP3_H
27 
28 #include "nghttp2_config.h"
29 
30 #include <cstring>
31 #include <string>
32 #include <vector>
33 
34 #include <nghttp3/nghttp3.h>
35 
36 #include "http2.h"
37 #include "template.h"
38 
39 namespace nghttp2 {
40 
41 namespace http3 {
42 
43 // Create nghttp3_nv from |name|, |value| and |flags|.
44 inline nghttp3_nv make_field_flags(const StringRef &name,
45                                    const StringRef &value,
46                                    uint8_t flags = NGHTTP3_NV_FLAG_NONE) {
47   auto ns = as_uint8_span(std::span{name});
48   auto vs = as_uint8_span(std::span{value});
49 
50   return {const_cast<uint8_t *>(ns.data()), const_cast<uint8_t *>(vs.data()),
51           ns.size(), vs.size(), flags};
52 }
53 
54 // Creates nghttp3_nv from |name|, |value| and |flags|.  nghttp3
55 // library does not copy them.
56 inline nghttp3_nv make_field(const StringRef &name, const StringRef &value,
57                              uint8_t flags = NGHTTP3_NV_FLAG_NONE) {
58   return make_field_flags(name, value,
59                           static_cast<uint8_t>(NGHTTP3_NV_FLAG_NO_COPY_NAME |
60                                                NGHTTP3_NV_FLAG_NO_COPY_VALUE |
61                                                flags));
62 }
63 
64 // Returns NGHTTP3_NV_FLAG_NEVER_INDEX if |never_index| is true,
65 // otherwise NGHTTP3_NV_FLAG_NONE.
never_index(bool never_index)66 inline uint8_t never_index(bool never_index) {
67   return never_index ? NGHTTP3_NV_FLAG_NEVER_INDEX : NGHTTP3_NV_FLAG_NONE;
68 }
69 
70 // Just like copy_headers_to_nva(), but this adds
71 // NGHTTP3_NV_FLAG_NO_COPY_NAME and NGHTTP3_NV_FLAG_NO_COPY_VALUE.
72 void copy_headers_to_nva_nocopy(std::vector<nghttp3_nv> &nva,
73                                 const HeaderRefs &headers, uint32_t flags);
74 
75 } // namespace http3
76 
77 } // namespace nghttp2
78 
79 #endif // HTTP3_H
80