7 Response (响应)
7 Response (响应)
[H6] 适用, 但将 HTTP-Version 替换为 RTSP-Version。此外, RTSP 定义了额外状态码且未定义部分 HTTP 码。有效响应码及其可与哪些方法联用见表 1。
接收并解释请求消息后, 接收方以 RTSP 响应消息作答。
Response = Status-Line ; Section 7.1
*( general-header ; Section 5
| response-header ; Section 7.1.2
| entity-header ) ; Section 8.1
CRLF
[ message-body ] ; Section 4.3
7.1 Status-Line (状态行)
响应消息的首行为 Status-Line (状态行), 由协议版本, 数字状态码, 以及与状态码关联的文本短语组成, 各元素以 SP 分隔。除最终 CRLF 序列外不得出现 CR 或 LF。
Status-Line = RTSP-Version SP Status-Code SP Reason-Phrase CRLF
7.1.1 Status Code and Reason Phrase (状态码与原因短语)
Status-Code 元素为试图理解并满足请求的三位整数结果码。这些码在第 11 节完整定义。Reason-Phrase 旨在对 Status-Code 给出简短文字描述。Status-Code 供自动机使用, Reason-Phrase 供人类用户。客户端不必检查或显示 Reason-Phrase。
Status-Code 的首位数字定义响应类别。后两位数字无分类作用。首位可取 5 个值:
-
1xx: 信息性 - 请求已收到, 过程继续
-
2xx: 成功 - 动作已被成功接收, 理解并接受
-
3xx: 重定向 - 为完成请求必须采取进一步动作
-
4xx: 客户端错误 - 请求含错误语法或无法满足
-
5xx: 服务器错误 - 服务器未能满足看似有效的请求
以下为 RTSP/1.0 定义的数值状态码的各取值及一组示例 Reason-Phrase。此处所列原因短语仅为建议 - 可用本地等价表述替换而不影响协议。注意 RTSP 采用大部分 HTTP/1.1 [2] 状态码, 并自 x50 起增加 RTSP 专用状态码以免与新定义的 HTTP 状态码冲突。
Status-Code = "100" ; Continue
| "200" ; OK
| "201" ; Created
| "250" ; Low on Storage Space
| "300" ; Multiple Choices
| "301" ; Moved Permanently
| "302" ; Moved Temporarily
| "303" ; See Other
| "304" ; Not Modified
| "305" ; Use Proxy
| "400" ; Bad Request
| "401" ; Unauthorized
| "402" ; Payment Required
| "403" ; Forbidden
| "404" ; Not Found
| "405" ; Method Not Allowed
| "406" ; Not Acceptable
| "407" ; Proxy Authentication Required
| "408" ; Request Time-out
| "410" ; Gone
| "411" ; Length Required
| "412" ; Precondition Failed
| "413" ; Request Entity Too Large
| "414" ; Request-URI Too Large
| "415" ; Unsupported Media Type
| "451" ; Parameter Not Understood
| "452" ; Conference Not Found
| "453" ; Not Enough Bandwidth
| "454" ; Session Not Found
| "455" ; Method Not Valid in This State
| "456" ; Header Field Not Valid for Resource
| "457" ; Invalid Range
| "458" ; Parameter Is Read-Only
| "459" ; Aggregate operation not allowed
| "460" ; Only aggregate operation allowed
| "461" ; Unsupported transport
| "462" ; Destination unreachable
| "500" ; Internal Server Error
| "501" ; Not Implemented
| "502" ; Bad Gateway
| "503" ; Service Unavailable
| "504" ; Gateway Time-out
| "505" ; RTSP Version not supported
| "551" ; Option not supported
| extension-code
extension-code = 3DIGIT
Reason-Phrase = *<TEXT, excluding CR, LF>
RTSP 状态码可扩展。RTSP 应用不必理解所有已注册状态码的含义, 尽管显然希望理解。但是, 应用 MUST 理解任一状态码由首位数字指示的类别, 并将任何无法识别的响应视同该类 x00 状态码, 但无法识别的响应 MUST NOT 被缓存。例如, 若客户端收到无法识别的 431 状态码, 可稳妥假定其请求有问题并将响应视同 400。此类情况下, 用户代理 SHOULD 向用户展示响应所带实体, 因该实体可能含解释异常状态的人类可读信息。
表 1: 状态码及其与 RTSP 方法的联用
| 代码 | 原因短语 | 方法 |
|---|---|---|
| 100 | Continue (继续) | all |
| 200 | OK | all |
| 201 | Created (已创建) | RECORD |
| 250 | Low on Storage Space (存储空间不足) | RECORD |
| 300 | Multiple Choices (多种选择) | all |
| 301 | Moved Permanently (永久移动) | all |
| 302 | Moved Temporarily (临时移动) | all |
| 303 | See Other (参见其他) | all |
| 305 | Use Proxy (使用代理) | all |
| 400 | Bad Request (错误请求) | all |
| 401 | Unauthorized (未授权) | all |
| 402 | Payment Required (需要付费) | all |
| 403 | Forbidden (禁止) | all |
| 404 | Not Found (未找到) | all |
| 405 | Method Not Allowed (方法不允许) | all |
| 406 | Not Acceptable (不可接受) | all |
| 407 | Proxy Authentication Required (需要代理认证) | all |
| 408 | Request Timeout (请求超时) | all |
| 410 | Gone (已不存在) | all |
| 411 | Length Required (需要长度) | all |
| 412 | Precondition Failed (前置条件失败) | DESCRIBE, SETUP |
| 413 | Request Entity Too Large (请求实体过大) | all |
| 414 | Request-URI Too Long (Request-URI 过长) | all |
| 415 | Unsupported Media Type (不支持的媒体类型) | all |
| 451 | Invalid parameter (无效参数) | SETUP |
| 452 | Illegal Conference Identifier (非法会议标识符) | SETUP |
| 453 | Not Enough Bandwidth (带宽不足) | SETUP |
| 454 | Session Not Found (会话未找到) | all |
| 455 | Method Not Valid In This State (此状态下方法无效) | all |
| 456 | Header Field Not Valid (头部字段无效) | all |
| 457 | Invalid Range (无效范围) | PLAY |
| 458 | Parameter Is Read-Only (参数只读) | SET_PARAMETER |
| 459 | Aggregate Operation Not Allowed (不允许聚合操作) | all |
| 460 | Only Aggregate Operation Allowed (仅允许聚合操作) | all |
| 461 | Unsupported Transport (不支持的传输) | all |
| 462 | Destination Unreachable (目的地不可达) | all |
| 500 | Internal Server Error (内部服务器错误) | all |
| 501 | Not Implemented (未实现) | all |
| 502 | Bad Gateway (错误网关) | all |
| 503 | Service Unavailable (服务不可用) | all |
| 504 | Gateway Timeout (网关超时) | all |
| 505 | RTSP Version Not Supported (不支持该 RTSP 版本) | all |
| 551 | Option not support (不支持该选项) | all |
7.1.2 Response Header Fields (响应头部字段)
response-header 字段使请求接收方能够传递无法置于 Status-Line 的关于响应的附加信息。这些字段提供关于服务器以及关于对 Request-URI 所标识资源的进一步访问的信息。
response-header = Location ; Section 12.25
| Proxy-Authenticate ; Section 12.26
| Public ; Section 12.28
| Retry-After ; Section 12.31
| Server ; Section 12.36
| Vary ; Section 12.42
| WWW-Authenticate ; Section 12.44
Response-header 字段名仅在与协议版本变更结合时才能可靠扩展。但是, 若通信各方均将其视为 response-header 字段, 则新的或实验性字段 MAY 被赋予 response-header 字段的语义。无法识别的头部字段按 entity-header 字段处理。