MCPcopy Create free account
hub / github.com/ElementsProject/lightning / get_http_hdr

Function get_http_hdr

connectd/websocketd.c:95–126  ·  view source on GitHub ↗

We know headers are terminated by \r\n\r\n at this point */

Source from the content-addressed store, hash-verified

93
94/* We know headers are terminated by \r\n\r\n at this point */
95static 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
128static bool http_headers_complete(const u8 *buf, size_t len)
129{

Callers 1

http_respondFunction · 0.85

Calls 3

memmemFunction · 0.85
memstartsFunction · 0.85
cisspaceFunction · 0.85

Tested by

no test coverage detected