Chrome开发工具Network没有显示完整的http request和response对话
Chrome开发工具Network没有显示完整的http request和response对话
这几天看《http defintion guide》介绍Authorization和www-Authorization的机制时不是很理解,因此自己动手做实验,从而发现了Chrome开发工具Network一点有趣的小问题,特此记录。
Authorization和www-Authorization是http header,用于对客户端用户的身份认证,过程如下图。
(1)client向server发出request
(2)Server发现request的resource需要身份认证,发出401 reponse给client,其中含有www-Authorization header,说明此资源需要通过Authorization来做身份认证
(3)Client的浏览器会弹出用户名和密码对话框,用户输入用户名和密码,点击确定按钮后,client向server又提交了一个request,并含有Authorization header,其内容是用户名和密码用Base64方式编码(没有加密)
(4)Server收到request后,返回200 reponse
这种方式被称为BASIC authentication
我当时不理解之处在于,这种身份验证方式建立之后,如果client要向server继续request其他的资源怎么处理?
于是我设计下面一个实验
在server中,创建一个auth1.php文件,其代码如下:
<?php
if (!isset($_SERVER[‘PHP_AUTH_USER‘])) {
header(‘WWW-Authenticate: Basic realm="My Realm"‘);
header(‘HTTP/1.0 401 Unauthorized‘);
echo ‘Text to send if user hits Cancel button 2‘;
exit;
} elseif ( $_SERVER[‘PHP_AUTH_USER‘] <> "kursk" ) {
echo "<p>your entere is wrong.</p>";
header(‘WWW-Authenticate: Basic realm="My Realm"‘);
header(‘HTTP/1.0 401 Unauthorized‘);
} else {
echo "<p>Hello {$_SERVER[‘PHP_AUTH_USER‘]}.</p>";
echo "<p>You entered {$_SERVER[‘PHP_AUTH_PW‘]} as your password 2.</p>";
}
?>
实验过程是这样:
(1)通过浏览器发出request
(2)弹出的对话框中输入错误的用户名
(3)再次弹出的对话框中输入正确的用户名
用chrome开发工具监视network情况,同时用tcpdump监视服务器80端口,结果是这样的。
chrome开发工具监视network情况的结果
这里发现了一些有趣的细节,chrome开发工具network窗口并没有显示出全部的C/S对话内容,而只是显示了最后一次request和response
通过Tcpdump捕获的packet我们可以看到更详细的过程
Tcpdump命令
sudo tcpdump -vv -x -X -i lo ‘tcp port 80 ‘ > auth.log
Auth.log内容
11:36:38.629644 IP (tos 0x0, ttl 64, id 14210, offset 0, flags [DF], proto TCP (6), length 60)
localhost.55696 > localhost.http: Flags [S], cksum 0xfe30 (incorrect -> 0xef18), seq 2731017717, win 43690, options [mss 65495,sackOK,TS val 16855671 ecr 0,nop,wscale 7], length 0
0x0000: 4500 003c 3782 4000 4006 0538 7f00 0001 E..<7.@. @..8....
0x0010: 7f00 0001 d990 0050 a2c8 05f5 0000 0000 .......P........
0x0020: a002 aaaa fe30 0000 0204 ffd7 0402 080a .....0..........
0x0030: 0101 3277 0000 0000 0103 0307 ..2w........
11:36:38.629680 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 60)
localhost.http > localhost.55696: Flags [S.], cksum 0xfe30 (incorrect -> 0x6bc1), seq 451228905, ack 2731017718, win 43690, options [mss 65495,sackOK,TS val 16855671 ecr 16855671,nop,wscale 7], length 0
0x0000: 4500 003c 0000 4000 4006 3cba 7f00 0001 E..<..@. @.<.....
0x0010: 7f00 0001 0050 d990 1ae5 34e9 a2c8 05f6 .....P....4.....
0x0020: a012 aaaa fe30 0000 0204 ffd7 0402 080a .....0..........
0x0030: 0101 3277 0101 3277 0103 0307 ..2w..2w....
11:36:38.629717 IP (tos 0x0, ttl 64, id 14211, offset 0, flags [DF], proto TCP (6), length 52)
localhost.55696 > localhost.http: Flags [.], cksum 0xfe28 (incorrect -> 0x3e06), seq 1, ack 1, win 342, options [nop,nop,TS val 16855671 ecr 16855671], length 0
0x0000: 4500 0034 3783 4000 4006 053f 7f00 0001 E..47.@. @..?....
0x0010: 7f00 0001 d990 0050 a2c8 05f6 1ae5 34ea .......P......4.
0x0020: 8010 0156 fe28 0000 0101 080a 0101 3277 ...V.(........2w
0x0030: 0101 3277 ..2w
11:36:38.630215 IP (tos 0x0, ttl 64, id 14212, offset 0, flags [DF], proto TCP (6), length 481)
localhost.55696 > localhost.http: Flags [P.], cksum 0xffd5 (incorrect -> 0x00fa), seq 1:430, ack 1, win 342, options [nop,nop,TS val 16855672 ecr 16855671], length 429
0x0000: 4500 01e1 3784 4000 4006 0391 7f00 0001 E...7.@.@.......
0x0010: 7f00 0001 d990 0050 a2c8 05f6 1ae5 34ea .......P......4.
0x0020: 8018 0156 ffd5 0000 0101 080a 0101 3278 ...V..........2x
0x0030: 0101 3277 4745 5420 2f61 7574 682d 6865 ..2wGET./auth-he
0x0040: 6164 6572 2f61 7574 6831 2e70 6870 2048 ader/auth1.php.H
0x0050: 5454 502f 312e 310d 0a48 6f73 743a 2031 TTP/1.1..Host:.1
0x0060: 3237 2e30 2e30 2e31 0d0a 436f 6e6e 6563 27.0.0.1..Connec
0x0070: 7469 6f6e 3a20 6b65 6570 2d61 6c69 7665 tion:.keep-alive
0x0080: 0d0a 4361 6368 652d 436f 6e74 726f 6c3a ..Cache-Control:
0x0090: 206d 6178 2d61 6765 3d30 0d0a 4163 6365 .max-age=0..Acce
0x00a0: 7074 3a20 7465 7874 2f68 746d 6c2c 6170 pt:.text/html,ap
0x00b0: 706c 6963 6174 696f 6e2f 7868 746d 6c2b plication/xhtml+
0x00c0: 786d 6c2c 6170 706c 6963 6174 696f 6e2f xml,application/
0x00d0: 786d 6c3b 713d 302e 392c 696d 6167 652f xml;q=0.9,image/
0x00e0: 7765 6270 2c2a 2f2a 3b71 3d30 2e38 0d0a webp,*/*;q=0.8..
0x00f0: 5573 6572 2d41 6765 6e74 3a20 4d6f 7a69 User-Agent:.Mozi
0x0100: 6c6c 612f 352e 3020 2858 3131 3b20 4c69 lla/5.0.(X11;.Li
0x0110: 6e75 7820 7838 365f 3634 2920 4170 706c nux.x86_64).Appl
0x0120: 6557 6562 4b69 742f 3533 372e 3336 2028 eWebKit/537.36.(
0x0130: 4b48 544d 4c2c 206c 696b 6520 4765 636b KHTML,.like.Geck
0x0140: 6f29 2055 6275 6e74 7520 4368 726f 6d69 o).Ubuntu.Chromi
0x0150: 756d 2f34 312e 302e 3232 3732 2e37 3620 um/41.0.2272.76.
0x0160: 4368 726f 6d65 2f34 312e 302e 3232 3732 Chrome/41.0.2272
0x0170: 2e37 3620 5361 6661 7269 2f35 3337 2e33 .76.Safari/537.3
0x0180: 360d 0a41 6363 6570 742d 456e 636f 6469 6..Accept-Encodi
0x0190: 6e67 3a20 677a 6970 2c20 6465 666c 6174 ng:.gzip,.deflat
0x01a0: 652c 2073 6463 680d 0a41 6363 6570 742d e,.sdch..Accept-
0x01b0: 4c61 6e67 7561 6765 3a20 656e 2c7a 682d Language:.en,zh-
0x01c0: 434e 3b71 3d30 2e38 2c7a 683b 713d 302e CN;q=0.8,zh;q=0.
0x01d0: 362c 7a68 2d54 573b 713d 302e 340d 0a0d 6,zh-TW;q=0.4...
0x01e0: 0a .
11:36:38.630224 IP (tos 0x0, ttl 64, id 1693, offset 0, flags [DF], proto TCP (6), length 52)
localhost.http > localhost.55696: Flags [.], cksum 0xfe28 (incorrect -> 0x3c4f), seq 1, ack 430, win 350, options [nop,nop,TS val 16855672 ecr 16855672], length 0
0x0000: 4500 0034 069d 4000 4006 3625 7f00 0001 E..4..@.@.6%....
0x0010: 7f00 0001 0050 d990 1ae5 34ea a2c8 07a3 .....P....4.....
0x0020: 8010 015e fe28 0000 0101 080a 0101 3278 ...^.(........2x
0x0030: 0101 3278 ..2x
11:36:38.631622 IP (tos 0x0, ttl 64, id 1694, offset 0, flags [DF], proto TCP (6), length 355)
localhost.http > localhost.55696: Flags [P.], cksum 0xff57 (incorrect -> 0x3ed1), seq 1:304, ack 430, win 350, options [nop,nop,TS val 16855672 ecr 16855672], length 303
0x0000: 4500 0163 069e 4000 4006 34f5 7f00 0001 E..c..@.@.4.....
0x0010: 7f00 0001 0050 d990 1ae5 34ea a2c8 07a3 .....P....4.....
0x0020: 8018 015e ff57 0000 0101 080a 0101 3278 ...^.W........2x
0x0030: 0101 3278 4854 5450 2f31 2e31 2034 3031 ..2xHTTP/1.1.401
0x0040: 2055 6e61 7574 686f 7269 7a65 640d 0a53 .Unauthorized..S
0x0050: 6572 7665 723a 206e 6769 6e78 2f31 2e34 erver:.nginx/1.4
0x0060: 2e36 2028 5562 756e 7475 290d 0a44 6174 .6.(Ubuntu)..Dat
0x0070: 653a 2053 756e 2c20 3039 2041 7567 2032 e:.Sun,.09.Aug.2
0x0080: 3031 3520 3033 3a33 363a 3338 2047 4d54 015.03:36:38.GMT
0x0090: 0d0a 436f 6e74 656e 742d 5479 7065 3a20 ..Content-Type:.
0x00a0: 7465 7874 2f68 746d 6c0d 0a54 7261 6e73 text/html..Trans
0x00b0: 6665 722d 456e 636f 6469 6e67 3a20 6368 fer-Encoding:.ch
0x00c0: 756e 6b65 640d 0a43 6f6e 6e65 6374 696f unked..Connectio
0x00d0: 6e3a 206b 6565 702d 616c 6976 650d 0a58 n:.keep-alive..X
0x00e0: 2d50 6f77 6572 6564 2d42 793a 2050 4850 -Powered-By:.PHP
0x00f0: 2f35 2e35 2e39 2d31 7562 756e 7475 342e /5.5.9-1ubuntu4.
0x0100: 390d 0a57 5757 2d41 7574 6865 6e74 6963 9..WWW-Authentic
0x0110: 6174 653a 2042 6173 6963 2072 6561 6c6d ate:.Basic.realm
0x0120: 3d22 4d79 2052 6561 6c6d 220d 0a0d 0a32 ="My.Realm"....2
0x0130: 390d 0a54 6578 7420 746f 2073 656e 6420 9..Text.to.send.
0x0140: 6966 2075 7365 7220 6869 7473 2043 616e if.user.hits.Can
0x0150: 6365 6c20 6275 7474 6f6e 2032 0d0a 300d cel.button.2..0.
0x0160: 0a0d 0a ...
11:36:38.631633 IP (tos 0x0, ttl 64, id 14213, offset 0, flags [DF], proto TCP (6), length 52)
localhost.55696 > localhost.http: Flags [.], cksum 0xfe28 (incorrect -> 0x3b20), seq 430, ack 304, win 350, options [nop,nop,TS val 16855672 ecr 16855672], length 0
0x0000: 4500 0034 3785 4000 4006 053d 7f00 0001 E..47.@.@..=....
0x0010: 7f00 0001 d990 0050 a2c8 07a3 1ae5 3619 .......P......6.
0x0020: 8010 015e fe28 0000 0101 080a 0101 3278 ...^.(........2x
0x0030: 0101 3278 ..2x
11:36:56.953092 IP (tos 0x0, ttl 64, id 14214, offset 0, flags [DF], proto TCP (6), length 516)
localhost.55696 > localhost.http: Flags [P.], cksum 0xfff8 (incorrect -> 0x5775), seq 430:894, ack 304, win 350, options [nop,nop,TS val 16860252 ecr 16855672], length 464
0x0000: 4500 0204 3786 4000 4006 036c 7f00 0001 E...7.@.@..l....
0x0010: 7f00 0001 d990 0050 a2c8 07a3 1ae5 3619 .......P......6.
0x0020: 8018 015e fff8 0000 0101 080a 0101 445c ...^..........D\
0x0030: 0101 3278 4745 5420 2f61 7574 682d 6865 ..2xGET./auth-he
0x0040: 6164 6572 2f61 7574 6831 2e70 6870 2048 ader/auth1.php.H
0x0050: 5454 502f 312e 310d 0a48 6f73 743a 2031 TTP/1.1..Host:.1
0x0060: 3237 2e30 2e30 2e31 0d0a 436f 6e6e 6563 27.0.0.1..Connec
0x0070: 7469 6f6e 3a20 6b65 6570 2d61 6c69 7665 tion:.keep-alive
0x0080: 0d0a 4361 6368 652d 436f 6e74 726f 6c3a ..Cache-Control:
0x0090: 206d 6178 2d61 6765 3d30 0d0a 4175 7468 .max-age=0..Auth
0x00a0: 6f72 697a 6174 696f 6e3a 2042 6173 6963 orization:.Basic
0x00b0: 2059 3239 7661 7a6f 784d 6a4d 3d0d 0a41 .Y29vazoxMjM=..A
0x00c0: 6363 6570 743a 2074 6578 742f 6874 6d6c ccept:.text/html
0x00d0: 2c61 7070 6c69 6361 7469 6f6e 2f78 6874 ,application/xht
0x00e0: 6d6c 2b78 6d6c 2c61 7070 6c69 6361 7469 ml+xml,applicati
0x00f0: 6f6e 2f78 6d6c 3b71 3d30 2e39 2c69 6d61 on/xml;q=0.9,ima
0x0100: 6765 2f77 6562 702c 2a2f 2a3b 713d 302e ge/webp,*/*;q=0.
0x0110: 380d 0a55 7365 722d 4167 656e 743a 204d 8..User-Agent:.M
0x0120: 6f7a 696c 6c61 2f35 2e30 2028 5831 313b ozilla/5.0.(X11;
0x0130: 204c 696e 7578 2078 3836 5f36 3429 2041 .Linux.x86_64).A
0x0140: 7070 6c65 5765 624b 6974 2f35 3337 2e33 ppleWebKit/537.3
0x0150: 3620 284b 4854 4d4c 2c20 6c69 6b65 2047 6.(KHTML,.like.G
0x0160: 6563 6b6f 2920 5562 756e 7475 2043 6872 ecko).Ubuntu.Chr
0x0170: 6f6d 6975 6d2f 3431 2e30 2e32 3237 322e omium/41.0.2272.
0x0180: 3736 2043 6872 6f6d 652f 3431 2e30 2e32 76.Chrome/41.0.2
0x0190: 3237 322e 3736 2053 6166 6172 692f 3533 272.76.Safari/53
0x01a0: 372e 3336 0d0a 4163 6365 7074 2d45 6e63 7.36..Accept-Enc
0x01b0: 6f64 696e 673a 2067 7a69 702c 2064 6566 oding:.gzip,.def
0x01c0: 6c61 7465 2c20 7364 6368 0d0a 4163 6365 late,.sdch..Acce
0x01d0: 7074 2d4c 616e 6775 6167 653a 2065 6e2c pt-Language:.en,
0x01e0: 7a68 2d43 4e3b 713d 302e 382c 7a68 3b71 zh-CN;q=0.8,zh;q
0x01f0: 3d30 2e36 2c7a 682d 5457 3b71 3d30 2e34 =0.6,zh-TW;q=0.4
0x0200: 0d0a 0d0a ....
11:36:56.953772 IP (tos 0x0, ttl 64, id 1695, offset 0, flags [DF], proto TCP (6), length 342)
localhost.http > localhost.55696: Flags [P.], cksum 0xff4a (incorrect -> 0x960b), seq 304:594, ack 894, win 359, options [nop,nop,TS val 16860252 ecr 16860252], length 290
0x0000: 4500 0156 069f 4000 4006 3501 7f00 0001 E..V..@.@.5.....
0x0010: 7f00 0001 0050 d990 1ae5 3619 a2c8 0973 .....P....6....s
0x0020: 8018 0167 ff4a 0000 0101 080a 0101 445c ...g.J........D\
0x0030: 0101 445c 4854 5450 2f31 2e31 2034 3031 ..D\HTTP/1.1.401
0x0040: 2055 6e61 7574 686f 7269 7a65 640d 0a53 .Unauthorized..S
0x0050: 6572 7665 723a 206e 6769 6e78 2f31 2e34 erver:.nginx/1.4
0x0060: 2e36 2028 5562 756e 7475 290d 0a44 6174 .6.(Ubuntu)..Dat
0x0070: 653a 2053 756e 2c20 3039 2041 7567 2032 e:.Sun,.09.Aug.2
0x0080: 3031 3520 3033 3a33 363a 3536 2047 4d54 015.03:36:56.GMT
0x0090: 0d0a 436f 6e74 656e 742d 5479 7065 3a20 ..Content-Type:.
0x00a0: 7465 7874 2f68 746d 6c0d 0a54 7261 6e73 text/html..Trans
0x00b0: 6665 722d 456e 636f 6469 6e67 3a20 6368 fer-Encoding:.ch
0x00c0: 756e 6b65 640d 0a43 6f6e 6e65 6374 696f unked..Connectio
0x00d0: 6e3a 206b 6565 702d 616c 6976 650d 0a58 n:.keep-alive..X
0x00e0: 2d50 6f77 6572 6564 2d42 793a 2050 4850 -Powered-By:.PHP
0x00f0: 2f35 2e35 2e39 2d31 7562 756e 7475 342e /5.5.9-1ubuntu4.
0x0100: 390d 0a57 5757 2d41 7574 6865 6e74 6963 9..WWW-Authentic
0x0110: 6174 653a 2042 6173 6963 2072 6561 6c6d ate:.Basic.realm
0x0120: 3d22 4d79 2052 6561 6c6d 220d 0a0d 0a31 ="My.Realm"....1
0x0130: 630d 0a3c 703e 796f 7572 2065 6e74 6572 c..<p>your.enter
0x0140: 6520 6973 2077 726f 6e67 2e3c 2f70 3e0d e.is.wrong.</p>.
0x0150: 0a30 0d0a 0d0a .0....
11:36:56.953788 IP (tos 0x0, ttl 64, id 14215, offset 0, flags [DF], proto TCP (6), length 52)
localhost.55696 > localhost.http: Flags [.], cksum 0xfe28 (incorrect -> 0x145d), seq 894, ack 594, win 359, options [nop,nop,TS val 16860252 ecr 16860252], length 0
0x0000: 4500 0034 3787 4000 4006 053b 7f00 0001 E..47.@.@..;....
0x0010: 7f00 0001 d990 0050 a2c8 0973 1ae5 373b .......P...s..7;
0x0020: 8010 0167 fe28 0000 0101 080a 0101 445c ...g.(........D\
0x0030: 0101 445c ..D\
11:37:05.953469 IP (tos 0x0, ttl 64, id 14216, offset 0, flags [DF], proto TCP (6), length 516)
localhost.55696 > localhost.http: Flags [P.], cksum 0xfff8 (incorrect -> 0x98a5), seq 894:1358, ack 594, win 359, options [nop,nop,TS val 16862502 ecr 16860252], length 464
0x0000: 4500 0204 3788 4000 4006 036a 7f00 0001 E...7.@.@..j....
0x0010: 7f00 0001 d990 0050 a2c8 0973 1ae5 373b .......P...s..7;
0x0020: 8018 0167 fff8 0000 0101 080a 0101 4d26 ...g..........M&
0x0030: 0101 445c 4745 5420 2f61 7574 682d 6865 ..D\GET./auth-he
0x0040: 6164 6572 2f61 7574 6831 2e70 6870 2048 ader/auth1.php.H
0x0050: 5454 502f 312e 310d 0a48 6f73 743a 2031 TTP/1.1..Host:.1
0x0060: 3237 2e30 2e30 2e31 0d0a 436f 6e6e 6563 27.0.0.1..Connec
0x0070: 7469 6f6e 3a20 6b65 6570 2d61 6c69 7665 tion:.keep-alive
0x0080: 0d0a 4361 6368 652d 436f 6e74 726f 6c3a ..Cache-Control:
0x0090: 206d 6178 2d61 6765 3d30 0d0a 4175 7468 .max-age=0..Auth
0x00a0: 6f72 697a 6174 696f 6e3a 2042 6173 6963 orization:.Basic
0x00b0: 2061 3356 7963 3273 364d 5449 7a0d 0a41 .a3Vyc2s6MTIz..A
0x00c0: 6363 6570 743a 2074 6578 742f 6874 6d6c ccept:.text/html
0x00d0: 2c61 7070 6c69 6361 7469 6f6e 2f78 6874 ,application/xht
0x00e0: 6d6c 2b78 6d6c 2c61 7070 6c69 6361 7469 ml+xml,applicati
0x00f0: 6f6e 2f78 6d6c 3b71 3d30 2e39 2c69 6d61 on/xml;q=0.9,ima
0x0100: 6765 2f77 6562 702c 2a2f 2a3b 713d 302e ge/webp,*/*;q=0.
0x0110: 380d 0a55 7365 722d 4167 656e 743a 204d 8..User-Agent:.M
0x0120: 6f7a 696c 6c61 2f35 2e30 2028 5831 313b ozilla/5.0.(X11;
0x0130: 204c 696e 7578 2078 3836 5f36 3429 2041 .Linux.x86_64).A
0x0140: 7070 6c65 5765 624b 6974 2f35 3337 2e33 ppleWebKit/537.3
0x0150: 3620 284b 4854 4d4c 2c20 6c69 6b65 2047 6.(KHTML,.like.G
0x0160: 6563 6b6f 2920 5562 756e 7475 2043 6872 ecko).Ubuntu.Chr
0x0170: 6f6d 6975 6d2f 3431 2e30 2e32 3237 322e omium/41.0.2272.
0x0180: 3736 2043 6872 6f6d 652f 3431 2e30 2e32 76.Chrome/41.0.2
0x0190: 3237 322e 3736 2053 6166 6172 692f 3533 272.76.Safari/53
0x01a0: 372e 3336 0d0a 4163 6365 7074 2d45 6e63 7.36..Accept-Enc
0x01b0: 6f64 696e 673a 2067 7a69 702c 2064 6566 oding:.gzip,.def
0x01c0: 6c61 7465 2c20 7364 6368 0d0a 4163 6365 late,.sdch..Acce
0x01d0: 7074 2d4c 616e 6775 6167 653a 2065 6e2c pt-Language:.en,
0x01e0: 7a68 2d43 4e3b 713d 302e 382c 7a68 3b71 zh-CN;q=0.8,zh;q
0x01f0: 3d30 2e36 2c7a 682d 5457 3b71 3d30 2e34 =0.6,zh-TW;q=0.4
0x0200: 0d0a 0d0a ....
11:37:05.954503 IP (tos 0x0, ttl 64, id 1696, offset 0, flags [DF], proto TCP (6), length 364)
localhost.http > localhost.55696: Flags [P.], cksum 0xff60 (incorrect -> 0x370d), seq 594:906, ack 1358, win 367, options [nop,nop,TS val 16862503 ecr 16862502], length 312
0x0000: 4500 016c 06a0 4000 4006 34ea 7f00 0001 E..l..@.@.4.....
0x0010: 7f00 0001 0050 d990 1ae5 373b a2c8 0b43 .....P....7;...C
0x0020: 8018 016f ff60 0000 0101 080a 0101 4d27 ...o.`........M‘
0x0030: 0101 4d26 4854 5450 2f31 2e31 2032 3030 ..M&HTTP/1.1.200
0x0040: 204f 4b0d 0a53 6572 7665 723a 206e 6769 .OK..Server:.ngi
0x0050: 6e78 2f31 2e34 2e36 2028 5562 756e 7475 nx/1.4.6.(Ubuntu
0x0060: 290d 0a44 6174 653a 2053 756e 2c20 3039 )..Date:.Sun,.09
0x0070: 2041 7567 2032 3031 3520 3033 3a33 373a .Aug.2015.03:37:
0x0080: 3035 2047 4d54 0d0a 436f 6e74 656e 742d 05.GMT..Content-
0x0090: 5479 7065 3a20 7465 7874 2f68 746d 6c0d Type:.text/html.
0x00a0: 0a54 7261 6e73 6665 722d 456e 636f 6469 .Transfer-Encodi
0x00b0: 6e67 3a20 6368 756e 6b65 640d 0a43 6f6e ng:.chunked..Con
0x00c0: 6e65 6374 696f 6e3a 206b 6565 702d 616c nection:.keep-al
0x00d0: 6976 650d 0a58 2d50 6f77 6572 6564 2d42 ive..X-Powered-B
0x00e0: 793a 2050 4850 2f35 2e35 2e39 2d31 7562 y:.PHP/5.5.9-1ub
0x00f0: 756e 7475 342e 390d 0a43 6f6e 7465 6e74 untu4.9..Content
0x0100: 2d45 6e63 6f64 696e 673a 2067 7a69 700d -Encoding:.gzip.
0x0110: 0a0d 0a34 650d 0a1f 8b08 0000 0000 0000 ...4e...........
0x0120: 03b3 29b0 f348 cdc9 c957 c82e 2d2a ced6 ..)..H...W..-*..
0x0130: b3d1 2fb0 b329 b08b cc2f 5548 cd2b 492d ../..).../UH.+I-
0x0140: 4a4d 5130 3432 5648 2c56 a8cc 2f2d 5228 JMQ042VH,V../-R(
0x0150: 482c 2e2e cf2f 4a51 3002 ab04 0032 5b0f H,.../JQ0....2[.
0x0160: d93d 0000 000d 0a30 0d0a 0d0a .=.....0....
11:37:05.954519 IP (tos 0x0, ttl 64, id 14217, offset 0, flags [DF], proto TCP (6), length 52)
localhost.55696 > localhost.http: Flags [.], cksum 0xfe28 (incorrect -> 0xffb6), seq 1358, ack 906, win 367, options [nop,nop,TS val 16862503 ecr 16862503], length 0
0x0000: 4500 0034 3789 4000 4006 0539 7f00 0001 E..47.@.@..9....
0x0010: 7f00 0001 d990 0050 a2c8 0b43 1ae5 3873 .......P...C..8s
0x0020: 8010 016f fe28 0000 0101 080a 0101 4d27 ...o.(........M‘
0x0030: 0101 4d27 ..M‘
红色的是Flags标记,含义介绍:
Flags are some combination of S (SYN), F (FIN), P (PUSH), R (RST), U (URG), W (ECN CWR), E (ECN-Echo) or `.‘ (ACK), or `none‘ if no flags are set.
还有一点容易搞混就是那个flags [DF],其实它的意思是这个frame没有拆分,只有一个。A packet with the IP don‘t fragment flag is marked with a trailing (DF).
以上【参考资料2】
关于SYN,ACK,FIN标记的介绍,属于TCP connection“三次握手”和“四次断开”的内容,网上有太多资料,比如【参考资料3】,下面这个图是对tcp connection close简单地介绍
值得注意的是,本次实验中的tcpdump捕获内容中没有FIN标记,说明实验结束时tcp connection没有断开——提到这一点是因为我原先以为每对http request和response后都有一次tcp connection close,现在做实验才发现完全和我想的不同,其实想想也对,每次equest和response对话一次就close不是太浪费了效率了么,何况还有tcp slow start特性,建立tcp connection是要花时间的。
从tcpdump捕获的内容,我们发现是完全遵循前面提到的Authorization和www-Authorization运作机制,当身份认证建立后,client向server提交的每个request都会带上Authorization header(似乎通过缓存机制,具体方式与每种浏览器的有关),要想解除这种机制,只有重新发送错误的用户名和密码,stackoverflow上有个这方面的回答。【参考资料1】
通过这个实验,我也发现chrome开发工具的network最终显示的并非完整的http request和response,我猜想chrome开发工具是按每个资源(resource)来显示network的情况,所以每个resource就只显示最后一次的request和response,如果关于这个资源有多次request和response,那么前面的就会被覆盖掉,这点值得开发者使用chrome开发工具时注意。
看来google的chrome开发工具仍有改进的空间!
参考资料
[1]https://stackoverflow.com/questions/233507/how-to-log-out-user-from-web-site-using-basic-authentication
[2]http://www.tcpdump.org/tcpdump_man.html
[3]http://intronetworks.cs.luc.edu/current/html/tcp.html