`
hideto
  • 浏览: 2678832 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

HTTP1.1 Notes 4, Request & Response & Entity

阅读更多
Request
        Request       = Request-Line             
                        *(( general-header       
                         | request-header        
                         | entity-header ) CRLF) 
                        CRLF
                        [ message-body ]
Request-Line
        Request-Line   = Method SP Request-URI SP HTTP-Version CRLF

An example Request-Line would be:

       GET http://www.w3.org/pub/WWW/TheProject.html HTTP/1.1

The Method token indicates the method to be performed on the resource identified by the Request-URI
The method is case-sensitive

       Method         = "OPTIONS"               
                      | "GET"                   
                      | "HEAD"                  
                      | "POST"                  
                      | "PUT"                   
                      | "DELETE"                
                      | "TRACE"                 
                      | "CONNECT"               
                      | extension-method
       extension-method = token

The methods GET and HEAD MUST be supported by all general-purpose servers. All other methods are OPTIONAL
An origin server SHOULD return the status code 405 (Method Not Allowed) if the method is known by the origin server but not allowed for the requested resource, and 501 (Not Implemented) if the method is unrecognized or not implemented by the origin server

       Request-URI    = "*" | absoluteURI | abs_path | authority

The asterisk "*" means that the request does not apply to a particular resource, but to the server itself, and is only allowed when the method used does not necessarily apply to a resource

The Resource Identified by a Request
The exact resource identified by an Internet request is determined by examining both the Request-URI and the Host header field
1. If Request-URI is an absoluteURI, the host is part of the Request-URI. Any Host header field value in the request MUST be ignored.

2. If the Request-URI is not an absoluteURI, and the request includes a Host header field, the host is determined by the Host header field value.

3. If the host as determined by rule 1 or 2 is not a valid host on the server, the response MUST be a 400 (Bad Request) error message.

Request Header Fields
       request-header = Accept                  
                      | Accept-Charset          
                      | Accept-Encoding         
                      | Accept-Language         
                      | Authorization           
                      | Expect                  
                      | From                    
                      | Host                    
                      | If-Match                

                      | If-Modified-Since       
                      | If-None-Match           
                      | If-Range                
                      | If-Unmodified-Since     
                      | Max-Forwards            
                      | Proxy-Authorization     
                      | Range                   
                      | Referer                 
                      | TE                      
                      | User-Agent          

                      | Range                   
                      | Referer                 
                      | TE                      
                      | User-Agent              
New or experimental header fields MAY be given the semantics of request- header fields if all parties in the communication recognize them to be request-header fields
Unrecognized header fields are treated as entity-header fields

Response
       Response      = Status-Line              
                       *(( general-header       
                        | response-header       
                        | entity-header ) CRLF) 
                       CRLF
                       [ message-body ]

Status-Line
       Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF

The first digit of the Status-Code defines the class of response
There are 5 values for the first digit:
      - 1xx: Informational - Request received, continuing process

      - 2xx: Success - The action was successfully received,
        understood, and accepted

      - 3xx: Redirection - Further action must be taken in order to
        complete the request

      - 4xx: Client Error - The request contains bad syntax or cannot
        be fulfilled

      - 5xx: Server Error - The server failed to fulfill an apparently
        valid request

      Status-Code    =
            "100"  ; Continue
          | "101"  ; Switching Protocols

          | "200"  ; OK
          | "201"  ; Created
          | "202"  ; Accepted
          | "203"  ; Non-Authoritative Information
          | "204"  ; No Content
          | "205"  ; Reset Content
          | "206"  ; Partial Content

          | "300"  ; Multiple Choices
          | "301"  ; Moved Permanently
          | "302"  ; Found
          | "303"  ; See Other
          | "304"  ; Not Modified
          | "305"  ; Use Proxy
          | "307"  ; Temporary Redirect

          | "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
          | "409"  ; Conflict
          | "410"  ; Gone
          | "411"  ; Length Required
          | "412"  ; Precondition Failed
          | "413"  ; Request Entity Too Large
          | "414"  ; Request-URI Too Large
          | "415"  ; Unsupported Media Type
          | "416"  ; Requested range not satisfiable
          | "417"  ; Expectation Failed

          | "500"  ; Internal Server Error
          | "501"  ; Not Implemented
          | "502"  ; Bad Gateway
          | "503"  ; Service Unavailable
          | "504"  ; Gateway Time-out
          | "505"  ; HTTP Version not supported
          | extension-code

      extension-code = 3DIGIT
      Reason-Phrase  = *<TEXT, excluding CR, LF>

pplications MUST understand the class of any status code, as indicated by the first digit, and treat any unrecognized response as being equivalent to the x00 status code of that class, with the exception that an unrecognized response MUST NOT be cached

Response Header Fields
       response-header = Accept-Ranges          
                       | Age                    
                       | ETag                   
                       | Location               
                       | Proxy-Authenticate     
                       | Retry-After            
                       | Server                 
                       | Vary                   
                       | WWW-Authenticate

Entity
Request and Response messages MAY transfer an entity if not otherwise restricted by the request method or response status code
An entity consists of entity-header fields and an entity-body, although some responses will only include the entity-headers

Entity Header Fields
Entity-header fields define metainformation about the entity-body or, if no body is present, about the resource identified by the request

       entity-header  = Allow                   
                      | Content-Encoding        
                      | Content-Language        
                      | Content-Length          
                      | Content-Location        
                      | Content-MD5             
                      | Content-Range           
                      | Content-Type            
                      | Expires                 
                      | Last-Modified           
                      | extension-header

       extension-header = message-header

Entity Body
The entity-body (if any) sent with an HTTP request or response is in a format and encoding defined by the entity-header fields

       entity-body    = *OCTET

An entity-body is only present in a message when a message-body is present
When an entity-body is included with a message, the data type of that body is determined via the header fields Content-Type and Content- Encoding
These define a two-layer, ordered encoding model:

       entity-body := Content-Encoding( Content-Type( data ) )

Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body
If and only if the media type is not given by a Content-Type field, the recipient MAY attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource
If the media type remains unknown, the recipient SHOULD treat it as type "application/octet-stream"

The entity-length of a message is the length of the message-body before any transfer-codings have been applied

Examples
D:\projects\maui>curl -I www.g.cn
HTTP/1.1 301 Moved Permanently
Location: http://www.google.cn/webhp?source=g_cn
Content-Type: text/html; charset=UTF-8
Date: Fri, 26 Dec 2008 05:07:21 GMT
Expires: Sun, 25 Jan 2009 05:07:20 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 0

D:\projects\maui>curl -I www.google.cn
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Date: Fri, 26 Dec 2008 05:07:28 GMT
Expires: -1
Content-Type: text/html; charset=GB2312
Set-Cookie: PREF=ID=fc9dd9293e07dfbd:NW=1:TM=1230268048:LM=1230268048:S=GSJ0ovAC
pSDvYdtq; expires=Sun, 26-Dec-2010 05:07:28 GMT; path=/; domain=.google.cn
Server: gws
Content-Length: 0

D:\projects\maui>curl -I 192.168.0.5
HTTP/1.1 302 Found
Content-Type: text/html; charset=utf-8
Set-Cookie: _freewheel_session_id=6f190d42bf361e23336c7b646a565c2d; path=/; Http
Only
Location: http://192.168.0.5/system/account/login
Cache-Control: no-cache
Content-Length: 105
Date: Fri, 26 Dec 2008 05:27:16 GMT
Server: lighttpd/1.4.19
分享到:
评论

相关推荐

    java-servlet-api.doc

    你可以从http://info.internet.isi.edu/7c/in-notes/rfc/.cache找到下面提到的所有这些RFC规范。 RFC1738统一资源定位器(URL) RFC1808相关统一资源定位器 RFC1945超文本传输协议--HTTP/1.0 RFC2045多用途Internet...

    为Java MVC框架集成Swagger生成Api文档的工具

    public ResponseEntity createUser(@RequestBody User user) { // 创建用户并返回响应 } } ``` 4. **访问Swagger UI**:启动项目后,可以通过浏览器访问`http://localhost:8080/swagger-ui.html`来查看和测试生成...

    swagger接口设计.docx

    public ResponseEntity createUser(@RequestBody @ApiParam("User details") User user) { // 方法实现 } } ``` 上述例子中,`@Api`注解描述了整个`UserController`,而`@ApiOperation`和`@ApiParam`则分别...

    springboot +swagger2 小例子

    public ResponseEntity&lt;String&gt; createUser(@RequestBody @Valid User user) { // 创建用户的逻辑... return ResponseEntity.ok("用户创建成功"); } } ``` 当上述代码配置完成后,运行SpringBoot应用,然后访问...

    课程表.txt

    - `ResponseEntity[][]&gt;&gt;`: 表示响应实体的类型,包含了封装好的数据和HTTP状态码。 - `PersonalResource[][]&gt;`: 一个自定义的数据结构,用来封装返回的数据。 - `String[][]`: 二维字符串数组,代表一周七天每天十...

    springboot集成swagger

    public ResponseEntity&lt;User&gt; createUser(@RequestBody User user) { // 实现业务逻辑 } } ``` `@ApiOperation`注解用于描述接口的主要功能,`@ApiParam`、`@ApiModel`、`@ApiModelProperty`等注解可以帮助我们...

    swagger返回数据注解.zip

    public ResponseEntity createUser(@RequestBody User user) { ... } ``` 5. `@ApiModel` 和 `@ApiModelProperty`:用于定义数据模型及其属性。`@ApiModel` 标记一个类,描述整个模型,而 `@ApiModelProperty` ...

    springboot-swagger2.rar

    public ResponseEntity&lt;User&gt; createUser(@RequestBody @Valid User user) { // 接口实现代码 } } ``` 4. **运行和访问Swagger UI** 完成以上步骤后,启动SpringBoot应用。Swagger UI默认会在`...

    swagger+springboot配置

    public ResponseEntity&lt;String&gt; protectedApi() { // 处理业务逻辑 } ``` 通过这种方式,Swagger不仅会生成API文档,还会展示需要认证的信息。用户在Swagger-UI中测试这些API时,需要在`Authorization`字段输入...

    spring3集成swagger的jar包

    public ResponseEntity&lt;List&lt;User&gt;&gt; getUsers() { // ... } } ``` 3. **配置Swagger UI**:Swagger UI是一个Web界面,用于展示和测试你的API。你可以通过在Spring配置中添加一个静态资源处理器来提供这个界面。 ...

    Elastic_Search_CRUD_Swagger

    public ResponseEntity&lt;String&gt; createDocument(@RequestBody Map, Object&gt; doc) { // Call Elasticsearch client to create the document } // Similar annotations for Read, Update and Delete methods } ``...

    spring_boot_swagger

    public ResponseEntity createUser(@RequestBody @ApiParam("用户信息") User user) { // 实现创建用户的逻辑 } } ``` 通过这些注解,Swagger可以自动收集到API的元数据,并生成清晰易懂的文档。 Swagger UI是...

    Spring boot集成swagger2生成接口文档的全过程

    public ResponseEntity&lt;User&gt; createUser(@RequestBody User user) { // 创建用户的逻辑 } } ``` 4. 完成上述步骤后,运行Spring Boot应用,Swagger的Web界面可以通过访问`...

    spring-framework-reference4.1.4

    Using SLF4J ............................................................................................ 13 Using Log4J ...................................................................................

    spring-framework-reference-4.1.2

    Using SLF4J ............................................................................................ 13 Using Log4J ...................................................................................

Global site tag (gtag.js) - Google Analytics