simple website development agreement pdf

2022.03.24

HTTP Agreement is the foundation agreement of the Internet,It is also a must-have knowledge of web development,The latest version HTTP/2 What makes it a technical hotspot。

This article introduction HTTP Historical evolution and design idea of the agreement。

simple website development agreement pdf

one、HTTP/0.9

HTTP is based on TCP/IP Application layer protocol。It does not involve packets(packet)transmission,It mainly specifies communication format between clients and servers.,By default80port。

The earliest version is1991Annual release0.9Version。This version is extremely simple,Only one commandGET

(simple website development agreement pdf)GET /index.html

The above command is indicated,TCP connect(connection)After the establishment,Client requests to server(request)Web pageindex.html

(simple website development agreement pdf)Agreement,Server can only respondHTMLFormat string,Can't respond to other formats。

<html>
 <body>Hello World</body>
</html>

Server is sent,Shut downTCPconnect。

two、HTTP/1.0

2.1 Introduction

1996year5moon,HTTP/1.0 Version release,Content greatly increase。

first,Any format content can be sent。This makes the Internet not only transmit text,Can also transfer images、video、binary file。This lays the foundation for the broad development of the Internet。

Secondly,Apart fromGETOrder,Also introducedPOSTCommandmentHEADOrder,Enrich the interaction of browser and server。

again,HTTPThe format of the request and response has changed.。In addition to data part,Each communication must include header information(HTTP header),Used to describe some metadata。

Other new features also include status codes(status code)、Multi-character set support、Multiple sends(multi-part type)、Authority(authorization)、Cache(cache)、Content coding(content encoding)Wait。

2.2 Request format

Here is one1.0VersionHTTPRequest example。

GET / HTTP/1.0User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5)Accept: */*

can be seen,This format is0.9Very variable version。

The first line is the request command,The protocol version must be added at the end(HTTP/1.0)。Behind the multi-line information,Describe the client's situation。

2.3 Response format

(simple website development agreement pdf)The response of the server is as follows。

HTTP/1.0 200 OK
Content-Type: text/plainContent-Length: 137582Expires: Thu, 05 Dec 1997 16:00:00 GMTLast-Modified: Wed, 5 August 1996 15:55:28 GMTServer: Apache 0.84
<html>
 <body>Hello World</body>
</html>
(simple website development agreement pdf)The format of the response is"Head information + A blank line(\r\n) + data"。in,First line is"Protocol version + status code(status code) + status description"。

2.4 Content-Type Field

Coding on characters,1.0Version regulations,Head information must be ASCII code,The following data can be any format。therefore,When the server responds,Must tell the client,What is the format of data?,This isContent-TypeField role。

(simple website development agreement pdf)Here are some commonContent-TypeValue of fields。

  • text/plain

  • text/html

  • text/css

  • image/jpeg

  • image/png

  • image/svg+xml

  • audio/mp4

  • video/mp4

  • application/javascript

  • application/pdf

  • application/zip

  • application/atom+xml

These data types are generally referred to asMIME type,Each value includes primary type and secondary type,Subject with slash。

In addition to predefined types,Vendors can also customize types。

(simple website development agreement pdf)application/vnd.debian.binary-package

The above type indicates,SentDebianSystem binary packet。

MIME typeYou can also use a semicolon at the end,Add parameters。

Content-Type: text/html; charset=utf-8

The above type indicates,Send a web page,And the encoding isUTF-8。

(simple website development agreement pdf)When the client requests,can useAcceptField declarations you can accept which data formats。

Accept: */*
(simple website development agreement pdf)Above,Client declares that you can accept data in any format。

MIME typeNot onlyHTTPprotocol,You can also use it elsewhere,for exampleHTMLWeb page。

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- Equivalent to -->
<meta charset="utf-8" />
(simple website development agreement pdf)2.5 Content-Encoding Field

(simple website development agreement pdf)Since the data sent can be any format,Therefore, you can compress the data and then send it.。Content-EncodingField Description Data Compression Method。

(simple website development agreement pdf)Content-Encoding: gzipContent-Encoding: compressContent-Encoding: deflate
(simple website development agreement pdf)The client is in the request,useAccept-EncodingField Description Which compression methods you can accept。

Accept-Encoding: gzip, deflate

2.6 shortcoming

HTTP/1.0 The main disadvantage is,EachTCPConnection can only send a request。Send data,Close connection,If you want to request other resources,You must create a connection again。

TCPNew cost of connectivity is high,Since the client and server are needed three times,And the transmission rate is slower at the beginning(slow start)。so,HTTP 1.0Version performance is relatively poor。More and more external resources loaded with web,This problem has become more prominent.。

To solve this problem,Some browsers are in the request,Used a non-standardConnectionField。

Connection: keep-alive
(simple website development agreement pdf)This field requires the server not to closeTCPconnect,In order to be reused by other requests。The server also responds to this field。

Connection: keep-alive

One can be reusedTCPConnection is established,Until the client or server actively turn off the connection。but,This is not a standard field,Different implementation may not be consistent,So not fundamental solution。

(simple website development agreement pdf)three、HTTP/1.1

1997year1moon,HTTP/1.1 Version release,Only 1.0 The version is late for half a year。It is further improved HTTP protocol,I have been used20Year later today,Until now is still the most popular version。

3.1 Persistent connection

1.1 Maximum change,That is to introduce a lasting connection(persistent connection),which isTCPConnection is not closed by default,Can be multiplexed by multiple requests,UnprovenConnection: keep-alive

The client and server find that the other party has no activity for a while,You can take the initiative to turn off the connection。but,Normative practice is,When the client is in the last request,sendConnection: close,Specify the server to closeTCPconnect。

Connection: close

Currently,For the same domain name,Most browsers allow simultaneous establishment6One-lasting connection。

3.2 Pipeline mechanism

1.1 The version has also introduced pipeline mechanisms(pipelining),At the sameTCPInside,Clients can send multiple requests at the same time。This will further improveHTTPProtocol efficiency。

for example,The client needs to request two resources。Previous practice is,In the sameTCPInside,SendAask,Then wait for the server to respond,ReceivedBask。The pipeline mechanism is to allow the browser to be issued simultaneously.ARequest andBask,But the server is still in order,First respondAask,Respondent after completingBask。

(simple website development agreement pdf)3.3 Content-Length Field

OneTCPConnection can now transmit multiple responses,It is necessary to have a mechanism,What is the response from the data package?。This isContent-lengthField role,Declare the data length of this response。

Content-Length: 3495

The above code tells the browser,The length of this response is3495Byte,The later bytes belong to the next response.。

exist1.0Version,Content-LengthField is not required,Because the browser finds that the server is turned offTCPconnect,It is clear that the received data package is all。

3.4 Partition transmission code

useContent-LengthThe prerequisite for fields is,Before the server sends a response,Must know the length of the response。

(simple website development agreement pdf)For some very time-consuming dynamic operations,this means,Server wants to wait until all operations are completed,Can only send data,Obviously this efficiency is not high。Better processing method is,A piece of data,Send a piece,use"Flow mode"(stream)replace"Cache mode"(buffer)。

therefore,1.1Version regulations can not be usedContent-LengthField,Use"Partition transmission code"(chunked transfer encoding)。As long as the header information requested or respondedTransfer-EncodingField,It is indicated that the response will consist of the quantity undisputed data block.。

Transfer-Encoding: chunked

Before each non-empty data block,There will be one16Encourage value,Represents the length of this block。Finally a size is0Block,I said that the data sent by this response is over.。Below is an example。

HTTP/1.1 200 OKContent-Type: text/plainTransfer-Encoding: chunked
25
This is the data in the first chunk
1C
and this is the second one
3
con
8
sequence
0
(simple website development agreement pdf)3.5 Other functions

1.1Edition added many verbs:PUTPATCHHEADOPTIONSDELETE

in addition,The header information requested by the client has been added.HostField,Domain name used to specify the server。

Host: www.example.com
(simple website development agreement pdf)HaveHostField,You can send a request to different websites on the same server.,Late the foundation for the rise of the virtual host。

3.6 shortcoming

although1.1Edition allows multiplexedTCPconnect,But the sameTCPInside,All data communication is in order。Server only handles one response,Will carry the next response。If the response in front is very slow,There will be many requests waiting in line behind.。This is called"Team head blockage"(Head-of-line blocking)。

To avoid this problem,Only two ways:First, reduce the number of requests,Second, while doing a long-lasting connection。This leads to a lot of web optimization skills,Such as merge scripts and style sheets、Embed picturesCSSCode、Domain(domain sharding)etc。ifHTTPAgreement is designed to be better,These additional work can be avoided。

(simple website development agreement pdf)Four、SPDY protocol

2009year,Google publicly developed its own research and development SPDY protocol,Mainly solve HTTP/1.1 Utty problem。

This agreement isChromeAfter the browser is proved,Be regarded as HTTP/2 The basics,Main characteristics are HTTP/2 Get inheritance。

Fives、HTTP/2

2015year,HTTP/2 release。It is not called HTTP/2.0,It is because the Standards Committee does not intend to release the release.,The next new version will be HTTP/3。

5.1 Binary agreement

HTTP/1.1 The header information is definitely text(ASCIIcoding),Digital data can be text,Can also be binary。HTTP/2 It is a thorough binary agreement,Head information and data body are binary,And collectively"frame"(frame):Head information frame and data frame。

One benefit of the binary agreement is,Additional frames can be defined。HTTP/2 Define nearly ten frames,Founded for future advanced applications。If you use text to implement this function,Analysis of data will become very troublesome,Binary analysis is more convenient。

5.2 Multi-worker

HTTP/2 MultiplexTCPconnect,In a connection,Both clients and browsers can send multiple requests or responses simultaneously,And do not have to be in order,This avoids this"Team head blockage"。

for example,in aTCPInside,The server received at the same time.ARequest andBask,So first respondAask,The results show that the processing process is very time consuming.,So sendARequests have been handled, Follow upBask,after finishing,Re-sendARequest the remaining part。

(simple website development agreement pdf)Such two-way、Real-time communication,Be called multiple workers(Multiplexing)。

5.3 data flow

because HTTP/2 The packet is not sent in order,Continuous data package in the same connection,May belong to different responses。therefore,Must be tagged for packets,Point out which response it belongs to。

HTTP/2 All packets of each request or response,A data stream(stream)。Each data stream has a unique number。When the packet is sent,Both must be marked data streamID,Which data is used to distinguish it?。Furthermode,Data flow issued by the client,IDAll be odd,Server,IDAn even number。

When the data stream is sent to half,Clients and servers can send signals(RST_STREAMframe),Cancel this data stream。1.1The only way to cancel data flow,CloseTCPconnect。This means that,HTTP/2 Can cancel a request,At the same timeTCPThe connection is also open,Can be used by other requests。

The client can also specify the priority of the data stream。The higher the priority,The sooner the server responds。

5.4 header compression

HTTP Protocols do not carry state,All information must be attached to each request。so,Many fields of the request are repeated,for exampleCookieandUser Agent,the same content,Every request must be accompanied by,This wastes a lot of bandwidth,also affects speed。

HTTP/2 optimized for this,Introduced header information compression mechanism(header compression)。on the one hand,header information usagegziporcompressCompress and send;on the other hand,The client and server maintain a header information table at the same time,All fields will be stored in this table,generate an index number,The same field will not be sent in the future,Only send the index number,This increases the speed。

(simple website development agreement pdf)5.5 server push

HTTP/2 Allow server unsolicited,Actively send resources to clients,It's called server push(server push)。

A common scenario is that the client requests a web page,This page contains a lot of static resources。Under normal circumstances,After the client has received the page,ParseHTMLsource code,Found static resources,Make another static resource request。actually,The server can expect that after the client requests the web page,Likely to request static resources again,So I took the initiative to send these static resources to the client along with the web page.。

返回列表
更多新闻资讯