今回は前回に続いて、
「デカいRFC」の読み方
まずHTTPにはバージョンとして1.
HTT1.
また、
BNFを知ることはプロトコルを覚えることにも役立つので、
たとえばPage17には、
HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT
とあります。
""で括られているのはリテラル
BNF記法自体、
HTTP/1.1の2大特徴
さて、
まずHTTP/
いまではname based virtualなWebサーバは当たり前すぎますが、
簡単に言うと、
つまり、
たとえば
HOST: www.
であればwww.
HOST: www.
であればwww.
ちなみにIP basedというのは、
そして、
Both clients and servers MUST support the Host request-header.
A client that sends an HTTP/1.1 request MUST send a Host header.
Servers MUST report a 400 (Bad Request) error if an HTTP/1.1
request does not include a Host request-header.
Servers MUST accept absolute URIs.
すなわち、
もうひとつ、
Persisitent connections are the deafult for HTTP/1.1 messages; we introduce
a new keyword (Connection: close) for declaring non-persistence.
つまり、
HTTP/
なぜかというと、
接続先IPのAレコード
であると同時に、
HOSTヘッダで伝えられるホスト名
でもあるのです。
ところが、
手で打って覚えるHTTP
ではさっそく、
$ telnet www.google.com 80 Trying 64.233.183.103... Connected to www.google.com (64.233.183.103). Escape character is '^]'. GET / HTTP/1.0 HTTP/1.0 302 Found Location: http://www.google.co.jp/ Cache-Control: private Content-Type: text/html; charset=UTF-8 Set-Cookie: PREF=ID=dcd5652deaacf010:FF=0:TM=1303887216:LM=1303887216:S=cUNIWkuapqmEMcb3; expires=Fri, 26-Apr-2013 06:53:36 GMT; path=/; domain=.google.com Date: Wed, 27 Apr 2011 06:53:36 GMT Server: gws Content-Length: 221 X-XSS-Protection: 1; mode=block <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>302 Moved</TITLE></HEAD><BODY> <H1>302 Moved</H1> The document has moved <A HREF="http://www.google.co.jp/">here</A>. </BODY></HTML> Connection closed by foreign host.
上記は、
GET / HTTP/1.0 (空行)
というのが、
それに対して、
HTTP/1.0 302 Found
というレスポンスが返ってきています。これはかいつまんで言うと、
Locationヘッダを見てみると、
Location: http://www.google.co.jp/
とありますので、
HTTP/1.1での接続(1)
次に、
$ telnet www.google.com 80 Trying 64.233.183.99... Connected to www.google.com (64.233.183.99). Escape character is '^]'. GET / HTTP/1.1 HOST: www.google.com HTTP/1.1 302 Found Location: http://www.google.co.jp/ Cache-Control: private Content-Type: text/html; charset=UTF-8 Set-Cookie: PREF=ID=7eab6b7eed7f7842:FF=0:TM=1303887994:LM=1303887994:S=4XH2bEZxD6t-DcEL; expires=Fri, 26-Apr-2013 07:06:34 GMT; path=/; domain=.google.com Date: Wed, 27 Apr 2011 07:06:34 GMT Server: gws Content-Length: 221 X-XSS-Protection: 1; mode=block <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>302 Moved</TITLE></HEAD><BODY> <H1>302 Moved</H1> The document has moved <A HREF="http://www.google.co.jp/">here</A>. </BODY></HTML>
ほとんど同じ内容になっていますが微妙に違います。
GET / HTTP/1.1 HOST: www.google.com (空行)
が、
レスポンスもほとんど一緒ですが、
ちなみにこういう場合、
telnet>
というプロンプトになるので、
HTTP/1.1での接続(2)
さらに続いて、
$ telnet www.google.com 80 Trying 64.233.183.105... Connected to www.google.com (64.233.183.105). Escape character is '^]'. GET / HTTP/1.1 HOST: www.google.com Connection: close HTTP/1.1 302 Found Location: http://www.google.co.jp/ Cache-Control: private Content-Type: text/html; charset=UTF-8 Set-Cookie: PREF=ID=a967b73bc9b997b2:FF=0:TM=1303888386:LM=1303888386:S=xpUUMjtShIblnhJM; expires=Fri, 26-Apr-2013 07:13:06 GMT; path=/; domain=.google.com Date: Wed, 27 Apr 2011 07:13:06 GMT Server: gws Content-Length: 221 X-XSS-Protection: 1; mode=block Connection: close <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>302 Moved</TITLE></HEAD><BODY> <H1>302 Moved</H1> The document has moved <A HREF="http://www.google.co.jp/">here</A>. </BODY></HTML> Connection closed by foreign host.
今回の例では、
GET / HTTP/1.1 HOST: www.google.com Connection: close (空行)
という内容をリクエストとして送っています。すると、
この例で重要なのは、
今回は非常にざっくりですが、