We know headers are terminated by \r\n\r\n at this point */
| 93 | |
| 94 | /* We know headers are terminated by \r\n\r\n at this point */ |
| 95 | static const char *get_http_hdr(const tal_t *ctx, const u8 *buf, size_t buflen, |
| 96 | const char *hdrname) |
| 97 | { |
| 98 | size_t hdrlen; |
| 99 | |
| 100 | for (;;) { |
| 101 | const u8 *end = memmem(buf, buflen, "\r\n", 2); |
| 102 | hdrlen = end - buf; |
| 103 | |
| 104 | /* Empty line? End of headers. */ |
| 105 | if (hdrlen == 0) |
| 106 | return NULL; |
| 107 | /* header name followed by : */ |
| 108 | if (memstarts(buf, hdrlen, hdrname, strlen(hdrname)) |
| 109 | && buf[strlen(hdrname)] == ':') |
| 110 | break; |
| 111 | buf = end + 2; |
| 112 | } |
| 113 | |
| 114 | buf += strlen(hdrname) + 1; |
| 115 | hdrlen -= strlen(hdrname) + 1; |
| 116 | |
| 117 | /* Ignore leading whitespace (technically, they can split |
| 118 | * fields over multiple lines, but that's silly for the fields |
| 119 | * we're dealing with, so Naah). */ |
| 120 | while (hdrlen && cisspace(*buf)) { |
| 121 | buf++; |
| 122 | hdrlen--; |
| 123 | } |
| 124 | |
| 125 | return tal_strndup(ctx, (const char *)buf, hdrlen); |
| 126 | } |
| 127 | |
| 128 | static bool http_headers_complete(const u8 *buf, size_t len) |
| 129 | { |
no test coverage detected