Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. HTTP
  3. Reference
  4. Headers
  5. Upgrade

Upgrade header

The HTTPUpgraderequest andresponse header can be used to upgrade an already-established client/server connection to a different protocol (over the same transport protocol).For example, it can be used by a client to upgrade a connection from HTTP/1.1 to HTTP/2, or an HTTP(S) connection to a WebSocket connection.

Warning:HTTP/2 explicitly disallows the use of this mechanism and header; it is specific to HTTP/1.1.

Header typeRequest header,Response header
Forbidden request headerYes

Syntax

http
Upgrade: <protocol>[/<protocol_version>]Upgrade: <protocol>[/<protocol_version>], …, <protocolN>[/<protocol_versionN>]

Directives

<protocol>

Protocols are listed, comma-separated, in order of descending preference.

<protocol_version>Optional

An optional protocol version may be provided prefixed with a/ forward slash.

Description

TheUpgrade header field may be used by clients to invite a server to switch to one (or more) of the listed protocols, in descending preference order.For example, the client might send aGET request as shown, listing the preferred protocols to switch to (in this caseexample/1 andfoo/2):

http
GET /index.html HTTP/1.1Host: www.example.comConnection: upgradeUpgrade: example/1, foo/2

Note:TheConnection header with typeupgrade mustalways be sent with theUpgrade header.

The server can ignore the request, for any reason, in which case it should respond as though theUpgrade header had not been sent (for example, with a200 OK).If the server will upgrade the connection, it must:

  1. Send back a101 Switching Protocols response status with anUpgrade header that specifies the protocol(s) being switched to. For example:

    http
    HTTP/1.1 101 Switching ProtocolsUpgrade: foo/2Connection: Upgrade
  2. Send a response to the original requestusing the new protocol (the server may only switch to a protocol with which it can complete the original request).

A server may also send the header as part of a426Upgrade Required response, to indicate that the server won't perform the request using the current protocol, but might do so if the protocol is changed. The client can then request a protocol change using the process above.

More detail and examples are provided in the topicProtocol upgrade mechanism.

Examples

Upgrade header with multiple protocols

The following request lists multiple protocols in descending preference:

http
Connection: upgradeUpgrade: HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11

Upgrading to WebSocket

This is a common combination of headers to use to begin upgrading a HTTP connection to WebSockets.SeeUpgrading to a WebSocket connection for more information.

http
Connection: UpgradeUpgrade: websocket

Specifications

Specification
HTTP Semantics
# field.upgrade
HTTP Semantics
# status.426
HTTP/2
# informational-responses

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp