MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / GetHttpHeader

Function GetHttpHeader

tools/websocket_to_posix_proxy/src/main.cpp:41–51  ·  view source on GitHub ↗

Given a multiline string of HTTP headers, returns a pointer to the beginning of the value of given header inside the string that was passed in.

Source from the content-addressed store, hash-verified

39// Given a multiline string of HTTP headers, returns a pointer to the beginning
40// of the value of given header inside the string that was passed in.
41static int GetHttpHeader(const char *headers, const char *header, char *out, int maxBytesOut) { // thread-safe, re-entrant
42 const char *pos = strstr(headers, header);
43 if (!pos) return 0;
44 pos += strlen(header);
45 const char *end = pos;
46 while (*end != '\r' && *end != '\n' && *end != '\0') ++end;
47 int numBytesToWrite = MIN((int)(end-pos), maxBytesOut-1);
48 memcpy(out, pos, numBytesToWrite);
49 out[numBytesToWrite] = '\0';
50 return (int)(end-pos);
51}
52
53// Sends WebSocket handshake back to the given WebSocket connection.
54void SendHandshake(int fd, const char *request) {

Callers 1

SendHandshakeFunction · 0.85

Calls 3

strlenFunction · 0.85
memcpyFunction · 0.85
strstrFunction · 0.50

Tested by

no test coverage detected