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((char*)key),
21 strlen((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((uint8_t*)key, (uint8_t*)value);
28 }
29
30 static inline AbstractParser* get_parser(void* user_data)
31 {
32 return reinterpret_cast<AbstractParser*>(user_data);
33 }
34
35 static inline std::optional<std::string> make_trailer_header_value(
36 const ccf::http::HeaderMap& trailers)
37 {
38 if (trailers.empty())
39 {
40 return std::nullopt;
41 }
42
43 using HeaderKeysIt =
45
46 const auto trailer_header_val = fmt::format(
47 "{}",
48 fmt::join(
49 HeaderKeysIt(trailers.begin()), HeaderKeysIt(trailers.end()), ","));
50
51 return trailer_header_val;
52 }
53
54 static inline StreamData* get_stream_data(
55 nghttp2_session* session, StreamId stream_id)
56 {
57 return reinterpret_cast<StreamData*>(
58 nghttp2_session_get_stream_user_data(session, stream_id));
59 }
60}
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:78
Definition http2_callbacks.h:12
int32_t StreamId
Definition http2_types.h:21