-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathresponse.cpp
More file actions
74 lines (64 loc) · 1.83 KB
/
response.cpp
File metadata and controls
74 lines (64 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifdef EMSCRIPTEN
# include "response.hpp"
# include "../utils/common.hpp"
# include "libgit2_internals.hpp"
wasm_http_response::wasm_http_response(char* buffer, size_t buffer_size, size_t* bytes_read)
: m_buffer(buffer)
, m_buffer_size(buffer_size)
, m_bytes_read(bytes_read)
, m_status(0)
{
*m_bytes_read = 0;
}
void wasm_http_response::add_header(const std::string& key, const std::string& value)
{
m_response_headers.emplace(key, trim(value));
}
void wasm_http_response::clear()
{
*m_bytes_read = 0;
m_status = 0;
m_status_text.clear();
m_response_headers.clear();
}
std::optional<std::string> wasm_http_response::get_header(const std::string& key) const
{
// Return the first header with the specified key.
// If we ever have to handle multiple headers with the same key, will need to do something more
// complicated here.
auto header = m_response_headers.find(key);
if (header != m_response_headers.end())
{
return header->second;
}
return std::nullopt;
}
bool wasm_http_response::has_header(const std::string& key) const
{
return m_response_headers.find(key) != m_response_headers.end();
}
bool wasm_http_response::has_header_matches(const std::string& key, std::string_view match) const
{
auto range = m_response_headers.equal_range(key);
for (auto i = range.first; i != range.second; ++i)
{
if (i->second == match)
{
return true;
}
}
return false;
}
bool wasm_http_response::has_header_starts_with(const std::string& key, std::string_view start) const
{
auto range = m_response_headers.equal_range(key);
for (auto i = range.first; i != range.second; ++i)
{
if (i->second.starts_with(start))
{
return true;
}
}
return false;
}
#endif // EMSCRIPTEN