HTTP の基本
informationnetworksundergraduatelecture
data/lecture/information/networks/dns-basics.lecture.n.md
1導入
この講義では、クライアントが資源に対する要求を送信し、サーバが処理結果を応答するためのHTTPの意味論を説明する。HTTP の要求と応答を、IP によるパケット転送やトランスポート層の機能と区別する。
2資源と表現
資源とは、HTTP による操作の対象であり、URIによって識別される。Web ページ、画像、API が管理するデータなどを資源として扱える。
表現とは、ある時点における資源の状態を表現するデータである。同一の資源が、HTML、JSON、画像形式などの異なる表現を提供することもある。この講義では、資源へのアクセスに用いるURIをURLと呼ぶ。
HTTP では、クライアントが要求を送信し、サーバがその要求を処理して応答を返送する。この役割は個々の交換に対して定まり、ブラウザに限定されない。
3要求と応答の意味論
HTTP 要求は、概念的に次の要素から構成される。
- メソッド: 資源に対して要求する意味を指定する。
- 要求対象: 操作の対象を指定する。
- フィールド: 表現形式、認証、キャッシュなどに関するメタデータを伝達する。
- 内容: 必要な場合に、処理対象となる表現を伝達する。
HTTP 応答は、要求の処理結果を分類する状態コード、フィールド、および必要に応じた内容から構成される。状態コードはサーバ自体の状態ではなく、その要求に対する処理結果を表す。
4HTTP/1.1 のメッセージ例
HTTP/1.1 は、開始行とフィールドをテキスト形式で表現する。たとえば、次の要求行は /index.html を要求対象とする GET 要求である。
GET /index.html HTTP/1.1
Host: example.com
Accept: text/html
応答の開始行には、HTTP のバージョン、状態コード、理由句が含まれる。
HTTP/1.1 200 OK
Content-Type: text/html
このテキスト形式は HTTP/1.1 の表現方法である。HTTP/2 と HTTP/3 は要求行を使用せず、HTTP の意味をバイナリフレームで符号化する。
5メソッドの性質
GETは、要求対象となる資源について、選択された現在の表現の転送を要求する。GET は安全なメソッドとして定義され、クライアントはサーバの状態変更を要求しない。また、同一の GET を複数回実行しても、意図されるサーバ上の効果は一回の実行と同じである。この性質を冪等という。ただし、アクセスログの記録などの付随的な変化は許容される。
POSTは、要求に含まれる表現を、要求対象となる資源に固有の意味で処理するよう要求する。フォームの送信、新たな資源の生成、処理の起動などに利用され得るため、POST を単なるファイル送信と定義することはできない。POST は一般に安全でも冪等でもない。
6状態コード
状態コードの先頭桁は、処理結果を次のように分類する。
1xx: 情報応答
2xx: 成功
3xx: リダイレクション
4xx: クライアントエラー
5xx: サーバエラー
200 OK は要求が成功したことを表す。404 Not Found は、サーバが要求対象の現在の表現を発見できない、またはその存在を開示しないことを表す。したがって、404 だけから資源が永久に存在しないとは断定できない。
7HTTPS と TLS
HTTPSは、TLSの機能によって保護されたHTTP通信を表す。HTTP/1.1とHTTP/2ではTLSをTCP上で使用し、HTTP/3ではTLSの暗号機能とハンドシェイクがQUICへ統合される。TLSは通信内容の機密性と完全性を保護し、証明書の検証を通じて通常はサーバを認証する。HTTPSはHTTPの要求・応答の意味を変更しない。また、TLSによる認証は、サーバが提供する情報内容の正確性まで保証するものではない。
8HTTP のバージョンと転送方式
| バージョン | 主な下位転送 | HTTP メッセージの表現 |
| HTTP/1.1 | TCP | テキスト形式の開始行とフィールド |
| HTTP/2 | TCP | バイナリフレーム、多重化 |
| HTTP/3 | UDP 上の QUIC | バイナリフレーム、QUIC ストリームによる多重化 |
資源、メソッド、状態コードなどの HTTP の意味論は、これらのバージョンで概ね共通する。一方、符号化と下位の転送方式は異なる。したがって、HTTP が常に TCP を利用するとは限らない。
9DNS および下位層との関係
URL にドメイン名が含まれる典型的な Web アクセスでは、クライアントは DNS による名前解決の後、選択した IP アドレスへ接続し、HTTP の要求を送信する。ただし、DNS は HTTP の意味論の一部ではなく、キャッシュされた結果や IP アドレスを直接使用する場合もある。
IP はパケットを宛先へ転送し、TCP または QUIC は HTTP メッセージを運搬するための機能を提供する。HTTP は、その上で資源に対する要求と応答の意味を規定する。
10要点
- HTTP は、URI で識別される資源に対する要求と応答の意味論を規定する。
- メソッドは要求の意味を、状態コードは処理結果の分類を表す。
- HTTPS は HTTP を TLS で保護する。HTTP/1.1 と HTTP/2 は通常 TCP を、HTTP/3 は QUIC を利用する。
11次に進む講義
data/lecture/information/database/database-portal.lecture.n.md
HTTP Fundamentals
data/lecture/information/networks/dns-basics.lecture.n.md
1Introduction
This lecture explains the semantics of HTTP, through which a client sends a request concerning a resource and a server responds with the result of processing that request. It distinguishes HTTP requests and responses from IP packet forwarding and transport-layer functions.
2Resources and Representations
A resource is a target of HTTP operations and is identified by a URI. Web pages, images, and data managed by an API can all be treated as resources.
A representation is data that represents the state of a resource at a particular time. A single resource can provide representations in HTML, JSON, image formats, or other forms. In this lecture, a URI used to access a resource is called a URL.
In HTTP, a client sends a request, and a server processes that request and returns a response. These roles are defined for each exchange and are not limited to web browsers.
3Request and Response Semantics
Conceptually, an HTTP request contains the following elements:
- a method, which specifies the requested semantics for the resource;
- a request target, which identifies the target of the operation;
- fields, which convey metadata concerning representation formats, authentication, caching, and other matters; and
- optional content, which conveys a representation to be processed when required.
An HTTP response contains a status code that classifies the result of processing the request, fields, and optional content. A status code describes the result for that request, not the state of the server itself.
4An HTTP/1.1 Message Example
HTTP/1.1 represents the start line and fields as text. The following request line is a GET request whose request target is /index.html.
GET /index.html HTTP/1.1
Host: example.com
Accept: text/html
The response start line contains the HTTP version, status code, and reason phrase.
HTTP/1.1 200 OK
Content-Type: text/html
This textual format is an HTTP/1.1 representation. HTTP/2 and HTTP/3 do not use request lines; they encode HTTP semantics in binary frames.
5Method Properties
GET requests transfer of a current selected representation for the target resource. GET is defined as a safe method: the client does not request a change to server state. GET is also idempotent: the intended effect on the server of several identical GET requests is the same as the effect of one such request. Incidental effects such as access logging remain permissible.
POST requests that the target resource process the enclosed representation according to its resource-specific semantics. It can submit a form, create a resource, or initiate a process, so POST cannot be defined merely as file transmission. POST is generally neither safe nor idempotent.
6Status Codes
The first digit of a status code classifies the processing result as follows:
1xx: informational responses;
2xx: successful responses;
3xx: redirection messages;
4xx: client errors; and
5xx: server errors.
200 OK indicates that the request succeeded. 404 Not Found indicates that the server cannot find a current representation for the target resource or is unwilling to disclose that one exists. A 404 response alone therefore does not prove that the resource will never exist.
7HTTPS and TLS
HTTPS denotes HTTP communication protected by TLS functions. HTTP/1.1 and HTTP/2 use TLS over TCP, while HTTP/3 integrates the TLS handshake and cryptographic functions into QUIC. TLS protects the confidentiality and integrity of communication and normally authenticates the server through certificate validation. HTTPS does not change HTTP request and response semantics. Authentication by TLS also does not guarantee the factual correctness of information supplied by the server.
8HTTP Versions and Transport
| Version | Primary underlying transport | HTTP message representation |
| HTTP/1.1 | TCP | Textual start lines and fields |
| HTTP/2 | TCP | Binary frames and multiplexing |
| HTTP/3 | QUIC over UDP | Binary frames and multiplexing over QUIC streams |
HTTP semantics such as resources, methods, and status codes are largely common across these versions. Their encodings and underlying transports differ, however. HTTP does not therefore always use TCP.
9Relationship to DNS and Lower Layers
In a typical web access whose URL contains a domain name, a client resolves the name through DNS, connects to a selected IP address, and sends an HTTP request. DNS is not part of HTTP semantics, however, and a client may instead use a cached result or an IP address directly.
IP forwards packets toward their destination. TCP or QUIC provides functions that carry HTTP messages. Above them, HTTP defines the semantics of requests and responses concerning resources.
10Key Points
- HTTP defines request and response semantics for resources identified by URIs.
- A method specifies request semantics, while a status code classifies the processing result.
- HTTPS protects HTTP with TLS. HTTP/1.1 and HTTP/2 normally use TCP, whereas HTTP/3 uses QUIC.
11Next Lecture
data/lecture/information/database/database-portal.lecture.n.md