6.1. HTTP Introduction
Web, server, and related Web applications are all communicating with each other through HTTP. HTTP (hypertext Transfer Protocol, Hypertext Transfer Protocol) is the common language used in modern global Internet. Web content is stored on a Web server, and the Web server uses the HTTP protocol, which is often referred to as an HTTP server. These HTTP servers store data from the Internet and, if the HTTP client makes the request, they provide the data. The client sends an HTTP request to the server, and the server echoes the requested data in the HTTP response.
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/97/41/wKioL1krx2KzqnecAAFFv463Aac976.png "title=" Qq20170529135021.png "alt=" wkiom1krtqei6giaaaffv463aac680.png-wh_50 "width=" "height=" 167 "border=" 0 "hspace=" 0 " Vspace= "0" style= "width:500px;height:167px;"/>
Web servers are the hosts of Web resources, and Web resources are the source of Web content. The simplest web resource is a static file in the Web server's file system. These files can contain arbitrary content: text files, HTML files, Word files, avi movie files, and so on. But resources are not necessarily static files, and resources can also be software programs that generate content as needed, which can produce different content based on the user's identity and the information requested.
There are thousands of different types of data on the Internet, and HTTP has a MIME-type data format label for each object to be transmitted over the Web. The Web server appends the MIME (Multipurpose Internet Mail Extension, Multipurpose Internet Mail Extension) type to all HTTP object data. When a Web browser retrieves an object from the server, it looks at the relevant MIME type to see if it can know how to handle the object, and most browsers can handle hundreds of common object types.
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/97/41/wKioL1krx3GhfXToAAE1l2IDWXc880.png "title=" Qq20170529140042.png "alt=" wkiol1krusczhyooaae1l2idwxc410.png-wh_50 "width=" "height=" 137 "border=" 0 "hspace=" 0 " Vspace= "0" style= "width:500px;height:137px;"/>
A MIME type is a text marker that represents a primary object type and a specific subtype, separated by a slash in the middle.
HTML-formatted text documents are marked by the text/html type Plain ASCII text documents are marked by the Text/plain type JPEG version picture is image/jpeg type GIF version picture for image/gif type ... |
Each Web server resource has a name so that the client can find the required resources by that name. The server resource name is called the Uniform Resource Identifier (Uniform Resource Indentifier,uri). The URI, like the postal address on the Internet, uniquely identifies and locates information resources worldwide.
Example: Http://www.joes-hardware.com/specials/saw-blade.gif
The Uniform Resource Locator (Uniform Resource Locator,url) is the most common form of resource identifiers, and URLs describe a specific location of a resource on a particular server. They can clearly explain how to get resources from a precise, fixed location. Shows how the URL accurately describes a voluntary location and how to access it.
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/97/40/wKiom1krx53Qs-wfAAIgZCYayI8534.png "title=" Qq20170529141950.png "alt=" wkiom1krvzogwr0paaigzcyayi8153.png-wh_50 "width=" "height=" 188 "border=" 0 "hspace=" 0 " Vspace= "0" style= "width:500px;height:188px;"/>
Shows how the client can transact with the Web server and its resources through HTTP. An HTTP transaction consists of a request from the client to the server, and a response (the server sends back to the client). This communication is done by drawing data blocks in the format of an HTTP message.
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/97/41/wKioL1krx8zTic0tAAJZFYSbwf8918.png "title=" Qq20170529142510.png "alt=" wkiol1krvtddjdejaajzfysbwf8052.png-wh_50 "width=" "height=" 207 "border=" 0 "hspace=" 0 " Vspace= "0" style= "width:500px;height:207px;"/>
HTTP supports several different request commands, which are called HTTP methods (http Mothod). Each HTTP request message contains a method. These methods tell the server what action to perform, and the common HTTP methods are:
GET |
Request for a resource to be sent by the server |
HEAD |
with GET similar, but it does not require the service to send resources and only returns the response header |
PUT |
with the GET instead, write the document to the server, such as publishing the system |
DELETE |
Request Delete URL Resources pointed to |
OPTIONS
|
Probe the server-side request method supported for a resource |
TRACE
|
A firewall, proxy, or gateway that tracks requests |
Pos
|
Support HTML form submission, the form has user-populated data that is sent to the server side and stored by the server to a location (such as a send handler) |
Each HTTP response message will carry a status code when it returns. The status code is a three-digit code that tells the client whether the request was successful or if it needs to take other actions, and the common status code is:
1xx |
Pure Informational Status Code |
2xx
|
information for the "Success" class (201, 202) |
3xx
|
< Span style= "font-family: ' The song body '; font-size:14px;" > REDIRECT status code moved permanently, in the response message with the header " location:url "specifies where the resource is now 302:FOUND,&NBSP; Use the header "location:url " to specify the temporary resource location; 304:not Modified, used in conditional requests; (used in cache) |
4xx |
403:Forbidden , the request was rejected by the server 404:not Found , the server could not find the requested url 405:method not allowed , this method is not allowed to request the corresponding url |
5xx
|
Server-side Error class information $:InternalServer error, server internal errors; 502: BadGateway, the proxy server received a pseudo response from upstream; 503: Serviceunavailable, the server is not available at this time, but may be available in the future; 504: GatewayTimeout, the backend service is not responding in a timely manner when the gateways proxy requests the backend service. |
An HTTP message consists of a simple string of rows. HTTP messages are plain text, not binary code, so they can be read and written easily. Shows an HTTP message used by a simple transaction.
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/97/41/wKioL1krx--zbSHSAAFJ5sxWiHo701.png "title=" Qq20170529143749.png "alt=" wkiol1krwcixliywaafj5sxwiho843.png-wh_50 "width=" "height=" 121 "border=" 0 "hspace=" 0 " Vspace= "0" style= "width:500px;height:121px;"/>
The htttp message is divided into three parts: Start line, first field, main body.
Request Message Syntax: <method> <request-URL> <version> (Must be blank line ) <entity-body> message body Response Message Syntax: <version> <status> <reason-phrase> (Must be blank line ) <entity-body> |
<method>: Request method, want to perform actions on server side, such as, post, etc. <REQUEST-URL>: The requested resource, which can be a relative path, is also the full URL <version>: protocol version, format Http/<major>.<minor>, such as http/1.0 <status>: Status code <reason-phrase>: Reason phrase, digital status code easy to read information <entity-body>: Body part |
http/0.9: Plain Text Only (hyperlinks), ASCII
http/1.0: Support the processing of multimedia data. Support to stay connected.
http/1.1: Supports persistent connections. Finer-grained cache control
Http-ng (also known as http/2.0), with a focus on performance optimizations and a more powerful remote execution framework for service logic, has no plans to replace http/1.1.
The HTTP header and method work together to determine what the client and server can do. The header can usually be divided into five categories:
Generic Header : Both request and response messages can be used
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/97/41/wKioL1kryAzAagtEAAKFOXFFq14472.png "title=" Qq20170529145314.png "alt=" wkiol1krxchguosqaakfoxffq14838.png-wh_50 "width=" "height=" 195 "border=" 0 "hspace=" 0 " Vspace= "0" style= "width:500px;height:195px;"/>
Http/1.0 introduces a header that allows an HTTP application to cache the local copy of an object, so that it does not always need to be fetched directly from the server segment.
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/97/41/wKioL1kryCjBpWSTAACwo1jE52Y493.png "title=" Qq20170529145517.png "alt=" wkiom1krxekxopxuaacwo1je52y169.png-wh_50 "width=" height= "0" border= "0" Vspace= "0" style= "width:500px;height:58px;"/>
Request Header : Only meaningful in Request message
Informational header of the request:
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/97/41/wKioL1kryKvzo7ApAAKf8SIuqnc571.png "title=" Qq20170529150617.png "width=" "height=" 213 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" WIDTH:500PX;HEIGHT:213PX; "alt = "Wkiol1krykvzo7apaakf8siuqnc571.png"/>
Accept Header:
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/97/40/wKiom1kryVmSjkskAAFT5R5gifY740.png "style=" width : 500px;height:115px; "title=" 1.png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" Wkiom1kryvmsjkskaaft5r5gify740.png "/>
Conditional Request Header:
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/97/41/wKioL1kryVqQ9_6dAAJwOsm1uEk738.png "style=" width : 500px;height:163px; "title=" 2.png "width=" "height=" 163 "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" wkiol1kryvqq9_ 6daajwosm1uek738.png "/>
Security Request Header:
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/97/41/wKioL1kryVqyud01AAEEp0iP5YE453.png "style=" width : 500px;height:74px; "title=" 3.png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" Wkiol1kryvqyud01aaeep0ip5ye453.png "/>
Proxy Request Header:
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/97/40/wKiom1kryVuwzBinAAFxNAglOZc546.png "style=" width : 500px;height:93px; "title=" 4.png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" Wkiom1kryvuwzbinaafxnaglozc546.png "/>
response Header : Only meaningful in Request message
Informational header of the response
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/97/41/wKiom1kryjnz9MccAAGXz1d7c3s220.png "style=" width : 500px;height:145px; "title=" 11.png "width=" "height=" 145 "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" Wkiom1kryjnz9mccaagxz1d7c3s220.png "/>
Negotiation Header
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/97/41/wKiom1kryjrjzXeLAAFJKDnZZNs613.png "style=" width : 500px;height:90px; "title=" 22.png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" Wkiom1kryjrjzxelaafjkdnzzns613.png "/>
Security Response Header
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/97/41/wKioL1kryjvRKbhuAAD3aHlp9DQ053.png "style=" width : 500px;height:71px; "title=" 33.png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" Wkiol1kryjvrkbhuaad3ahlp9dq053.png "/>
entity Header : Used to specify entity properties
The informational header of the entity
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/97/42/wKioL1kryx7SJtfSAADcpqLLSe8413.png "style=" width : 500px;height:78px; "title=" 111.png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" Wkiol1kryx7sjtfsaadcpqllse8413.png "/>
Content Header
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/97/41/wKiom1kryx6SBlNuAAHmwofZhXk582.png "style=" width : 500px;height:173px; "title=" 222.png "width=" "height=" 173 "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" Wkiom1kryx6sblnuaahmwofzhxk582.png "/>
Entity Cache Header
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/97/42/wKioL1kryx-zPfZ8AADzf2Vc4n4055.png "style=" width : 500px;height:75px; "title=" 333.png "width=" "height=" "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" Wkiol1kryx-zpfz8aadzf2vc4n4055.png "/>
extension Header : Non-standard header, possibly created by a program developer, such as X-forward-for
Client:
Gui:ie, Firefox, Safari, Chrome, Opera
Cli:elinks, Curl
Service side:
SERVER:HTTPD (ASF Foundation), Nginx, lighttpd
App Server:iis, Tomcat, jetty, resin
6.2. How the Web server handles connection request schema
1. Single Thread Web server (single-threaded Web servers)
In this way, the Web server processes one request at a time, and then reads and processes the next request at the end. During the processing of a request, all other requests are ignored, so there will be serious mandatory problems in scenarios where there are more concurrent requests.
2, multi-process/multi-threaded Web server
In this architectural approach, the Web server generates multiple processes or threads that process multiple user requests in parallel, and processes or threads can be generated on demand or in advance. There are Web server applications that generate a single process or thread for each user request, but when the number of concurrent requests reaches tens of thousands, multiple concurrently running processes or threads consume a large amount of system resources.
3. I/O multiplexing Web server
In order to be able to support more concurrent user requests, more and more Web servers are using multiple reuse architectures-synchronous monitoring of the active state of all connection requests, a series of specific actions for a connection when the state of a link changes (such as the data is ready or an error occurs), and after the operation is complete, This connection will be reset back to the transient stable state and returned to the list of open connections until the next status change. Because of its multiplexing nature, processes or threads are not occupied by idle connections, and thus provide an efficient mode of operation.
4. Multiplexing multi-threaded Web server
A Web server architecture that combines multi-process and multiplexed functionality to avoid having a process serve too many user requests and take advantage of the computing power provided by multi-CPU hosts.
1, establish the connection-accept or reject the client connection request;
2, receive the request--read the HTTP request message through the network;
3, processing request-parse the request message and make the corresponding action;
4, access to resources-access to the relevant resources in the request message;
5, build the response--use the correct header to generate HTTP response messages;
6, send the response-send the generated response message to the client;
7, logging-when the completed HTTP transaction logs into the log file;
650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/97/41/wKiom1krzWTg72mSAAKHseW8bqw194.png-wh_500x0-wm_ 3-wmp_4-s_4248075833.png "title=" Qq20170529152719.png "alt=" Wkiom1krzwtg72msaakhsew8bqw194.png-wh_50 "/>
This article is from the "Wind and Drift" blog, please be sure to keep this source http://yinsuifeng.blog.51cto.com/10173491/1930580
VI. Web Services Fundamentals