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

Function get_http_hdr

connectd/websocketd.c:90–122  ·  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

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

Callers 1

http_respondFunction · 0.85

Calls 3

memmemFunction · 0.85
memstartsFunction · 0.85
cisspaceFunction · 0.85

Tested by

no test coverage detected