summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_http_response.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2017-12-28 16:01:06 +0300
committerIgor Sysoev <igor@sysoev.ru>2017-12-28 16:01:06 +0300
commit9a6d3c5775d945509c7c2cbec48be59757da42c3 (patch)
tree7129c13d6027a45e1a324deab373125bd7a14794 /src/nxt_http_response.c
parent497faf1b9abb188cab40c389a9e6221add5dd496 (diff)
downloadunit-9a6d3c5775d945509c7c2cbec48be59757da42c3.tar.gz
unit-9a6d3c5775d945509c7c2cbec48be59757da42c3.tar.bz2
HTTP keep-alive connections support.
Diffstat (limited to 'src/nxt_http_response.c')
-rw-r--r--src/nxt_http_response.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/nxt_http_response.c b/src/nxt_http_response.c
new file mode 100644
index 00000000..330890c1
--- /dev/null
+++ b/src/nxt_http_response.c
@@ -0,0 +1,83 @@
+
+/*
+ * Copyright (C) Igor Sysoev
+ * Copyright (C) NGINX, Inc.
+ */
+
+#include <nxt_router.h>
+#include <nxt_http.h>
+
+
+static nxt_int_t nxt_http_response_status(void *ctx, nxt_http_field_t *field,
+ uintptr_t data);
+static nxt_int_t nxt_http_response_skip(void *ctx, nxt_http_field_t *field,
+ uintptr_t data);
+static nxt_int_t nxt_http_response_field(void *ctx, nxt_http_field_t *field,
+ uintptr_t offset);
+
+
+nxt_lvlhsh_t nxt_response_fields_hash;
+
+static nxt_http_field_proc_t nxt_response_fields[] = {
+ { nxt_string("Status"), &nxt_http_response_status, 0 },
+ { nxt_string("Server"), &nxt_http_response_skip, 0 },
+ { nxt_string("Connection"), &nxt_http_response_skip, 0 },
+ { nxt_string("Content-Type"), &nxt_http_response_field,
+ offsetof(nxt_http_request_t, resp.content_type) },
+ { nxt_string("Content-Length"), &nxt_http_response_field,
+ offsetof(nxt_http_request_t, resp.content_length) },
+};
+
+
+nxt_int_t
+nxt_http_response_hash_init(nxt_task_t *task, nxt_runtime_t *rt)
+{
+ return nxt_http_fields_hash(&nxt_response_fields_hash, rt->mem_pool,
+ nxt_response_fields, nxt_nitems(nxt_response_fields));
+}
+
+
+nxt_int_t
+nxt_http_response_status(void *ctx, nxt_http_field_t *field,
+ uintptr_t data)
+{
+ nxt_int_t status;
+ nxt_http_request_t *r;
+
+ r = ctx;
+
+ field->skip = 1;
+
+ if (field->value_length >= 3) {
+ status = nxt_int_parse(field->value, 3);
+
+ if (status >= 100 && status <= 999) {
+ r->status = status;
+ return NXT_OK;
+ }
+ }
+
+ return NXT_ERROR;
+}
+
+
+nxt_int_t
+nxt_http_response_skip(void *ctx, nxt_http_field_t *field, uintptr_t data)
+{
+ field->skip = 1;
+
+ return NXT_OK;
+}
+
+
+nxt_int_t
+nxt_http_response_field(void *ctx, nxt_http_field_t *field, uintptr_t offset)
+{
+ nxt_http_request_t *r;
+
+ r = ctx;
+
+ nxt_value_at(nxt_http_field_t *, r, offset) = field;
+
+ return NXT_OK;
+}