Introduction:
The HTTP(Hyper Text Transfer Protocol) Hypertext Transfer Protocol is the protocol for the World Wide Web application layer, using connection-oriented TCP as the Transport layer protocol.
Features:
- Simple and fast: through the URL can access resources, the protocol is simple, so that the HTTP Server program size small, fast communication.
- Flexible: HTTP allows any type of data object to be transmitted . The type being transmitted is marked by Content-type .
- No connection: Each time the connection responds to a request, the connection is disconnected once the response is connected.
- Stateless: Stateless protocol, which means that there is no memory capability for transaction processing, and it does not remember the state that the customer has visited and cannot distinguish the access identity.
How HTTP Works:
The HTTP protocol defines How Web clients request Web pages from a Web server , and how the server puts web The page is routed to the client. the HTTP protocol uses the request / response model. The client sends a request message to the server that contains the requested method,URL, protocol version, request header, and request data. The server responds with a status line that includes the version of the Protocol, the success or error code, the server information, the response header, and the response data.
in the browser address bar, type URL, you will experience the following process after you press ENTER:
- the browser requests the server to resolve the The IP address that corresponds to the domain name in the URL
- Browser through IP address and default listening Port, establish TCP connection with server
- The browser sends the request message as third message data for TCP third handshake sent to server
- The server locates the requested resource, responds to the client,
- if the connection mode is close, the server actively shuts down the TCP connection, the client shuts down the connection passively, releases the TCP connection ; if Connection mode is keepalive , the connection is maintained for a period of time and can continue to receive requests (that is, persistent connections) ;
- The client browser first parses the status line, the response header, and then reads the response data HTML, and is displayed in the browser window.
URL:
< protocol >://< host >:< port (default can be omitted) >/< Path >
URLs are distinguished from URIs :
URL Uniform Resource Locator,URI Uniform Resource Identifier,URL It is a specific URI, the URL can be used to identify a resource, which is a subset of the URI, that is, the url belongs to the URI.
HTTP Message composition:
Request message: Request line, request header, blank line, request body
Response message: Status line, response header, blank line, response body
Request Method :
Get: Get resources
POST : Transferring Resources
HEAD : Get message header
Delete : Deleting a resource
PUT: Updating resources
HTTP1.0 defines three methods of request: GET, POST, and HEAD .
HTTP1.1 has five new request methods:options, PUT, DELETE, TRACE , and CONNECT methods.
Post/get Method Differences:
Get is less secure than Post method, Parameter burst on URL , cannot be used to pass sensitive information ;
Get in the URL can be passed the length of the parameters is limited,thePost method can pass the length of the parameter is not limited ;
The Get parameter is passed on the URL andthePost is placed in the request body ;
The GET request parameters are kept intact in the browser history, and thePost parameters are not retained;
Browser fallback, the Get request is not repeated, and thePost request repeats the submission;
the Get request browser is automatically cached and thePost request is not automatically cached.
Response Line Status code:
1**: Indication Information
2**: Successful 200:ok 206:p artial content ( request a get request with range Header )
3**: redirect 301: The requested page is transferred to a new URL, permanent redirect 302: Temporary redirect 304: Content not modified
4**: Client side error :Client syntax error 403: Requested page access Forbidden 404: Resource not found
5**: Server error 503: Server is overloaded or is a machine.
Status code, request header, response header data Reprint connection:
Http://www.51testing.com/html/38/225738-216202.html
Persistent Connection (continuous connection)
The http1.1 version begins with support for persistent connections, which are keep-alive connections, wherehttp is "request - Answer mode, each time a request is made, a connection is made, and then disconnected after completion, i.e. no connection status. A persistent connection (persistent connection), which remains connected after the response is completed, can continue to transmit http Request messages and response messages on this connection.
Pipeline:
In the case of a persistent connection, the delivery of a message on a connection is similar to the following:
Request 1 ==> response 1 ==> request 2 ==> response 2 ==> request 3 ==> Response 3
A message on a connection becomes:
request 1 ==> request 2 ==> request 3 ==> response 1 ==> response 2 ==> response 3
Features: Complete with persistent connection, only http1.1 support; get,HEAD requests can be pipelined,post restrictions, the first time you create a connection should not start the pipeline, because the server does not necessarily support, pipeline will not affect the order of response, the service side support pipeline, does not require the service side also to the pipeline processing. Because the end pipeline does not bring significant performance improvement, modern browser chrome,firefox does not open pipeline.
Http/https Differences:
Httpsis inhttpunder JoinSSLlayer for secure encryption. httpthe standard port is the, whileHTTPSthe standard port is443.
Cache-Related headers:
Expires:
validity period, expiration time, this property tells the cache: how long the relevant copy is fresh. After this time, the cache sends a request to the source server to check if the document has been modified. Almost all cache servers support the Expires(Expiration Time) attribute.
Cache-control:
This field is used to specify the instructions that all caching mechanisms must obey in the entire request / response chain. Used to block caching of behavior that adversely interferes with requests or responses. These directives typically override the default cache algorithms, such as Expires and last-modified. The cache instruction is one-way, that is, the presence of an instruction in the request does not imply that the same instruction will exist in the response.
the client can Standard Cache-control directives used in HTTP requests :
Cache-control:max-age=<seconds>
cached content will expire after xxx seconds , This option is only available in HTTP 1.1 , and if and last-modified when used together , Higher priority
Cache-control:max-stale[=<seconds>]
Cache-control:min-fresh=<seconds>
Cache-control:no-cache
you must first confirm with the server whether the returned response has been changed before you can use the response to satisfy subsequent requests for the same URL. Therefore, if there is an appropriate authentication token (ETAG),no-cache initiates a round-trip communication to validate the cached response and avoids the download if the resource has not been changed.
Cache-control:no-store
All content is not cached to the cache or the temporary Internet file.
Cache-control:no-transform
Cache-control:only-if-cached
the criteria that the server can use in the response Cache-control directive:
Cache-control:must-revalidate
Cache-control:no-cache
Cache-control:no-store
Cache-control:no-transform
Cache-control:public
Cache-control:private
Cache-control:proxy-revalidate
Cache-control:max-age=<seconds>
Cache-control:s-maxage=<seconds>
Last-modified/if-modified-since:
If you request the same data for the second time, you can tell the server last modified date : Send a if-modified-since header message in your request that contains the date that was last obtained from the server along with the data.
If the data has not changed since then, the server returns a 304, and when the server sends the status code 304 , the data is no longer resent. You only get this status code. So when the data is not updated, you don't need to download the same data again and again; The server assumes you have local cache data.
Etag/if-none-match:
The ETag is used to indicate whether the URL object has changed and is routed to the client in the HTTP response header, which is the format returned by the server side:ETag: " 50b1c1d4f775c61:df3 " The client's query update format is this:if-none-match:w/" 50B1C1D4F775C61:DF3 " if The ETag does not change, then returns the status 304 and then does not return, which is also the same as last-modified. Testing the Etag is primarily useful when downloading breakpoints.
The Expires/cache-control Header is the control of whether the browser caches data directly from the browser or re-sends requests to the server to fetch data . Just Cache-control more than Expires can control, and cache-control will rewrite Expires 's rules.
Last-modified/if-modified-since and etag/if-none-match are when the browser sends a request to the server to determine if the file has been modified , if not modified, send only one 304 back to the browser, telling the browser to fetch the data directly from its local cache, and if so, the entire data will be sent back to the browser.
Relevant knowledge points to be understood by the HTTP frontend