LoginSignup
3
0

More than 1 year has passed since last update.

HTTPのバージョンによるリクエストの形式比較

Posted at

はじめに

HTTPのバージョンによるリクエストの形式比較を行う。

HTTP0.9

登場時には、HTTPと呼ばれており、後ほど、他のバージョンと区別するためにHTTP0.9と呼ばれるようになった。
curlコマンドはHTTP1.0以降の対応なので使用できない。netcatコマンドを使う。
curlコマンドは使用できないというより、0.9の仕様上使用する必要がないのかもしれない。

  • GETリクエストのみ存在する
  • HTTPヘッダはない
  • HTTPステータスコードはない
  • 応答は原則HTMLのみ

検証方法

リクエストとレスポンスは以下の場合、HTTP/0.9を使用していると言えるそうだ。

$ echo -e "GET /\r\n" | nc hogehoge.hoge 80
<html><body><h1>Yatta!</h1></body></html>

参考:

実行結果

クライアント
% echo -e "GET /\r\n" | nc localhost 8080 -v
Connection to localhost port 8080 [tcp/http-alt] succeeded!
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>hello</title></head><body>Hello World</body></html>

HTTP/1.0

HTTP/1.0以降は、curlコマンドのオプションでhttpのバージョンを指定して検証する。

※レスポンスは自作したサーバーを使用しているため、考慮もれあり

クライアント
% curl http://127.0.0.1:8080 -v --http1.0
*   Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.0
> Host: 127.0.0.1:8080
> User-Agent: curl/7.79.1
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
* no chunk, no close, no size. Assume close to signal end
< 
* Closing connection 0
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>hello</title></head><body>Hello World</body></html>

HTTP/1.1

HTTP/1.0との差はなさそう。

※レスポンスは自作したサーバーを使用しているため、考慮もれあり

クライアント
% curl http://127.0.0.1:8080 -v --http1.1
*   Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.79.1
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
* no chunk, no close, no size. Assume close to signal end
< 
* Closing connection 0
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>hello</title></head><body>Hello World</body></html>

HTTP/2.0

HTTP1.1と比較して、以下が追加されている。

Connection: Upgrade, HTTP2-Settings
Upgrade: h2c
HTTP2-Settings: AAMAAABkAAQCAAAAAAIAAAAA

※レスポンスは自作したサーバーを使用しているため、考慮もれあり

curl http://127.0.0.1:8080 -v --http2  
*   Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.79.1
> Accept: */*
> Connection: Upgrade, HTTP2-Settings
> Upgrade: h2c
> HTTP2-Settings: AAMAAABkAAQCAAAAAAIAAAAA
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
* no chunk, no close, no size. Assume close to signal end
< 
* Closing connection 0
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>hello</title></head><body>Hello World</body></html>%

HTTP3.0

TODO:

おわりに

HTTPのバージョンによるリクエストの形式を実際にコマンドを送り、比較した。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0