aboutsummaryrefslogtreecommitdiff
path: root/src/http/ngx_http_headers.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-10-29 17:39:05 +0000
committerIgor Sysoev <igor@sysoev.ru>2003-10-29 17:39:05 +0000
commit14be46ee9862352fc055da8005e9bdf3dd1bc16e (patch)
tree6c17dac364e25c5b5bacce1188a5bb73d01b9c87 /src/http/ngx_http_headers.c
parentb5faed2dc853ee7e6bda6004b16ceedc6c194641 (diff)
downloadnginx-14be46ee9862352fc055da8005e9bdf3dd1bc16e.tar.gz
nginx-14be46ee9862352fc055da8005e9bdf3dd1bc16e.zip
nginx-0.0.1-2003-10-29-20:39:05 import
Diffstat (limited to 'src/http/ngx_http_headers.c')
-rw-r--r--src/http/ngx_http_headers.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/http/ngx_http_headers.c b/src/http/ngx_http_headers.c
new file mode 100644
index 000000000..3f009149a
--- /dev/null
+++ b/src/http/ngx_http_headers.c
@@ -0,0 +1,100 @@
+
+#include <ngx_config.h>
+#include <ngx_core.h>
+#include <ngx_http.h>
+
+
+ngx_http_header_t ngx_http_headers_in[] = {
+ { ngx_string("Host"), offsetof(ngx_http_headers_in_t, host) },
+ { ngx_string("Connection"), offsetof(ngx_http_headers_in_t, connection) },
+ { ngx_string("If-Modified-Since"),
+ offsetof(ngx_http_headers_in_t, if_modified_since) },
+ { ngx_string("User-Agent"), offsetof(ngx_http_headers_in_t, user_agent) },
+
+ { ngx_string("Content-Length"),
+ offsetof(ngx_http_headers_in_t, content_length) },
+ { ngx_string("Accept-Encoding"),
+ offsetof(ngx_http_headers_in_t, accept_encoding) },
+ { ngx_string("Range"), offsetof(ngx_http_headers_in_t, range) },
+#if 0
+ { ngx_string("If-Range"), offsetof(ngx_http_headers_in_t, if_range) },
+#endif
+
+ { ngx_string("Keep-Alive"), offsetof(ngx_http_headers_in_t, keep_alive) },
+
+ { ngx_null_string, 0 }
+};
+
+
+ngx_http_header_t ngx_http_headers_out[] = {
+ { ngx_string("Server"), offsetof(ngx_http_headers_out_t, server) },
+ { ngx_string("Date"), offsetof(ngx_http_headers_out_t, date) },
+ { ngx_string("Content-Type"),
+ offsetof(ngx_http_headers_out_t, content_type) },
+ { ngx_string("Content-Length"),
+ offsetof(ngx_http_headers_out_t, content_length) },
+ { ngx_string("Content-Encoding"),
+ offsetof(ngx_http_headers_out_t, content_encoding) },
+ { ngx_string("Location"), offsetof(ngx_http_headers_out_t, location) },
+ { ngx_string("Last-Modified"),
+ offsetof(ngx_http_headers_out_t, last_modified) },
+ { ngx_string("Accept-Ranges"),
+ offsetof(ngx_http_headers_out_t, accept_ranges) },
+
+ { ngx_null_string, 0 }
+};
+
+
+ngx_table_elt_t *ngx_http_add_header(void *header,
+ ngx_http_header_t *http_headers)
+{
+ int i, j, nelts;
+ char *prev;
+ ngx_table_t *headers;
+ ngx_table_elt_t *h, *new;
+
+ headers = *(ngx_table_t **) header;
+
+ prev = headers->elts;
+ nelts = headers->nelts;
+
+ if (!(new = ngx_push_table(headers))) {
+ return NULL;
+ }
+
+ if (prev == headers->elts) {
+ return new;
+ }
+
+ /*
+ * When table is relocated we need to update pointers in r->headers_in,
+ * r->headers_out, etc. However this relocation should be very rare
+ * because we preallocate enough space for the number of the real world
+ * HTTP headers.
+ */
+
+ ngx_log_error(NGX_LOG_ALERT, headers->pool->log, 0,
+ "header table is small, %d elements", nelts);
+
+ h = headers->elts;
+ for (i = 0; i < nelts; i++) {
+ if (h[i].key.len == 0) {
+ continue;
+ }
+
+ for (j = 0; http_headers[j].name.len != 0; j++) {
+ if (http_headers[j].name.len != h[i].key.len) {
+ continue;
+ }
+
+ if (ngx_strcasecmp(http_headers[j].name.data, h[i].key.data) == 0) {
+ *((ngx_table_elt_t **)
+ ((char *) header + http_headers[j].offset)) = &h[i];
+ break;
+ }
+ }
+ }
+
+ return new;
+}
+