Skip to content

Commit

Permalink
fix 1.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
cirospaciari committed Jul 12, 2023
1 parent 5444cb9 commit f33291d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/HttpParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ struct HttpParser {
}

/* Puts method as key, target as value and returns non-null (or nullptr on error). */
static inline char *consumeRequestLine(char *data, HttpRequest::Header &header) {
static inline char *consumeRequestLine(char *data, HttpRequest::Header &header, bool *ancientHttp) {
/* Scan until single SP, assume next is / (origin request) */
char *start = data;
/* This catches the post padded CR and fails */
Expand All @@ -258,9 +258,11 @@ struct HttpParser {
header.value = {start, (size_t) (data - start)};
/* Check that the following is http 1.1 */
if (memcmp(" HTTP/1.1\r\n", data, 11) == 0) {
*ancientHttp = false;
return data + 11;
}
if (memcmp(" HTTP/1.0\r\n", data, 11) == 0) {
*ancientHttp = true;
return data + 11;
}
return nullptr;
Expand All @@ -286,7 +288,7 @@ struct HttpParser {
}

/* End is only used for the proxy parser. The HTTP parser recognizes "\ra" as invalid "\r\n" scan and breaks. */
static unsigned int getHeaders(char *postPaddedBuffer, char *end, struct HttpRequest::Header *headers, void *reserved, unsigned int &err) {
static unsigned int getHeaders(char *postPaddedBuffer, char *end, struct HttpRequest::Header *headers, void *reserved, unsigned int &err, bool *ancientHttp) {
char *preliminaryKey, *preliminaryValue, *start = postPaddedBuffer;

#ifdef UWS_WITH_PROXY
Expand Down Expand Up @@ -316,7 +318,7 @@ struct HttpParser {
* which is then removed, and our counters to flip due to overflow and we end up with a crash */

/* The request line is different from the field names / field values */
if (!(postPaddedBuffer = consumeRequestLine(postPaddedBuffer, headers[0]))) {
if (!(postPaddedBuffer = consumeRequestLine(postPaddedBuffer, headers[0], ancientHttp))) {
/* Error - invalid request line */
/* Assuming it is 505 HTTP Version Not Supported */
err = HTTP_ERROR_505_HTTP_VERSION_NOT_SUPPORTED;
Expand Down Expand Up @@ -408,14 +410,14 @@ struct HttpParser {
data[length] = '\r';
data[length + 1] = 'a'; /* Anything that is not \n, to trigger "invalid request" */

for (unsigned int consumed; length && (consumed = getHeaders(data, data + length, req->headers, reserved, err)); ) {
/* Store HTTP version (ancient 1.0 or 1.1) */
req->ancientHttp = false;

for (unsigned int consumed; length && (consumed = getHeaders(data, data + length, req->headers, reserved, err, &req->ancientHttp)); ) {
data += consumed;
length -= consumed;
consumedTotal += consumed;

/* Store HTTP version (ancient 1.0 or 1.1) */
req->ancientHttp = false;

/* Add all headers to bloom filter */
req->bf.reset();
for (HttpRequest::Header *h = req->headers; (++h)->key.length(); ) {
Expand Down

0 comments on commit f33291d

Please sign in to comment.