summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2018-01-15 20:50:14 +0300
committerValentin Bartenev <vbart@nginx.com>2018-01-15 20:50:14 +0300
commita073616fc35b76fce4c4cc1b3ad30837a22d5499 (patch)
tree78b91d5c19a2300ee4fd0a8b1f1cf40649f7071d /src
parent3fb140d6d2f8bf0344e7c311923178db808cb437 (diff)
downloadunit-a073616fc35b76fce4c4cc1b3ad30837a22d5499.tar.gz
unit-a073616fc35b76fce4c4cc1b3ad30837a22d5499.tar.bz2
Improved HTTP version representation.
Diffstat (limited to '')
-rw-r--r--src/nxt_h1proto.c4
-rw-r--r--src/nxt_http_parse.c24
-rw-r--r--src/nxt_http_parse.h7
3 files changed, 19 insertions, 16 deletions
diff --git a/src/nxt_h1proto.c b/src/nxt_h1proto.c
index 5623c019..ac60753d 100644
--- a/src/nxt_h1proto.c
+++ b/src/nxt_h1proto.c
@@ -254,7 +254,7 @@ nxt_h1p_header_parse(nxt_task_t *task, void *obj, void *data)
* enabled in HTTP/1.1. The mode can be overridden later by
* the "Connection" field processed in nxt_h1p_connection().
*/
- h1p->keepalive = (h1p->parser.version.str[7] != '0');
+ h1p->keepalive = (h1p->parser.version.s.minor != '0');
r->fields = h1p->parser.fields;
@@ -658,7 +658,7 @@ nxt_h1p_request_header_send(nxt_task_t *task, nxt_http_request_t *r)
/* Trailing CRLF at the end of header. */
size += sizeof("\r\n") - 1;
- http11 = (h1p->parser.version.str[7] != '0');
+ http11 = (h1p->parser.version.s.minor != '0');
if (r->resp.content_length == NULL || r->resp.content_length->skip) {
if (http11) {
diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c
index 0a63ab1a..ef9fee45 100644
--- a/src/nxt_http_parse.c
+++ b/src/nxt_http_parse.c
@@ -169,7 +169,7 @@ nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos,
{
u_char *p, ch, *after_slash;
nxt_int_t rc;
- nxt_http_ver_t version;
+ nxt_http_ver_t ver;
nxt_http_target_traps_e trap;
static const nxt_http_ver_t http11 = { "HTTP/1.1" };
@@ -383,21 +383,17 @@ space_after_target:
/* " HTTP/1.1\r\n" or " HTTP/1.1\n" */
- nxt_memcpy(version.str, &p[1], 8);
-
- if (nxt_fast_path((version.ui64 == http11.ui64
- || version.ui64 == http10.ui64
- || (p[1] == 'H'
- && p[2] == 'T'
- && p[3] == 'T'
- && p[4] == 'P'
- && p[5] == '/'
- && p[6] >= '0' && p[6] <= '9'
- && p[7] == '.'
- && p[8] >= '0' && p[8] <= '9'))
+ nxt_memcpy(ver.str, &p[1], 8);
+
+ if (nxt_fast_path((ver.ui64 == http11.ui64
+ || ver.ui64 == http10.ui64
+ || (nxt_memcmp(ver.s.prefix, "HTTP/", 5) == 0
+ && ver.s.major >= '0' && ver.s.major <= '9'
+ && ver.s.point == '.'
+ && ver.s.minor >= '0' && ver.s.minor <= '9'))
&& (p[9] == '\r' || p[9] == '\n')))
{
- rp->version.ui64 = version.ui64;
+ rp->version.ui64 = ver.ui64;
if (nxt_fast_path(p[9] == '\r')) {
p += 10;
diff --git a/src/nxt_http_parse.h b/src/nxt_http_parse.h
index 0a0ca340..51c6809a 100644
--- a/src/nxt_http_parse.h
+++ b/src/nxt_http_parse.h
@@ -22,6 +22,13 @@ typedef struct nxt_http_fields_hash_s nxt_http_fields_hash_t;
typedef union {
u_char str[8];
uint64_t ui64;
+
+ struct {
+ u_char prefix[5];
+ u_char major;
+ u_char point;
+ u_char minor;
+ } s;
} nxt_http_ver_t;