Parses a HTTP header */
| 166 | |
| 167 | /* Parses a HTTP header */ |
| 168 | static 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. */ |
| 197 | static void Http_AddHeader(struct HttpRequest* req, const char* key, const cc_string* value); |
no test coverage detected