| 248 | } |
| 249 | |
| 250 | static const char* FindHeader(Worker* worker, const char* header, char* buffer, uint32_t buffer_length) |
| 251 | { |
| 252 | // Headers are either 0, of a list of strings "header1: value\nheader2: value\n" |
| 253 | const char* current = (const char*)worker->m_Request->m_Headers; |
| 254 | const char* headers_end = current + worker->m_Request->m_HeadersLength; |
| 255 | uint32_t header_length = strlen(header); |
| 256 | while (current < headers_end) |
| 257 | { |
| 258 | const char* end = (const char*) memchr(current, '\n', headers_end - current); |
| 259 | if (!end) |
| 260 | { |
| 261 | end = headers_end; |
| 262 | } |
| 263 | uint32_t length = end - current; |
| 264 | if (length >= header_length && memcmp(current, header, header_length) == 0) |
| 265 | { |
| 266 | if (length < buffer_length) |
| 267 | { |
| 268 | memcpy(buffer, current, length); |
| 269 | buffer[length] = 0; |
| 270 | return buffer; |
| 271 | } |
| 272 | } |
| 273 | current = end + (end < headers_end ? 1 : 0); |
| 274 | } |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | void HandleRequest(Worker* worker, const dmMessage::URL* requester, uintptr_t userdata1, uintptr_t userdata2, dmHttpDDF::HttpRequest* request) |
| 279 | { |