Skip to content

Commit

Permalink
* src/ne_request.c (read_status_line): Fail for a non-HTTP/1.x
Browse files Browse the repository at this point in the history
  status-line.
  (ne_begin_request): Simplify, assume HTTP major version is 1.

* test/request.c (fail_on_invalid): Test for non-HTTP/1.x responses.
  • Loading branch information
notroj committed May 21, 2024
1 parent 4ad37ac commit 76e638d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/ne_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,9 +1093,15 @@ static int read_status_line(ne_request *req, ne_status *status, int retry)
status->klass = buffer[4] - '0';
NE_DEBUG(NE_DBG_HTTP, "[status-line] ICY protocol; code %d\n",
status->code);
} else if (ne_parse_statusline(buffer, status)) {
return 0;
}

if (ne_parse_statusline(buffer, status)) {
return aborted(req, _("Could not parse response status line"), 0);
}
if (status->major_version != 1) {
return aborted(req, _("Incompatible HTTP version"), 0);
}

return 0;
}
Expand Down Expand Up @@ -1386,12 +1392,9 @@ int ne_begin_request(ne_request *req)
ne_buffer_destroy(data);
if (ret != NE_OK) return ret == NE_RETRY ? NE_ERROR : ret;

/* Determine whether server claims HTTP/1.1 compliance. */
req->session->is_http11 = (st->major_version == 1 &&
st->minor_version > 0) || st->major_version > 1;

/* Persistent connections supported implicitly in HTTP/1.1 */
if (req->session->is_http11) req->can_persist = 1;
/* HTTP/1.x is assured by read_status_line() not failing.
* Persistent connections supported implicitly in HTTP/1.1. */
req->can_persist = req->session->is_http11 = st->minor_version > 0;

ne_set_error(req->session, "%d %s", st->code, st->reason_phrase);

Expand Down
8 changes: 8 additions & 0 deletions test/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,14 @@ static int fail_on_invalid(void)
"\r\n" "abcde",
"Invalid Content-Length" },

/* incompatible HTTP-version */
{ "HTTP/2.0 200 OK\r\n"
"Content-Length: 0\r\n\r\n",
"Incompatible HTTP version" },
{ "HTTP/0.9 200 OK\r\n"
"Content-Length: 0\r\n\r\n",
"Incompatible HTTP version" },

{ NULL, NULL }
};
unsigned n;
Expand Down

0 comments on commit 76e638d

Please sign in to comment.