MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / Http_ParseHeader

Function Http_ParseHeader

src/_HttpBase.h:168–194  ·  view source on GitHub ↗

Parses a HTTP header */

Source from the content-addressed store, hash-verified

166
167/* Parses a HTTP header */
168static void Http_ParseHeader(struct HttpRequest* req, const cc_string* line) {
169 static const cc_string httpVersion = String_FromConst("HTTP");
170 cc_string name, value, parts[3];
171 int numParts;
172
173 /* HTTP[version] [status code] [status reason] */
174 if (String_CaselessStarts(line, &httpVersion)) {
175 numParts = String_UNSAFE_Split(line, ' ', parts, 3);
176 if (numParts >= 2) Convert_ParseInt(&parts[1], &req->statusCode);
177 }
178 /* For all other headers: name: value */
179 if (!String_UNSAFE_Separate(line, ':', &name, &value)) return;
180
181 if (String_CaselessEqualsConst(&name, "ETag")) {
182 String_CopyToRawArray(req->etag, &value);
183 } else if (String_CaselessEqualsConst(&name, "Content-Length")) {
184 Http_ParseContentLength(req, &value);
185 } else if (String_CaselessEqualsConst(&name, "X-Dropbox-Content-Length")) {
186 /* dropbox stopped returning Content-Length header since switching to chunked transfer */
187 /* https://www.dropboxforum.com/t5/Discuss-Dropbox-Developer-API/Dropbox-media-can-t-be-access-by-azure-blob/td-p/575458 */
188 Http_ParseContentLength(req, &value);
189 } else if (String_CaselessEqualsConst(&name, "Last-Modified")) {
190 String_CopyToRawArray(req->lastModified, &value);
191 } else if (req->cookies && String_CaselessEqualsConst(&name, "Set-Cookie")) {
192 Http_ParseCookie(req, &value);
193 }
194}
195
196/* Adds a http header to the request headers. */
197static void Http_AddHeader(struct HttpRequest* req, const char* key, const cc_string* value);

Callers 1

HttpClient_ProcessFunction · 0.85

Calls 7

String_CaselessStartsFunction · 0.85
String_UNSAFE_SplitFunction · 0.85
Convert_ParseIntFunction · 0.85
String_UNSAFE_SeparateFunction · 0.85
Http_ParseContentLengthFunction · 0.85
Http_ParseCookieFunction · 0.85

Tested by

no test coverage detected