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.
| 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. |
| 41 | static 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. |
| 54 | void SendHandshake(int fd, const char *request) { |
no test coverage detected