CCF
Loading...
Searching...
No Matches
http2_utils.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
6#include "ds/nonstd.h"
7
8#include <nghttp2/nghttp2.h>
9#include <optional>
10
11namespace http2
12{
13 // Functions to create HTTP2 headers
14 static nghttp2_nv make_nv(const uint8_t* key, const uint8_t* value)
15 {
16 // Note: Investigate no copy flags here
17 return {
18 const_cast<uint8_t*>(key),
19 const_cast<uint8_t*>(value),
20 strlen(reinterpret_cast<const char*>(key)),
21 strlen(reinterpret_cast<const char*>(value)),
22 NGHTTP2_NV_FLAG_NONE};
23 }
24
25 static inline nghttp2_nv make_nv(const char* key, const char* value)
26 {
27 return make_nv(
28 reinterpret_cast<const uint8_t*>(key),
29 reinterpret_cast<const uint8_t*>(value));
30 }
31
32 static inline AbstractParser* get_parser(void* user_data)
33 {
34 return reinterpret_cast<AbstractParser*>(user_data);
35 }
36
37 static inline std::optional<std::string> make_trailer_header_value(
38 const ccf::http::HeaderMap& trailers)
39 {
40 if (trailers.empty())
41 {
42 return std::nullopt;
43 }
44
45 using HeaderKeysIt =
47
48 auto trailer_header_val = fmt::format(
49 "{}",
50 fmt::join(
51 HeaderKeysIt(trailers.begin()), HeaderKeysIt(trailers.end()), ","));
52
53 return trailer_header_val;
54 }
55
56 static inline StreamData* get_stream_data(
57 nghttp2_session* session, StreamId stream_id)
58 {
59 return reinterpret_cast<StreamData*>(
60 nghttp2_session_get_stream_user_data(session, stream_id));
61 }
62}
Definition nonstd.h:11
std::map< std::string, std::string, std::less<> > HeaderMap
Definition http_header_map.h:10
uint8_t * key
Definition kv_helpers.h:80
Definition http2_callbacks.h:12
int32_t StreamId
Definition http2_types.h:20