comparison src/http/ngx_http_request.c @ 9021:8d0753760546 quic

Merged with the default branch.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 22 Jun 2022 18:34:58 +0400
parents aa3c59524e2f c263f9ffa1fd
children 7b83da3bdf9f
comparison
equal deleted inserted replaced
9020:efbcdb9b37dc 9021:8d0753760546
20 20
21 static ngx_int_t ngx_http_process_header_line(ngx_http_request_t *r, 21 static ngx_int_t ngx_http_process_header_line(ngx_http_request_t *r,
22 ngx_table_elt_t *h, ngx_uint_t offset); 22 ngx_table_elt_t *h, ngx_uint_t offset);
23 static ngx_int_t ngx_http_process_unique_header_line(ngx_http_request_t *r, 23 static ngx_int_t ngx_http_process_unique_header_line(ngx_http_request_t *r,
24 ngx_table_elt_t *h, ngx_uint_t offset); 24 ngx_table_elt_t *h, ngx_uint_t offset);
25 static ngx_int_t ngx_http_process_multi_header_lines(ngx_http_request_t *r,
26 ngx_table_elt_t *h, ngx_uint_t offset);
27 static ngx_int_t ngx_http_process_host(ngx_http_request_t *r, 25 static ngx_int_t ngx_http_process_host(ngx_http_request_t *r,
28 ngx_table_elt_t *h, ngx_uint_t offset); 26 ngx_table_elt_t *h, ngx_uint_t offset);
29 static ngx_int_t ngx_http_process_connection(ngx_http_request_t *r, 27 static ngx_int_t ngx_http_process_connection(ngx_http_request_t *r,
30 ngx_table_elt_t *h, ngx_uint_t offset); 28 ngx_table_elt_t *h, ngx_uint_t offset);
31 static ngx_int_t ngx_http_process_user_agent(ngx_http_request_t *r, 29 static ngx_int_t ngx_http_process_user_agent(ngx_http_request_t *r,
157 ngx_http_process_header_line }, 155 ngx_http_process_header_line },
158 156
159 #if (NGX_HTTP_X_FORWARDED_FOR) 157 #if (NGX_HTTP_X_FORWARDED_FOR)
160 { ngx_string("X-Forwarded-For"), 158 { ngx_string("X-Forwarded-For"),
161 offsetof(ngx_http_headers_in_t, x_forwarded_for), 159 offsetof(ngx_http_headers_in_t, x_forwarded_for),
162 ngx_http_process_multi_header_lines }, 160 ngx_http_process_header_line },
163 #endif 161 #endif
164 162
165 #if (NGX_HTTP_REALIP) 163 #if (NGX_HTTP_REALIP)
166 { ngx_string("X-Real-IP"), 164 { ngx_string("X-Real-IP"),
167 offsetof(ngx_http_headers_in_t, x_real_ip), 165 offsetof(ngx_http_headers_in_t, x_real_ip),
189 187
190 { ngx_string("Date"), offsetof(ngx_http_headers_in_t, date), 188 { ngx_string("Date"), offsetof(ngx_http_headers_in_t, date),
191 ngx_http_process_header_line }, 189 ngx_http_process_header_line },
192 #endif 190 #endif
193 191
194 { ngx_string("Cookie"), offsetof(ngx_http_headers_in_t, cookies), 192 { ngx_string("Cookie"), offsetof(ngx_http_headers_in_t, cookie),
195 ngx_http_process_multi_header_lines }, 193 ngx_http_process_header_line },
196 194
197 { ngx_null_string, 0, NULL } 195 { ngx_null_string, 0, NULL }
198 }; 196 };
199 197
200 198
1750 { 1748 {
1751 ngx_table_elt_t **ph; 1749 ngx_table_elt_t **ph;
1752 1750
1753 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + offset); 1751 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + offset);
1754 1752
1755 if (*ph == NULL) { 1753 while (*ph) { ph = &(*ph)->next; }
1756 *ph = h; 1754
1757 } 1755 *ph = h;
1756 h->next = NULL;
1758 1757
1759 return NGX_OK; 1758 return NGX_OK;
1760 } 1759 }
1761 1760
1762 1761
1768 1767
1769 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + offset); 1768 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + offset);
1770 1769
1771 if (*ph == NULL) { 1770 if (*ph == NULL) {
1772 *ph = h; 1771 *ph = h;
1772 h->next = NULL;
1773 return NGX_OK; 1773 return NGX_OK;
1774 } 1774 }
1775 1775
1776 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, 1776 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
1777 "client sent duplicate header line: \"%V: %V\", " 1777 "client sent duplicate header line: \"%V: %V\", "
1800 ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); 1800 ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
1801 return NGX_ERROR; 1801 return NGX_ERROR;
1802 } 1802 }
1803 1803
1804 r->headers_in.host = h; 1804 r->headers_in.host = h;
1805 h->next = NULL;
1805 1806
1806 host = h->value; 1807 host = h->value;
1807 1808
1808 rc = ngx_http_validate_host(&host, r->pool, 0); 1809 rc = ngx_http_validate_host(&host, r->pool, 0);
1809 1810
1835 1836
1836 static ngx_int_t 1837 static ngx_int_t
1837 ngx_http_process_connection(ngx_http_request_t *r, ngx_table_elt_t *h, 1838 ngx_http_process_connection(ngx_http_request_t *r, ngx_table_elt_t *h,
1838 ngx_uint_t offset) 1839 ngx_uint_t offset)
1839 { 1840 {
1841 if (ngx_http_process_header_line(r, h, offset) != NGX_OK) {
1842 return NGX_ERROR;
1843 }
1844
1840 if (ngx_strcasestrn(h->value.data, "close", 5 - 1)) { 1845 if (ngx_strcasestrn(h->value.data, "close", 5 - 1)) {
1841 r->headers_in.connection_type = NGX_HTTP_CONNECTION_CLOSE; 1846 r->headers_in.connection_type = NGX_HTTP_CONNECTION_CLOSE;
1842 1847
1843 } else if (ngx_strcasestrn(h->value.data, "keep-alive", 10 - 1)) { 1848 } else if (ngx_strcasestrn(h->value.data, "keep-alive", 10 - 1)) {
1844 r->headers_in.connection_type = NGX_HTTP_CONNECTION_KEEP_ALIVE; 1849 r->headers_in.connection_type = NGX_HTTP_CONNECTION_KEEP_ALIVE;
1852 ngx_http_process_user_agent(ngx_http_request_t *r, ngx_table_elt_t *h, 1857 ngx_http_process_user_agent(ngx_http_request_t *r, ngx_table_elt_t *h,
1853 ngx_uint_t offset) 1858 ngx_uint_t offset)
1854 { 1859 {
1855 u_char *user_agent, *msie; 1860 u_char *user_agent, *msie;
1856 1861
1857 if (r->headers_in.user_agent) { 1862 if (ngx_http_process_header_line(r, h, offset) != NGX_OK) {
1858 return NGX_OK; 1863 return NGX_ERROR;
1859 } 1864 }
1860
1861 r->headers_in.user_agent = h;
1862 1865
1863 /* check some widespread browsers while the header is in CPU cache */ 1866 /* check some widespread browsers while the header is in CPU cache */
1864 1867
1865 user_agent = h->value.data; 1868 user_agent = h->value.data;
1866 1869
1915 } else if (ngx_strstrn(user_agent, "Konqueror", 9 - 1)) { 1918 } else if (ngx_strstrn(user_agent, "Konqueror", 9 - 1)) {
1916 r->headers_in.konqueror = 1; 1919 r->headers_in.konqueror = 1;
1917 } 1920 }
1918 } 1921 }
1919 1922
1920 return NGX_OK;
1921 }
1922
1923
1924 static ngx_int_t
1925 ngx_http_process_multi_header_lines(ngx_http_request_t *r, ngx_table_elt_t *h,
1926 ngx_uint_t offset)
1927 {
1928 ngx_array_t *headers;
1929 ngx_table_elt_t **ph;
1930
1931 headers = (ngx_array_t *) ((char *) &r->headers_in + offset);
1932
1933 if (headers->elts == NULL) {
1934 if (ngx_array_init(headers, r->pool, 1, sizeof(ngx_table_elt_t *))
1935 != NGX_OK)
1936 {
1937 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1938 return NGX_ERROR;
1939 }
1940 }
1941
1942 ph = ngx_array_push(headers);
1943 if (ph == NULL) {
1944 ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
1945 return NGX_ERROR;
1946 }
1947
1948 *ph = h;
1949 return NGX_OK; 1923 return NGX_OK;
1950 } 1924 }
1951 1925
1952 1926
1953 ngx_int_t 1927 ngx_int_t