これは何?
- 分からんぞ?ってなって、調べて、多分こうでは?っていうところまで辿り着いたけど、本当かどうかはまだ分かってない話
何が分からなかったの?
- ウェブサーバにリクエストを投げたとき、レスポンスでHTTPステータスコードが返ってくる(ここまでは分かってるつもり)
- 返ってくるHTTPステータスコードは「
200
みたいな数字だけ」なのか、それとも「200 OK
みたいな数字と文字の両方」なのか?が分からなかった
実際にリクエストを投げてみた
WSL(Ubuntu 18.04.1 LTS)からwww.yahoo.com
$ curl --head https://www.yahoo.com/
HTTP/2 200
date: Fri, 15 Nov 2019 00:54:16 GMT
strict-transport-security: max-age=31536000
server: ATS
cache-control: no-store, no-cache, max-age=0, private
content-type: text/html
content-language: en
expires: -1
content-security-policy: sandbox allow-forms allow-same-origin allow-scripts allow-popups allow-popups-to-escape-sandbox allow-presentation; report-uri https://csp.yahoo.com/beacon/csp?src=ats&site=frontpage®ion=US&lang=en-US&device=desktop&yrid=&partner=;
x-frame-options: SAMEORIGIN
x-xss-protection: 1; report="https://csp.yahoo.com/beacon/csp?src=fp-hpkp-www"
expect-ct: max-age=31536000, report-uri="http://csp.yahoo.com/beacon/csp?src=yahoocom-expect-ct-report-only"
content-length: 12
さくらのVPS(CentOS release 6.10)からwww.yahoo.com
$ curl --head https://www.yahoo.com/
HTTP/1.1 200 OK
Date: Fri, 15 Nov 2019 00:56:22 GMT
Connection: keep-alive
Strict-Transport-Security: max-age=31536000
Server: ATS
Cache-Control: no-store, no-cache, max-age=0, private
Content-Type: text/html
Content-Language: en
Expires: -1
Content-Security-Policy: sandbox allow-forms allow-same-origin allow-scripts allow-popups allow-popups-to-escape-sandbox allow-presentation; report-uri https://csp.yahoo.com/beacon/csp?src=ats&site=frontpage®ion=US&lang=en-US&device=desktop&yrid=&partner=;
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; report="https://csp.yahoo.com/beacon/csp?src=fp-hpkp-www"
Expect-CT: max-age=31536000, report-uri="http://csp.yahoo.com/beacon/csp?src=yahoocom-expect-ct-report-only"
Content-Length: 12
WSL(Ubuntu 18.04.1 LTS)からgoogle.co.jp
$ curl --head https://google.co.jp/
HTTP/2 301
location: https://www.google.co.jp/
content-type: text/html; charset=UTF-8
date: Fri, 15 Nov 2019 01:13:35 GMT
expires: Sun, 15 Dec 2019 01:13:35 GMT
cache-control: public, max-age=2592000
server: gws
content-length: 222
x-xss-protection: 0
x-frame-options: SAMEORIGIN
alt-svc: quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000
HTTP/1.1
で 301 Moved Permanently
が返ってきた
$ curl -I https://google.co.jp/
HTTP/1.1 301 Moved Permanently
Location: https://www.google.co.jp/
Content-Type: text/html; charset=UTF-8
Date: Fri, 15 Nov 2019 01:20:48 GMT
Expires: Sun, 15 Dec 2019 01:20:48 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 222
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Alt-Svc: quic=":443"; ma=2592000; v="46,43",h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000
WSL(Ubuntu 18.04.1 LTS)から7net.omni7.jp
HTTP/1.1
で 301 Moved Permanently
が返ってきた
$ curl --head https://7net.omni7.jp/
HTTP/1.1 301 Moved Permanently
Date: Fri, 15 Nov 2019 01:22:54 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
Vary: User-Agent,Accept-Encoding
X-Content-Type-Options: nosniff
Location: https://7net.omni7.jp/top
Content-Type: text/html; charset=iso-8859-1
Set-Cookie: lb.session.osz=!S/mVG1ZlvAacUoPMACvlP+YcZKUCT6QFwxr6nsi2KijB/22G23HZSZLuaeQFyqGCuYKUjqg58TZTxw==;Path=/;Domain=omni7.jp
さくらのVPS(CentOS release 6.10)から7net.omni7.jp
HTTP/1.1
で 301 Moved Permanently
が返ってきた
$ curl --head https://7net.omni7.jp/
HTTP/1.1 301 Moved Permanently
Date: Fri, 15 Nov 2019 01:12:17 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
Vary: User-Agent,Accept-Encoding
X-Content-Type-Options: nosniff
Location: https://7net.omni7.jp/top
Content-Type: text/html; charset=iso-8859-1
Set-Cookie: lb.session.osz=!jM+NMdGpeetXUnHMACvlP+YcZKUCT/lN+PpuVDXiNJIc+v3UJm4GjwIulP/ofHVwQi+MVSmUXjOfxm0=;Path=/;Domain=omni7.jp
The status-code element is a three-digit integer code giving the result of the attempt to understand and satisfy the request.
(意訳:ステータスコード要素は3桁の整数で、リクエストに対する結果を示してるよ)
The reason phrases listed here are only recommendations. they can be replaced by local equivalents without affecting the protocol.
(意訳:OKとかMoved Permanentlyとかのreason phrasesはあくまで推奨事項なので、同等の何かに置き換えられるよ)
取りあえず辿り着いた結論
- 今回リクエストを投げてみた結果だけ見ると、
HTTP/2
だと「数字だけ」、 HTTP/1.1
だと「数字と文字」が返ってきているように見える
- サーバにリクエストを投げたとき、レスポンスヘッダで何かしらのHTTPステータスコードが返ってくるけど、そのとき
200
や 301
のような「数字のみ」が返ってくるのか、200 OK
や 301 Moved Permanently
のような「数字と文字」が返ってくるのかは、ウェブサーバ(ApacheなのかNginxなのか)や、プロトコル(HTTP/1.1なのかHTTP/2なのか)や、その上のアプリケーションで何を返してるのかに依るっぽい
誰か教えて
HTTP/2
だと「数字だけ」、 HTTP/1.1
だと「数字と文字」が返ってくる、が本当なのか?それとも今回たまたまそういう結果になっただけなのか?
- RFCで推奨しているのはどっちなのか?
追記
blog.magnolia.tech
さらに追記