Mercurial > hg > nginx-quic
comparison src/http/modules/proxy/ngx_http_proxy_parse.c @ 170:c42be4185301
nginx-0.0.1-2003-11-03-01:56:18 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 02 Nov 2003 22:56:18 +0000 |
parents | |
children | caa57ddf6d77 |
comparison
equal
deleted
inserted
replaced
169:edf29bb717da | 170:c42be4185301 |
---|---|
1 | |
2 #include <ngx_config.h> | |
3 #include <ngx_core.h> | |
4 #include <ngx_http.h> | |
5 #include <ngx_http_proxy_handler.h> | |
6 | |
7 | |
8 int ngx_http_proxy_parse_status_line(ngx_http_proxy_ctx_t *p) | |
9 { | |
10 char ch; | |
11 char *pos; | |
12 enum { | |
13 sw_start = 0, | |
14 sw_H, | |
15 sw_HT, | |
16 sw_HTT, | |
17 sw_HTTP, | |
18 sw_first_major_digit, | |
19 sw_major_digit, | |
20 sw_first_minor_digit, | |
21 sw_minor_digit, | |
22 sw_status, | |
23 sw_space_after_status, | |
24 sw_status_text, | |
25 sw_almost_done, | |
26 sw_done | |
27 } state; | |
28 | |
29 state = p->state; | |
30 pos = p->header_in->pos; | |
31 | |
32 while (pos < p->header_in->last && state < sw_done) { | |
33 ch = *pos++; | |
34 | |
35 switch (state) { | |
36 | |
37 /* "HTTP/" */ | |
38 case sw_start: | |
39 switch (ch) { | |
40 case 'H': | |
41 state = sw_H; | |
42 break; | |
43 default: | |
44 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
45 } | |
46 break; | |
47 | |
48 case sw_H: | |
49 switch (ch) { | |
50 case 'T': | |
51 state = sw_HT; | |
52 break; | |
53 default: | |
54 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
55 } | |
56 break; | |
57 | |
58 case sw_HT: | |
59 switch (ch) { | |
60 case 'T': | |
61 state = sw_HTT; | |
62 break; | |
63 default: | |
64 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
65 } | |
66 break; | |
67 | |
68 case sw_HTT: | |
69 switch (ch) { | |
70 case 'P': | |
71 state = sw_HTTP; | |
72 break; | |
73 default: | |
74 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
75 } | |
76 break; | |
77 | |
78 case sw_HTTP: | |
79 switch (ch) { | |
80 case '/': | |
81 state = sw_first_major_digit; | |
82 break; | |
83 default: | |
84 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
85 } | |
86 break; | |
87 | |
88 /* the first digit of major HTTP version */ | |
89 case sw_first_major_digit: | |
90 if (ch < '1' || ch > '9') { | |
91 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
92 } | |
93 | |
94 state = sw_major_digit; | |
95 break; | |
96 | |
97 /* the major HTTP version or dot */ | |
98 case sw_major_digit: | |
99 if (ch == '.') { | |
100 state = sw_first_minor_digit; | |
101 break; | |
102 } | |
103 | |
104 if (ch < '0' || ch > '9') { | |
105 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
106 } | |
107 | |
108 break; | |
109 | |
110 /* the first digit of minor HTTP version */ | |
111 case sw_first_minor_digit: | |
112 if (ch < '0' || ch > '9') { | |
113 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
114 } | |
115 | |
116 state = sw_minor_digit; | |
117 break; | |
118 | |
119 /* the minor HTTP version or the end of the request line */ | |
120 case sw_minor_digit: | |
121 if (ch == ' ') { | |
122 state = sw_status; | |
123 break; | |
124 } | |
125 | |
126 if (ch < '0' || ch > '9') { | |
127 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
128 } | |
129 | |
130 break; | |
131 | |
132 /* HTTP status code */ | |
133 case sw_status: | |
134 if (ch < '0' || ch > '9') { | |
135 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
136 } | |
137 | |
138 p->status = p->status * 10 + ch - '0'; | |
139 | |
140 if (++p->status_count == 3) { | |
141 state = sw_space_after_status; | |
142 p->status_start = pos - 3; | |
143 } | |
144 | |
145 break; | |
146 | |
147 /* space or end of line */ | |
148 case sw_space_after_status: | |
149 switch (ch) { | |
150 case ' ': | |
151 state = sw_status_text; | |
152 break; | |
153 case CR: | |
154 state = sw_almost_done; | |
155 break; | |
156 case LF: | |
157 state = sw_done; | |
158 break; | |
159 default: | |
160 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
161 } | |
162 break; | |
163 | |
164 /* any text until end of line */ | |
165 case sw_status_text: | |
166 switch (ch) { | |
167 case CR: | |
168 state = sw_almost_done; | |
169 | |
170 break; | |
171 case LF: | |
172 state = sw_done; | |
173 break; | |
174 } | |
175 break; | |
176 | |
177 /* end of request line */ | |
178 case sw_almost_done: | |
179 p->status_end = pos - 2; | |
180 switch (ch) { | |
181 case LF: | |
182 state = sw_done; | |
183 break; | |
184 default: | |
185 return NGX_HTTP_PROXY_PARSE_NO_HEADER; | |
186 } | |
187 break; | |
188 } | |
189 } | |
190 | |
191 p->header_in->pos = pos; | |
192 | |
193 if (state == sw_done) { | |
194 if (p->status_end == NULL) { | |
195 p->status_end = pos - 1; | |
196 } | |
197 | |
198 p->state = sw_start; | |
199 return NGX_OK; | |
200 } | |
201 | |
202 p->state = state; | |
203 return NGX_AGAIN; | |
204 } |