[425] [DFN[[CODE(HTTP)@en[[[Expect:]]]]]] [[ヘッダー]]は、
[[鯖]]の[[応答]]の送信に関する[[クライアント]]の期待を表明する[[要求ヘッダー]]です。

* 仕様書

[REFS[
- [419] '''[CITE@en[RFC 7231 - Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content]] ([TIME[2014-06-07 01:55:45 +09:00]] 版) <https://tools.ietf.org/html/rfc7231#section-5.1.1>'''
- [5] [CITE@en[RFC 7231 - Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content]] ([TIME[2014-08-07 05:54:02 +09:00]] 版) <https://tools.ietf.org/html/rfc7231#page-92>
]REFS]

* 意味

[420] [CODE(HTTP)@en[[[Expect:]]]] [[ヘッダー]]は、
当該[[要求]]を正しく処理するために[[鯖]]が対応する必要がある特定の動作の集合 
([RUBYB[期待]@en[expectation]]) を示すものです [SRC[>>419]]。

* 構文

[421] 値としては、 [CODE(HTTP)@en[[[100-continue]]]] のみが認められています [SRC[>>419]]。
[[大文字・小文字不区別]]です [SRC[>>419]]。

[FIG(railroad)[
- [CODE(HTTP)@en[[[100-continue]]]]
]FIG]

* 文脈

[9] [[HTTP要求]]で指定できます。

[10] 有効に活用されている例はほとんど見られません。

[11] [CODE[Expect:]] に対応しているとわかっている[[HTTPサーバー]]に送信する場合を除き、
使うべきではありません。

* 処理

[422] [CODE(HTTP)[[[100-continue]]]] については、そちらの項を参照してください。

[423] [[鯖]]は、[CODE(HTTP)@en[[[100-continue]]]] 以外を受信した場合、
[CODE(HTTP)[[[417]]]] [[応答]]を返して構いません [SRC[>>419]]。

;; [426] [CODE(HTTP)[[[417]]]] を返すことは義務ではないようです。

* 歴史

** RFC 2616

[1] この欄は [[RFC 2616]] ではじめて導入されました。

[FIG(quote)[
[FIGCAPTION[
[418] RFC 2616 (HTTP/1.1) 14.20 Expect
]FIGCAPTION]

> The Expect request-header field is used to indicate that particular
server behaviors are required by the client.

[CODE(HTTP)[Expect]] 要求頭欄は、クライアントが必要としている特定のサーバーの動作を示すのに使います。

>
- Expect       =  "Expect" ":" 1#expectation
>
- expectation  =  "100-continue" | expectation-extension
- expectation-extension =  token [ "=" ( token | quoted-string ) *expect-params ]
- expect-params =  ";" token [ "=" ( token | quoted-string ) ]

> A server that does not understand or is unable to comply with any of
the expectation values in the Expect field of a request MUST respond
with appropriate error status. The server MUST respond with a 417
(Expectation Failed) status if any of the expectations cannot be met
or, if there are other problems with the request, some other 4xx status.

サーバーは要求中の [CODE(HTTP)[Expect]] 欄の期待値のいずれかが理解できないか又は完了できないなら、
適当な誤り状態で応答しなければ'''なりません'''。
サーバーは、期待のいずれかを満たすことができないなら
[CODE(HTTP)[[[417]]]] (期待失敗) 状態で応答しなければ'''なりません'''。
要求にその他の問題があったなら、他の [CODE(HTTP)[4[VAR[xx]]]]
状態で応答しなければ'''なりません'''。

> This header field is defined with extensible syntax to allow for
future extensions. If a server receives a request containing an
Expect field that includes an expectation-extension that it does not
support, it MUST respond with a 417 (Expectation Failed) status.

この頭欄は将来の拡張のために拡張可能な構文で定義しています。
サーバーが対応していない [CODE(ABNF)[expectation-extension]]
を含む [CODE(HTTP)[Expect]] 欄を含む要求を受け取ったなら、
[CODE(HTTP)[417]] (期待失敗) 状態で応答しなければ'''なりません'''。

> Comparison of expectation values is case-insensitive for unquoted
tokens (including the 100-continue token), and is case-sensitive for
quoted-string expectation-extensions.

期待値の比較は引用符で囲まれていない字句 ([CODE(HTTP)[100-continue]]
字句を含む。) は大文字・小文字を区別せず、
[CODE(ABNF)[[[quoted-string]]]] [CODE(ABNF)[expectation-extensions]]
は大文字・小文字を区別して行います。

> The Expect mechanism is hop-by-hop: that is, an HTTP/1.1 proxy MUST
return a 417 (Expectation Failed) status if it receives a request
with an expectation that it cannot meet. However, the Expect
request-header itself is end-to-end; it MUST be forwarded if the
request is forwarded.

[CODE(HTTP)[Expect]] 機構は hop‐by‐by です。
つまり、 HTTP/1.1 串はその満たすことのできない期待をもつ要求を受け取ったときには
[CODE(HTTP)[417]] (期待失敗) 状態を返さなければ'''なりません'''。
しかし、 [CODE(HTTP)[Expect]] 要求頭自体は末端対末端です。
要求が転送される時に転送されなければ'''なりません'''。

> Many older HTTP/1.0 and HTTP/1.1 applications do not understand the
Expect header.

古い HTTP/1.0 応用や HTTP/1.1 応用の多くは [CODE(HTTP)[Expect]]
頭を理解しません。

> See section 8.2.3 for the use of the 100 (continue) status.
]FIG]

** RFC 7231

[424] [[RFC 2616]] では [CODE(HTTP)[[[100]]]] 
を求める機能と理解必須の拡張を示す一般的な仕組みとの2つの機能を
[CODE(HTTP)@en[[[Expect:]]]] が担っていましたが、
[[クライアント]]も[[鯖]]も拡張機能は実装していないどころか壊れている [SRC[>>5]]
とされ、利用価値がないとして削除して簡略化されました [SRC[>>419]]。

* 関連

[2] 似た欄として [[RTSP]] ([[RFC 2326]]) の [CODE(RTSP)[[[Require]]]], [CODE(RTSP)[[[Proxy-Require]]]] があります。 [WEAK[(HTTP と RTSP の WG が密に連絡取ってれば統一できたんじゃないかなあ。。。)]]

- [3] HTTP/1.1 内にも似た欄として [CODE(HTTP)[[[Upgrade]]]] があります。
- [4] >>3 使い分けは、現在使用中のプロトコルに上乗せする機能を示すのが [CODE(HTTP)[Expect]], 現在のプロトコルの代わりに使うのが [CODE(HTTP)[Upgrade]] でしょうか。

[7] [CODE(HTTP)@en[[[Man:]]]] [[ヘッダー]]もありますが、そちらは機能を直接指定するものではなく、[[名前空間]]により間接的に要求するものとなっています。

[6] 必須でなく希望を伝える[[ヘッダー]]として、新たに
[CODE(HTTP)@en[[[Prefer:]]]] が追加されています。


[427] [CITE@en[draft-goland-http-reliability-00 - SOA-Reliability (SOA-Rity) for HTTP]]
( ([TIME[2014-11-18 19:45:11 +09:00]] 版))
<https://tools.ietf.org/html/draft-goland-http-reliability-00#appendix-A.7>

[FIG(quote)[
[FIGCAPTION[
[8] [CITE[WebRequestのExpectにデフォルトで100-continueがつく件 - 初学者の箸置]]
( ([TIME[2017-07-27 02:35:49 +09:00]]))
<http://d.hatena.ne.jp/tkuro/20110208/1297181393>
]FIGCAPTION]

> .NETにて簡単にHTTP接続するにはWebRequestを使う訳なのですが、これがデフォルトでは強制的に Expect: 100-continueを送るように固定されていて

]FIG]
