MCPcopy Create free account
hub / github.com/SmingHub/Sming / testHttpHeaders

Method testHttpHeaders

tests/HostTests/modules/Network/Http.cpp:123–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121 }
122
123 void testHttpHeaders()
124 {
125 HttpHeaders headers;
126
127 DEFINE_FSTR_LOCAL(FS_X_Auth_Header, "X-Auth-Header");
128 DEFINE_FSTR_LOCAL(FS_x_auth_header, "x-auth-header");
129 DEFINE_FSTR_LOCAL(FS_X_AUTH_HEADER, "X-AUTH-HEADER");
130 DEFINE_FSTR_LOCAL(FS_valueData, "Value Data");
131 DEFINE_FSTR_LOCAL(FS_valueDataNew, "Value Data New");
132
133 headers[FS_X_Auth_Header] = FS_valueData;
134 headers[FS_x_auth_header] = FS_valueDataNew;
135 REQUIRE(headers.count() == 1);
136 REQUIRE(headers[FS_X_AUTH_HEADER] == FS_valueDataNew);
137 printHeaders(headers);
138
139 headers.remove(FS_x_auth_header);
140 REQUIRE(headers.count() == 0);
141 printHeaders(headers);
142
143 DEFINE_FSTR_LOCAL(FS_corsTest, "This is access control origin");
144 DEFINE_FSTR_LOCAL(FS_acao, "access-control-Allow-Origin");
145 headers[HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN] = FS_corsTest;
146 REQUIRE(headers[FS_acao] == FS_corsTest);
147 REQUIRE(headers.count() == 1);
148
149 headers.clear();
150 REQUIRE(headers.count() == 0);
151
152 TEST_CASE("Non-existent (const)")
153 {
154 const HttpHeaders& constHeaders = headers;
155 String hdr = constHeaders["Non-Existent"];
156 REQUIRE(headers.count() == 0);
157 REQUIRE(!hdr);
158 REQUIRE(hdr.length() == 0);
159 printHeaders(headers);
160 }
161
162 TEST_CASE("Non-existent (non-const)")
163 {
164 String hdr = headers["Non-Existent"];
165 REQUIRE(headers.count() == 1);
166 REQUIRE(!hdr);
167 REQUIRE(hdr.length() == 0);
168 printHeaders(headers);
169 }
170
171 DEFINE_FSTR_LOCAL(FS_serialized, "Non-Existent: \r\n"
172 "Mary: Had a little lamb\r\n"
173 "Content-Length: 12345\r\n"
174 "George: Was an idiot\r\n");
175
176 auto serialize = [](HttpHeaders& h) {
177 String s;
178 for(unsigned i = 0; i < h.count(); ++i) {
179 s += h[i];
180 }

Callers

nothing calls this directly

Calls 7

serializeFunction · 0.85
countMethod · 0.45
removeMethod · 0.45
clearMethod · 0.45
lengthMethod · 0.45
setMultipleMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected