HTTP Protocol Diagram--http response status Code (key analysis)

Source: Internet
Author: User
Tags http authentication

1. Status Code Overview
    • The HTTP status code is responsible for the return result of the client HTTP request, the marking of the server-side processing is normal, the notification error, and so on.
    • HTTP status codes, such as 200 OK 3-digit and reason phrases. The first digit in the number specifies the response category, and the latter two bits are not categorized.
    • Many of the returned response status codes are wrong, but the user may not be aware of this. For example, there is an error inside the WEB application and the status code returns 200 OK .
2. Status Code category
category reason phrases
1xx Informational (Informational status code) The received request is being processed
2xx Success (Success status code) Request normal processing complete
3xx Redirection (Redirected status code) Additional action required to complete the request
4xx Client error (Customer fault status code) The server cannot process the request
5xx Server error (incorrect status code) Server Processing Request Error

We can change the status code defined in the RFC2616 or the server side to create the status code, as long as the status code to comply with the category definition.

3. Common Status Code parsing

HTTP status code has a wide variety of dozens of kinds. One of the most commonly used are the following 14 kinds, one to see.

3.1 OK

Indicates that a request from the client is handled properly on the server side.

3.2 204 No Content
    • Requests received on behalf of the server have been processed successfully, but the body portion of the entity is not included in the returned response message. Also, it is not allowed to return the body of any entity.
    • Typically, you only need to send messages from the client to the server, and the server side does not have to send new message content to the client.
3.3 206 Partial Content

Indicates that the client made a scope request, and the server successfully performed this part of the GET request. The response message contains the entity content specified by the Content-range header field.

3.4 301 Moved Permanently

Permanent redirection. Indicates that the requested resource has been assigned a new URI. The URI that the resource now refers to should be used later. That is, if the URI of the resource is already saved as a bookmark, it should be re-saved by the URI of the Location header field prompt.

3.5 302 Found
    • Temporary redirection. Indicates that the requested resource has been assigned a new URI and that the user (this time) will be able to access it using the new URI.
    • 301 Moved PermanentlyIt is similar to the status code, but 302 Found the status code indicates that the resource is not permanently moved but is temporary in nature. In other words, the URI corresponding to the moved resource may change in the future.
3.6 303 See other
    • Indicates that the requested resource should be obtained by using the Get method, because another URI exists for the requesting resource.
    • 303 See OtheR and 302 Found status code have the same function, but the 303 See Other status code clearly indicates that the client should use the Get method to obtain resources, which 302 Found is different from the status code.
3.7 304 Not Modified
    • Indicates that the server side allows requests for access to resources, but does not satisfy the condition when the client sends a request with a condition.
    • 304 Not ModifiedWhen the status code returns, it does not contain any body parts of the response.
    • 304 Not ModifiedAlthough it is divided into the 3xx category, it is not related to redirection.
3.8 307 Temporary Redirect

Temporary redirection. The status code 302 Found has the same meaning.

3.9 Bad Request
    • Indicates that there is a syntax error in the request message. When the error occurs, you need to modify the requested content and send the request again.
    • In addition, the browser 200 OK treats the status code as if it were.
3.10 401 Unauthorized
    • Indicates that a request to be sent requires authentication information via HTTP authentication (BASIC authentication, DIGEST authentication).
    • In addition, if 1 requests have been made before, the user authentication fails.
    • The return contains a 401 Unauthorized response that must contain a www-authenticate header for the requested resource to challenge (Challenge) the user information.
3.11 403 Forbidden

Indicates that access to the requested resource was rejected by the server. The server side does not need to give a detailed reason for refusal, of course, can also be described in the entity body of the response message part of the reason.

3.12 404 Not Found

Indicates that the requested resource could not be found on the server. In addition, it can be used when the server denies the request and does not want to justify it.

3.13 Internal Server Error

Indicates that a server-side error occurred while executing the request. It can also be a bug or some temporary failure in the Web app.

3.14 503 Service unavailable

Indicates that the server is temporarily over-loaded or is undergoing downtime maintenance and cannot process requests now. It is best to write the Retry-after header field and return it to the client if you know beforehand how long it takes to release the above situation.

viii. HTTP Message Entities1. HTTP Message Entity Overview HTTP Message Structure

Please take a closer look at the contents of each component in the example above.
Next, let's look at the concept of reading paper and entities. If an HTTP message is imagined as a box in an Internet freight system, the HTTP entity is the actual cargo in the message.

    • Message: is a data unit that is exchanged and transmitted in the network, that is, a data block to be sent by the site once. The message contains the complete data information to be sent, the length of which is inconsistent, unlimited and variable.
    • Entity: The payload data (supplementary item) as a request or response is transmitted, and its contents consist of the entity header and the entity body. (The entity header related content is described in the 6th above.) )

As we can see, the contents of the Deep red box in the image on the right of the above example is the entity part of the message, and the two parts of the blue box are the entity header and the entity body respectively. The content of the pink box in the left image is the message body.
Typically, the message body equals the entity body. The content of the entity body is changed only when it is encoded in the transmission, which causes it to differ from the message body.

2. Content Encoding
    • HTTP applications sometimes need to encode content before they are sent. For example, a server might compress a large HTML document before it is sent to a client over a slow connection, which can help reduce the time it takes to transfer the entity. The server can also scramble or encrypt the content to prevent unauthorized third parties from seeing the contents of the document.
    • This type of encoding is applied to the content on the sender side. When content is encoded, the coded data is placed in the entity body and sent to the receiving party as usual.

content encoding Type:

encoding description
gz IP Indicates that the entity is using the GNU zip code
Span style= "FONT-SIZE:18PX; Font-family: Italic ">compress Indicates that the entity is using Unix's file compression program
deflate Indicates that the entity is compressed in zlib format
ident ity Indicates that the entity is not encoded and, when there is no content-encoding header field, This encoding is used by default
3. Transfer Code

Content encoding is a reversible transformation of the main body of a message, and is closely related to the specific format details of the content.
Transfer encodings are also reversible transformations that act on entity bodies, but they are used for architectural reasons, regardless of the format of the content. The transfer encoding is used to change the way in which the data in the message is transmitted over the network.

 Comparison of content encoding and transmission encoding4. chunked Coding

The chunked code divides the message into chunks of known size. The blocks are sent next to each other, so that you do not need to know the size of the entire message before sending it. Block coding is a transmission encoding, which is the attribute of a message.

chunked Encoding and persistent connection
If the client is not a persistent connection to the server, the client does not need to know the length of the principal it is reading, but only needs to read to the server to close the principal connection.
When using a persistent connection, you must know its size and send it in the Content-length header before the server writes the principal. If the server dynamically creates content, it may not be able to know the length of the principal before it is sent.
chunked Coding provides a solution to this difficulty, as long as the server is allowed to send the main block, indicating the size of each block is possible. Because the principal is created dynamically, the server can buffer its part, send its size and the corresponding block, and then repeat the process before the body sends it out. The server can use a block of size 0 as a signal to end the body so that it can continue to stay connected and prepare for the next response.
Take a look at an example of a chunked encoded message:

 chunked encoded Messages

5. Multi-part media type

The multipart (multipart) e-mail message in MIME contains multiple messages, which together are sent as a single, complex message. Each part is independent and has its own set of content that describes it, and the different parts are concatenated with a delimited string.
Accordingly, the HTTP protocol also incorporates a collection of multipart objects, which can contain multiple types of entities within the body of a message being sent.
The multi-part object collection contains the following objects:

    • Multipart/form-data: Used when uploading Web forms files.
    • Multipart/byteranges: The Status Code 206 Partial Content response message contains multiple ranges of content when used.
6. Scope Request

Suppose you are downloading a very large file, already under Three-fourths, suddenly the network is interrupted, the download must start over again. To solve this problem, a recoverable mechanism is needed to resume the download from the previous download outage. To implement this feature, you need to use the scope request.
With a scope request, the HTTP client can resume downloading the entity by requesting a range (or part of it) of the entity that failed. There is, of course, a premise that the object has not changed since the last time the client requested the entity to this request for a range. For example:

GET  /bigfile.html  HTTP/1.1Host: www.sample.comRange: bytes=20224-···
 Entity Scope Request Example

In the example above, the client requested the section after the beginning of the 20224 bytes of the document.

ix. WEB Server with HTTP collaboration

HTTP Communication, in addition to the client and the server, there are some applications to assist communication. The following are some of the more important: proxies, caches, gateways, tunnels, agent agents .

1. Agent Agent

HTTP proxy servers are an important component of WEB security, application integration, and performance optimization. The agent sits between the client and the server, receives all HTTP requests from the client, and forwards the requests to the server (which may be modified before forwarding). For users, these applications are a proxy that accesses the server on behalf of the user.
For security reasons, agents are typically used as trusted intermediary nodes that forward all WEB traffic. Agents can also filter requests and responses, secure Internet access or green Internet access.

2. Caching

Browser Request for the first time:

 Browser Request for the first time

The browser requests again:

 Browser Request again

Web cache or proxy caching is a special kind of HTTP proxy server that can be used to save a copy of a common document that has been transferred by proxy. The next client requesting the same document will be able to enjoy the services provided by the cached private copy. It is much faster for clients to download documents from nearby caches than from remote Web servers.

3. Gateways HTTP/FTP Gateway

A gateway is a special server that is used as an intermediary entity for other servers. Typically used to convert HTTP traffic to other protocols. The gateway receives the request as if it were the source server for the resource. The client may not know that he is communicating with a gateway.

4. Tunnels Http/ssl Tunnel

A tunnel is an HTTP application that will blindly forward the original data between two connections after it is established. HTTP tunneling is typically used to forward non-HTTP data on one or more HTTP connections and does not spy on the data when it is forwarded.
A common use of HTTP tunneling is to host encrypted Secure Sockets Layer (SSL) traffic over an HTTP connection so that SSL traffic passes through firewalls that allow only WEB traffic.

5. Agent Agents automatic search Engine "web Spider"

An agent agent is a client application that initiates an HTTP request on behalf of a user. All applications that publish WEB requests are HTTP agent agents.

HTTP Protocol Diagram--http response status Code (key analysis)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.