comparison src/http/ngx_http_request.c @ 2004:38fa1d3a31b7

test user agent in header callback
author Igor Sysoev <igor@sysoev.ru>
date Tue, 13 May 2008 09:18:58 +0000
parents f32cc6df6bd6
children 22ec7da42e6f
comparison
equal deleted inserted replaced
2003:fe94e3e28fea 2004:38fa1d3a31b7
20 static ngx_int_t ngx_http_process_header_line(ngx_http_request_t *r, 20 static ngx_int_t ngx_http_process_header_line(ngx_http_request_t *r,
21 ngx_table_elt_t *h, ngx_uint_t offset); 21 ngx_table_elt_t *h, ngx_uint_t offset);
22 static ngx_int_t ngx_http_process_unique_header_line(ngx_http_request_t *r, 22 static ngx_int_t ngx_http_process_unique_header_line(ngx_http_request_t *r,
23 ngx_table_elt_t *h, ngx_uint_t offset); 23 ngx_table_elt_t *h, ngx_uint_t offset);
24 static ngx_int_t ngx_http_process_connection(ngx_http_request_t *r, 24 static ngx_int_t ngx_http_process_connection(ngx_http_request_t *r,
25 ngx_table_elt_t *h, ngx_uint_t offset);
26 static ngx_int_t ngx_http_process_user_agent(ngx_http_request_t *r,
25 ngx_table_elt_t *h, ngx_uint_t offset); 27 ngx_table_elt_t *h, ngx_uint_t offset);
26 static ngx_int_t ngx_http_process_cookie(ngx_http_request_t *r, 28 static ngx_int_t ngx_http_process_cookie(ngx_http_request_t *r,
27 ngx_table_elt_t *h, ngx_uint_t offset); 29 ngx_table_elt_t *h, ngx_uint_t offset);
28 30
29 static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r); 31 static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r);
77 79
78 { ngx_string("If-Modified-Since"), 80 { ngx_string("If-Modified-Since"),
79 offsetof(ngx_http_headers_in_t, if_modified_since), 81 offsetof(ngx_http_headers_in_t, if_modified_since),
80 ngx_http_process_unique_header_line }, 82 ngx_http_process_unique_header_line },
81 83
82 { ngx_string("User-Agent"), offsetof(ngx_http_headers_in_t, user_agent), 84 { ngx_string("User-Agent"), 0, ngx_http_process_user_agent },
83 ngx_http_process_header_line },
84 85
85 { ngx_string("Referer"), offsetof(ngx_http_headers_in_t, referer), 86 { ngx_string("Referer"), offsetof(ngx_http_headers_in_t, referer),
86 ngx_http_process_header_line }, 87 ngx_http_process_header_line },
87 88
88 { ngx_string("Content-Length"), 89 { ngx_string("Content-Length"),
1248 return NGX_ERROR; 1249 return NGX_ERROR;
1249 } 1250 }
1250 1251
1251 1252
1252 static ngx_int_t 1253 static ngx_int_t
1254 ngx_http_process_user_agent(ngx_http_request_t *r, ngx_table_elt_t *h,
1255 ngx_uint_t offset)
1256 {
1257 u_char *ua, *user_agent;
1258
1259 if (r->headers_in.user_agent) {
1260 return NGX_OK;
1261 }
1262
1263 r->headers_in.user_agent = h;
1264
1265 /* check some widespread browsers while the header is in CPU cache */
1266
1267 user_agent = h->value.data;
1268
1269 ua = ngx_strstrn(user_agent, "MSIE", 4 - 1);
1270
1271 if (ua && ua + 8 < user_agent + r->headers_in.user_agent->value.len) {
1272
1273 r->headers_in.msie = 1;
1274
1275 if (ua[4] == ' ' && ua[5] == '4' && ua[6] == '.') {
1276 r->headers_in.msie4 = 1;
1277 }
1278
1279 #if 0
1280 /* MSIE ignores the SSL "close notify" alert */
1281 if (c->ssl) {
1282 c->ssl->no_send_shutdown = 1;
1283 }
1284 #endif
1285 }
1286
1287 if (ngx_strstrn(user_agent, "Opera", 5 - 1)) {
1288 r->headers_in.opera = 1;
1289 r->headers_in.msie = 0;
1290 r->headers_in.msie4 = 0;
1291 }
1292
1293 if (!r->headers_in.msie && !r->headers_in.opera) {
1294
1295 if (ngx_strstrn(user_agent, "Gecko/", 6 - 1)) {
1296 r->headers_in.gecko = 1;
1297
1298 } else if (ngx_strstrn(user_agent, "Konqueror", 9 - 1)) {
1299 r->headers_in.konqueror = 1;
1300 }
1301 }
1302
1303 return NGX_OK;
1304 }
1305
1306
1307 static ngx_int_t
1253 ngx_http_process_request_header(ngx_http_request_t *r) 1308 ngx_http_process_request_header(ngx_http_request_t *r)
1254 { 1309 {
1255 size_t len; 1310 size_t len;
1256 u_char *host, *ua, *user_agent, ch; 1311 u_char *host, ch;
1257 ngx_uint_t hash; 1312 ngx_uint_t hash;
1258 1313
1259 if (r->headers_in.host) { 1314 if (r->headers_in.host) {
1260 1315
1261 hash = 0; 1316 hash = 0;
1348 if (r->headers_in.connection_type == NGX_HTTP_CONNECTION_KEEP_ALIVE) { 1403 if (r->headers_in.connection_type == NGX_HTTP_CONNECTION_KEEP_ALIVE) {
1349 if (r->headers_in.keep_alive) { 1404 if (r->headers_in.keep_alive) {
1350 r->headers_in.keep_alive_n = 1405 r->headers_in.keep_alive_n =
1351 ngx_atotm(r->headers_in.keep_alive->value.data, 1406 ngx_atotm(r->headers_in.keep_alive->value.data,
1352 r->headers_in.keep_alive->value.len); 1407 r->headers_in.keep_alive->value.len);
1353 }
1354 }
1355
1356 if (r->headers_in.user_agent) {
1357
1358 /*
1359 * check some widespread browsers while the headers are still
1360 * in CPU cache
1361 */
1362
1363 user_agent = r->headers_in.user_agent->value.data;
1364
1365 ua = ngx_strstrn(user_agent, "MSIE", 4 - 1);
1366
1367 if (ua && ua + 8 < user_agent + r->headers_in.user_agent->value.len) {
1368
1369 r->headers_in.msie = 1;
1370
1371 if (ua[4] == ' ' && ua[5] == '4' && ua[6] == '.') {
1372 r->headers_in.msie4 = 1;
1373 }
1374
1375 #if 0
1376 /* MSIE ignores the SSL "close notify" alert */
1377 if (c->ssl) {
1378 c->ssl->no_send_shutdown = 1;
1379 }
1380 #endif
1381 }
1382
1383 if (ngx_strstrn(user_agent, "Opera", 5 - 1)) {
1384 r->headers_in.opera = 1;
1385 r->headers_in.msie = 0;
1386 r->headers_in.msie4 = 0;
1387 }
1388
1389 if (!r->headers_in.msie && !r->headers_in.opera) {
1390
1391 if (ngx_strstrn(user_agent, "Gecko/", 6 - 1)) {
1392 r->headers_in.gecko = 1;
1393
1394 } else if (ngx_strstrn(user_agent, "Konqueror", 9 - 1)) {
1395 r->headers_in.konqueror = 1;
1396 }
1397 } 1408 }
1398 } 1409 }
1399 1410
1400 return NGX_OK; 1411 return NGX_OK;
1401 } 1412 }