Nezha’s life creed: If you like what you learn, there will be strong motivation to support it.
Learn programming every day, so that you can update your dream step, thank you not to live up to every programmer who loves programming, no matter how strange the knowledge point is, together with me, let that wandering heart settle down, go on, come on 2021! Welcome to follow me vx:xiaoda0423, welcome to like, favorites and comments
Don’t be afraid to dream, but don’t just dream. Be a doer, not a talker.
preface
I hope I can get help for you through this article. Have you accepted the challenge?
About HTTP Modules
1. What are the port numbers of HTTP and HTTPS
HTTP is a request and response based, stateless, application-layer protocol that transmits data over TCP/IP. It is the most widely used network protocol on the Internet. All WWW files must comply with this standard. HTTP was originally designed to provide a way to publish and receive HTML pages.
HTTP is a widely used network transport protocol. It is the application layer communication protocol or standard TCP between the client browser or other programs and the Web server. It is used to transfer hypertext from the WWW server to the local browser.
So HTTPS, which is a transport protocol for complete communication over a computer network, over HTTP, using SSL/TLS to establish communication, encrypting packets. The primary purpose of HTTPS is to provide identity authentication to web servers and protect the privacy and integrity of the data exchanged.
HTTPS is the encrypted version of HTTP, which aims at security. SSL is added to HTTP, based on SSL.
TLS is a transport layer encryption protocol, formerly known as SSL.
HTTP is usually carried on top of TCP, adding a layer of security protocol (SSL or TSL) between HTTTP and TCP, commonly known as HTTPS.
HTTP features:
Support client or server mode, C/S mode;
Simple and fast, when the client requests services to the server, it only needs to transmit the request method and path. Request methods are commonly used GET,HEAD,POST, each method defines the customer and server contact type is different, because HTTP protocol is simple, making HTTP server program size is small, so the communication speed is fast;
More flexible, HTTP allows data objects of any Type to be transferred, with the Type being transferred marked by the Content-Type;
No connection: indicates that only one request can be processed for each connection. The server disconnects from the client after processing the request and receiving the response from the client. This mode saves transmission time.
Stateless, HTTP protocol is stateless, stateless said agreement for the transaction is not memory ability, lack of state means that if the information in front of the subsequent processing need, then it must be the retransmission, that could lead to increasing amount of data transmitted per connection, on the other hand, when the server does not require the information previously its response is fast.
HTTPS characteristics
It is the use of mixed encryption technology, the middle is unable to see the plaintext content, the content encrypted;
It also authenticates the identity and authenticates the client to access its own server through the certificate.
It can prevent the transmitted content from being impersonated or tampered with by middlemen and protect the integrity of data.
HTTP urls start with http:// and HTTPS urls start with https://. HTTP is not secure, HTTPS is secure; HTTP cannot be encrypted, whereas HTTPS encrypts transmitted data. HTTP does not require a certificate, whereas HTTPS requires an SSL certificate issued by the CA.
Their port numbers are:
The default HTTP port number is 80 and HTTPS port number is 443
HTTPS is more secure because, in a network request, many servers and routers need to forward it. Each of these nodes can tamper with information, whereas if HTTPS is used, the key is only available at the terminal. HTTPS is more secure than HTTP because it uses the SSL/TLS protocol for transmission. It includes certificate, unload, traffic forwarding, load balancing, page adaptation, browser adaptation, REFER transfer and other technologies to ensure the security of the transmission process.
HTTPS, short for Hyper Text Transfer Protocol Secure, provides one more Secure than HTTP. This Secure is provided by TLS (SSL). HTTPS and HTTP are both application Layer protocols based on TCP and UDP, but they are completely different.
HTTP is a format specification for data transfer between client and server. It stands for hypertext Transfer Protocol.
summary
-
Stateless protocols have no memory for transactions, and the lack of state means that information provided previously is required if it needs to be processed later
-
One way to overcome the pitfalls of stateless protocols is to save information through cookies and sessions
2.http/2
How much do you know?
HTTP/2 introduces the concept of “server-side push,” which allows the server to proactively send data to the client cache before the client needs it, thereby improving performance.
HTTP/2 provides additional encryption support. The use of multiplexing allows multiple messages to be crossed simultaneously on one connection. Increased header compression so that requests are very small, and headers for both requests and responses use very small bandwidth ratios.
The HTTP /2 protocol is based on HTTPS, so HTTP /2 security is also guaranteed.
Header compression: HTTP /2 will compress the header, so if you make multiple requests at the same time and their headers are the same or similar, the protocol will help you eliminate duplicate parts.
For HTTP /2, instead of using plain text messages like HTTP /1.1, the binary format is used. Header information and data body are binary, collectively called frame, header information frame and data frame.
Data flow: HTTP /2 packets are not sent sequentially. Consecutive packets within the same connection may belong to different responses and must be marked to indicate which response they belong to. All packets of data for each request or response are called a data stream.
Multiplexing: HTTP /2 can be in a connection to concurrent multiple requests or responses, rather than in accordance with the sequence of one to one correspondence, to solve the HTTP /1.1 serial requests, do not need to queue waiting, there will be no queue head blocking problem, reduce the delay, greatly improve the utilization of the connection.
Server push, HTTP /2 improves the request-response mode of transmission, so that the server can automatically send information to the client instead of passively responding.
Http2 problem in multiple HTTP requests in reuse a TCP connection, the lower the TCP protocol is don’t know how many a HTTP request, in case of packet loss phenomenon, triggers TCP retransmission mechanism, so all the HTTP requests in a TCP connection must be waiting for the lost package is heavy to return to.
First, if a single request is blocked in HTTP /1.1 piping, all the post-queue requests are blocked. Second, HTTP /2 multiple requests reuse a TCP connection, which blocks all HTTP requests once packet loss occurs.
3. Describe common HTTP status codes
Five types of HTTP status codes:
1xx: indicates that the protocol processing is in the intermediate state and there are further operations to be performed
2xx: yes. The packet is received and correctly processed. 200, 204, 206
3xx: redirection. The resource location changes and the client needs to resend the request
4xx: An error occurs on the client. The request packet is incorrect, and the server cannot process it
5xx: Server error. An internal error occurred while the server was processing the request
-
100 Continue Indicates a continuation. Generally, after the HTTP header has been sent during post requests, the server returns this information to confirm the request and then sends specific parameters.
-
200 OK: The information is returned normally.
-
201 Created Indicates that the request succeeds and the server creates a new resource
-
202 Accepted Indicates that the server has Accepted the request but has not yet processed it
-
301 Moved Permanently: Indicates that the requested web page has been Permanently Moved to the new location
-
302 Found indicates a temporary redirect
-
303 See Other indicates a temporary redirection and always uses GET to request a new URI
-
304 Not Modified indicates that the requested page has been Modified since the last request
-
400 Bad Request Indicates that the server cannot understand the format of the Request. The client should not try to send the Request again with the same content.
-
401 Unauthorized The request is not authorized
-
403 Forbidden Forbidden access
-
404 Not Found: Can’t find resource that matches uri
-
500 Internal Server Error Indicates the most common Server errors
-
503 Service Unavailable Indicates that the server cannot process the request temporarily
4. Tell me abouthttp
Transaction process
The first step, domain name resolution; Second, initiate a TCP three-way handshake. The third step is to initiate HTTP requests after establishing TCP connections. Fourth, the server responds to the HTTP request and the browser gets the HTML code. Fifth, the browser parses the HTML code and requests resources in the HTML code. Sixth, the browser renders the page and renders it to the user.
5. Write simpleHTTP
The server
var http = require('http');
http.createServer(function(req, res){
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<meta charset="UTF-8"><h1>dadaqianduan</h1>');
res.end();
}).listen(3000);
Copy the code
6. Tell me abouthttp
Which parts are contained in the request message and response message
The request packet consists of three parts:
1. The request line contains the request method, URI, and HTTP version information
2. Request header field
3. Request content entities
The request packet consists of three parts:
1. Status line, containing HTTP version, status code, status code reason phrase
-
Response header field
-
Response content entity
7. What is a reverse proxy
Reverse Proxy: a Proxy server receives Internet connection requests, forwards the requests to the Intranet server, and returns the results to the Internet client. In this case, the Proxy server acts as a Reverse Proxy server externally.
8. What request methods are available in HTTP
GET: requests access to a resource that has been identified by the URI, the Uniform Resource Identifier (URI), and can pass parameter data to the server through the URL
POST transfers information to the server. It is similar to GET, but the amount of data that can be transferred is usually unlimited.
PUT: transfers the file. The packet body contains the file content and saves it to the URI.
HEAD, which is similar to GET but does not return the packet body, is used to verify whether the URI is valid.
DELETE deletes a file, as opposed to the PUT method, which produces the file at the URI location
OPTIONS: Queries HTTP methods supported by the URI
9.HTTP
In the agreement1.0
Version specification and1.1
Version specification differences
In HTTP1.0, when a connection is established, the client sends a request, the server returns a message, closes the connection, and the browser re-establishes the connection the next time it requests. This method of constantly establishing a connection can cause many problems.
In HTTP1.1, the concept of continuous connections was introduced, whereby a browser can establish a connection, send a request and get a return message, and then send the request again and wait for the return message. Clients can send multiple requests in succession without waiting for each response to arrive.
10.HTTP
What types are included in the header field of
A common header field that is used in both request and response packets
Date
Is the time when the packet is createdConnection
, connection managementCache-Control
Cache controlTransfer-Encoding
Is the transmission coding mode of the packet body
The header field that will be used in the request message
Host
, requesting the server where the resource residesAccept
, the type of media that can be processedAccept-Charset
, acceptable character setAccept-Encoding
, acceptable content encodingAccept-Language
: Acceptable natural language
Response header field. The header field used by the response packet
Accept-Ranges
, the range of acceptable bytesLocation
To redirect the client to the URIServer
HTTP server installation information
Entity header field. The header field used in the entity part of the request message and response message
Allow
, resources can support HTTP methodsContent-Type
, the type of the entity bodyContent-Encoding
, the encoding method used by the entity bodyContent-Language
The natural language of the entity subjectContent-Length
, the number of bytes of the entity bodyContent-Range
, the location range of the entity body, commonly used when making partial requests
With 11.https
Compared to thehttp
What are the disadvantages
The disadvantages of HTTP are: communication uses plaintext, not encryption, content may be eavesdropped, that is, captured packet analysis; If the identity of the communication party is not verified, it may be disguised; Failed to verify packet integrity, possibly tampering.
HTTPS is HTTP + encryption + authentication + integrity protection
12. How to optimizeHTTP
request
Optimize and speed UP HTTP application requests using load balancing and optimize web site requests using HTTP caching
13. What are the features of HTTP
Support client or server mode, simple, fast, flexible, no connection, no state.
14.HTTP1.1
Release of new features
The default persistent connection saves traffic. As long as neither the client nor the server explicitly disconnects the TCP connection, the connection is kept and HTTP requests can be sent multiple times.
Piped, a client can make multiple HTTP requests at the same time without waiting for a response.
Principle of breakpoint continuation.
15.tcp
Transmission of three handshakes, four waves
After sending the data packet through TCP, TCP does not ignore the data after transmission. It must confirm whether the data is successfully delivered to the other party. TCP flags are used in the handshake, both SYN and ACK
The sender first sends a packet with the SYN flag to the receiver. After receiving the packet, the receiver sends back a packet with the SYN/ACK flag to indicate correct communication and confirm the information. Finally, the sender sends back a packet with an ACK flag, indicating the end of the handshake. If the handshake is interrupted at some stage, TCP sends the same packets in the same order again.
Breaking a TCP connection requires a “four-way handshake”
First handshake: The active closing party sends a FIN to close data transmission from the active closing party to the passive closing party. That is, the active closing party tells the passive closing party that the active closing party will no longer send data to the passive closing party, but the active closing party can still receive data.
Second handshake: After receiving the FIN packet, the passive closing party sends an ACK with the received sequence number +1, which is the same as that of the SYN. Each FIN occupies one SEQUENCE number.
Third handshake: After the passive closing party receives the FIN packet, it is used to close the data transmission from the passive closing party to the active closing party. In other words, it tells the active closing party that the data of the passive closing party has been sent and no more data will be sent to the active closing party.
Fourth handshake: After the active closing party receives a FIN, it sends an ACK to the passive closing party, confirming that the sequence number is +1.
16. Tell me the difference between TCP and UDP
TCP is a connection-based protocol, that is, before sending or receiving data, a reliable connection must be established with the peer party. A TCP connection must be set up in three sessions.
Udp user datagram protocol, which corresponds to TCP. It is a connection-oriented protocol, which does not establish a connection with the other party, but sends the packet directly. Udp is suitable for applications where only a small amount of data is transmitted at a time and reliability is not high.
17. A page from inputurl
What does the page load display send to complete the process
When a URL request is sent, whether it is the URL of a Web page or the URL of each resource on the Web page, the browser starts a thread to process the request and a DNS query on a remote DNS server, which enables the browser to obtain the Ip address of the request.
The browser establishes a TCP/IP connection with the remote Web server through TCP three-way handshake negotiation. The handshake includes a synchronous message, a synchronous response message and a response message, the three message passed between the browser and the web server, the handshake firstly by the client try to set up the communication, then the server response and accept the client’s request, and finally made by the client has accepted the request message.
Once a TCP/IP connection is established, the browser sends an HTTP GET request to the remote server over the connection. The remote server finds the resource and returns the resource with an HTTP response. An HTTP response status code of 200 indicates a correct response.
The Web server provides resource services. The client starts to download resources, and when the request is returned, it enters the browser module. The browser will parse HTML to generate A DOM Tree, and then generate a CSS rule Tree based on CSS.
18. What are the seven layers of the network hierarchical model
- Application layer: Means of allowing access to the OSI environment
- Presentation layer: Data is translated, encrypted, and compressed
- Session layer: Establishes, manages, and terminates sessions
- Transport layer: Provides reliable end-to-end message delivery and error recovery
- Network layer: responsible for packet transfer from source to destination and Internet interconnection
- Data link layer: assembles bits into frames and implements point-to-point transmission
- Physical layer: Transmits bits through the medium, determining mechanical and electrical specifications
19. Tell me about304
How caching works
The server first generates an ETag for the request, which the server can use later in the request to determine whether the page has been modified. In essence, the client asks the server to verify that its client is cached by passing this token back to the server.
304 is the HTTP status code that the server uses to indicate that the file is unmodified and does not return content. The browser will use the cached file when it receives the status code.
The client requests page A, the server returns page A, and adds an ETag to page A. The client displays the page and caches the page with the ETag. The client requests page A again, and passes the ETag returned by the server to the server. The server checks the ETag, determines that the page has not been modified since the last client request, and returns response 304 with an empty response body.
Es module
20. Summarize the limitations of strict patterns
- Variables must be declared before being used
- The parameters of a function cannot have the same name; otherwise, an error will be reported
- You can’t use
with
statements - Cannot assign a value to a read-only attribute, otherwise an error is reported
- Octal numbers cannot be used or an error will be reported
- Special characters cannot be used
- You can’t use
delete
Delete variables, methods, etcdelete
Deletes an attribute of an object eval
No variables are introduced in its outer scopeThe eval and the arguments
Cannot be reassignedarguments
Does not automatically reflect changes in function parameters- You can’t use
arguments.callee
- You can’t use
arguments.caller
- ban
this
Pointing to a global object - You can’t use
Fn. The caller and fn. The arguments
Gets the stack of function calls - Added reserved words
21. Tell me aboutes6
- Added template string
The ${}
- Arrow function
for-of
- Gets the remaining parameter syntax instead
arguments
object - Define default parameter syntax
es6
willPromise
Object incorporated into the specification, provided nativePromise
object- increased
let
Keyword to define block-scoped variables - increased
const
To define constants - increased
Symbol
The data type - The introduction of
module
Module concept
22.Promise
What are the characteristics
Es6 natively provides Promise objects that are used to handle asynchronous operations.
Promise object features:
The state of the Promise object is unaffected by the outside world. The Promise object has three states: Pending, Resolved, completed, and Rejected. Only the result of the asynchronous operation can determine the state.
Once the state changes, it never changes again, and you can get this result at any time. There are only two possibilities for a Promise object to change from Pending to Resolved and from Pending to Rejected. Only in these two cases, the state is fixed, it’s going to stay the same, it’s never going to change.
Even if you add a callback to a Promise object, you get this result immediately, as opposed to an event, where you can’t get a result if you miss it and then listen.
With Promise objects, asynchronous operations can be expressed as a flow of synchronous operations, eliminating layers of nested callback functions, and Promise objects provide a unified interface that makes it easier to control asynchronous operations.
Disadvantages: You can’t cancel a Promise. Once it’s created, it executes immediately and can’t cancel midway. If you don’t set a callback function, errors thrown inside a Promise won’t be reflected externally.
23. Tell me aboutPromise
The understanding of the
Three states:
Pending refers to the initial state, which is not Fulfilled or Rejected
Resolved means a successful operation
Rejected refers to a failed operation
let p = new Promise(resolve, reject) => {
if(condition) {
resolve(result)
}else{
reject(result)
}
}
});
promise.then(onResolved,onRejected)
Copy the code
24. Es6 implements array deduplication
/ / es5 var varr,2,3,4,3,4,5,5,3 [1] the function removeDa (arr) {var obj = {}; arr.forEach(function(item,index){ obj[item] = true }) return Object.keys(obj); } // es6 let removeDa = arr => [...{new Set([...arr]))];Copy the code
25. Es6 uses the exchange of two numbers
let a = 1, b = 2; [a,b] = [b,a]; console.log(a); // 2 console.log(b); / / 1Copy the code
26. Why is it usedes6
First: conform to the future trend; Second: improve development efficiency; Third: reduce the amount of code, improve readability, etc.
27. How to make browser support in the development environmentes6
Compile using Babel
28.es6
In thelet
Do keywords support block-level scope
var arr = []; for (var i = 0; i < 5; i++){ arr[i] = function(){ console.log(i); } } arr[3](); // 5 let arr = []; for(let i = 0; i < 5; i++) { arr[i] = function() { console.log(i); } } arr[3](); / / / 5Copy the code
Let adds a block-level scope to JavaScript that allows variables to be declared only within the code block in which the let keyword resides.
29. Code examples
var obj = {
// es5
fn1: function() {
console.log('fn1',this)
},
fn2:() => {
console.log('fn3',this)
}
}
obj.fn1(); // obj
obj.fn2(); // window
Copy the code
30.super
What is the
It is a keyword used as super(…) Or super. Xx (…).
The syntactic definition of super is different from that of this, where the keyword this is replaced by a reference, whereas super is super(…). Is replaced by a call. In addition to calling super directly from constructor, you can also use super.xx(…) To call a prototypical method on a parent class, which is also a qualified syntax.
31. Code examples
(function(x,f=()=>x){ var x: var y = x; x = 2; return [x,y,fn()]; ,1,1 [2]}) (1)Copy the code
32. Code examples
(function(){
console.log([
(()=>this.x).bind({x:'inner'})(),
(()=>this.x)()
})
}).call({x:'outer'});
// ['outer','outer']
Copy the code
33. Code examples
(function(){ let a = this? class b{} : class c{}; console.log(typeof a, typeof b, typeof c) })() // function undefined undefinedCopy the code
34. Code examples
(typeof (new (class { class () {} })))
// object
Copy the code
var Test = class{
class(){}
};
var test = new Test();
typeof test;
Copy the code
35. Code examples
(function(){
if(false){
let f={g()=>1};
}
return typeof f;
})()
// error
Copy the code
36. What isDOM
The template
A DOM template is a browser-recognized HTML result written on the page and rendered by the browser when it is loaded. Therefore, it is necessary to follow the HTML structure and tag naming, otherwise it cannot be parsed by the browser and can not get the content, and then use JavaScript to obtain the content of the DOM node, forming a DOM template.
What is a string template
A string template may originally reside in aScript tag on the server as a JavaScript string and not participate in page rendering, so it may not care about HTML structure and tag naming, as long as the corresponding structure is generated from the template and named in accordance with the HTML specification.
38. Tell the difference between an extension operator and a residual operator
In some ways, the residual operator is the opposite of the extension operator. The extension operator “expands” the array into multiple elements, and the remaining operator collects and “compresses” multiple elements into a single element.
39.var,let,const
Declare variable differences
The variable declared by var does not support block scope, supports pre-declaration, can be repeatedly defined, and the value can be changed.
Variables declared by lets support block scope, do not support pre-declaration, cannot be defined repeatedly, and their values can be changed.
Const defines constants. The declared constants are scoped, do not support predeclarations, cannot be defined repeatedly, and cannot be changed. Values are usually of value type and cannot be used to define loop variables.
40. Deconstruct categories
Object deconstruction; Array deconstruction; Mixed deconstruction; Parameter deconstruction.
41.es6
theextends
Do you support multiple inheritance
Es6 does not support multiple inheritance, but it can be simulated by techniques such as blending, which overwrites methods of the same name in declarative order once multiple inheritance is used.
42. Residual parameters andarguments
Object distinction
The remaining arguments contain only arguments that have no corresponding parameters, whereas the Arguments object contains all arguments passed to the function.
The Arguments object is not a real Array, and the remaining arguments are real Array instances on which all Array methods can be used directly.
The Arguments object also has some additional properties.
If you want to use array methods on arguments objects, you first need to convert it to a real array.
43.for.. of
What’s a little
Has the same for… The concise syntax of in, but without for… The disadvantage of the in
Unlike forEach, it can be used with break,continue, or return
Provides a unified operation interface for traversing all data structures
44. Why can’t modifiers be used for functions
Modifiers can only be used for classes and methods of classes, not functions, because function promotion exists
45.Iterator
What is the purpose of the interface
Provides a unified access mechanism for all data structures, for.. Of circulation
When using the for… When the of loop iterates over some data structure, the loop automatically looks for the Iterator interface.
46. What should be noted when using external module scripts
Code is run in module scope, not global scope, and top-level variables inside the module are not visible externally.
Module scripts automatically adopt strict mode regardless of whether use strict is declared
In a module, you can use the import command to load other modules, and you can use the export command to output external interfaces
In a module, the top-level this keyword returns undefined instead of pointing to the window, meaning that using this at the top of the module is meaningless.
If the same module is loaded more than once, it is executed only once.
47.Iterator
Function and traversal process
First, to provide a unified, easy access interface for various data structures
Second, the members of the data structure can be sorted in some order
Third, ES6 creates a new traversal command for… The Iterator interface mainly provides for… Of the use of
Process:
Create a pointer object that points to the start of the current data structure; that is, the traverser object is essentially a pointer object.
The first call to the next method of a pointer object points to the first member of the data structure
The next method of the pointer object is called the second time, and the pointer points to the second member of the data structure
Call the next method of the pointer object until it points to the end of the array structure. Each time the next method is called, information about the current member of the data structure is returned.
48.async
Functions can be declared in several ways
Function declaration
async function da(){}
Copy the code
Expression declaration
var bar = async function () {}
Copy the code
By object declaration
var obj = {
async daFun(){}
}
Copy the code
Declared by the arrow function
var da = async() =>{}
Copy the code
49.async
Function, how to handle error statements
try... catch
async function demo() {
try{
await doSomeThing();
} catch(err){
console.log(err)
}
}
Copy the code
Add the catch callback
async function demo() {
await doSomeThing().cache(err=>console.log(err))
}
Copy the code
50.es6
,generator
Function of thethrow
Method how to use
Throw () resumes the execution of the generator and throws an exception at the point of execution
Throw (), like next(), returns {value,done}, and the generator body will not actually execute throw() until the exception thrown is handled.
Likes, favorites and comments
I’m Jeskson, thanks for your talent: likes, favorites and comments, and we’ll see you next time! ☞ Thank you for learning with me.
See you next time!
This article is constantly updated. You can search “Programmer Doraemon” on wechat to read it for the first time, and reply [information] there are materials of first-line big factories prepared by me, which have been included in this article www.dadaqianduan.cn/#/
Star: github.com/webVueBlog/…