A. Cookies
With Set-cookie settings, the next browser request will be brought up, key-value pairs, you can set more than one.
Cookie Properties
Max-age and expires setting expiration time
Secure is only sent when HTTPS is
HttpOnly cannot be accessed through Document.cookie
Server.js Code
ConstHTTP = require ('http')ConstFS = require ('FS') Http.createserver (function (request, response) {Console.log ('Request Come', Request.url)if(Request.url = = ='/') { Consthtml = Fs.readfilesync ('test.html','UTF8') Response.writehead ( $, { 'Content-type':'text/html', 'Set-cookie': ['id=123; max-age=2','abc=456;domain=test.com']}) Response.End (HTML)}). Listen (8888) Console.log ('Server listening on 8888')
test.html Code
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <Metaname= "Viewport"content= "Width=device-width, initial-scale=1.0"> <Metahttp-equiv= "X-ua-compatible"content= "Ie=edge"> <title>Document</title></Head><Body> <Div>Content</Div></Body><Script>Console.log (Document.cookie)</Script></HTML>
Request Result:
Second, HTTP long connection
Server.js
ConstHTTP = require ('http')ConstFS = require ('FS') Http.createserver (function (request, response) {Console.log ('Request Come', Request.url)Consthtml = Fs.readfilesync ('test.html','UTF8') Constimg = Fs.readfilesync ('test.jpg') if(Request.url = = ='/') {Response.writehead ( $, { 'Content-type':'text/html', }) Response.End (HTML)}Else{Response.writehead ( $, { 'Content-type':'image/jpg', 'Connection':'keep-alive' //or Close}) Response.End (IMG)}). Listen (8888) Console.log ('Server listening on 8888')
Test.html
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <Metaname= "Viewport"content= "Width=device-width, initial-scale=1.0"> <Metahttp-equiv= "X-ua-compatible"content= "Ie=edge"> <title>Document</title></Head><Body> <imgsrc= "/test1.jpg"alt=""> <imgsrc= "/test2.jpg"alt=""> <imgsrc= "/test3.jpg"alt=""> <imgsrc= "/test4.jpg"alt=""> <imgsrc= "/test5.jpg"alt=""> <imgsrc= "/test6.jpg"alt=""> <imgsrc= "/test7.jpg"alt=""> <imgsrc= "/test11.jpg"alt=""> <imgsrc= "/test12.jpg"alt=""> <imgsrc= "/test13.jpg"alt=""> <imgsrc= "/test14.jpg"alt=""> <imgsrc= "/test15.jpg"alt=""> <imgsrc= "/test16.jpg"alt=""> <imgsrc= "/test17.jpg"alt=""> <imgsrc= "/test111.jpg"alt=""> <imgsrc= "/test112.jpg"alt=""> <imgsrc= "/test113.jpg"alt=""> <imgsrc= "/test114.jpg"alt=""> <imgsrc= "/test115.jpg"alt=""> <imgsrc= "/test116.jpg"alt=""> <imgsrc= "/test117.jpg"alt=""></Body></HTML>
Test.jpg
Request Run Result:
HTTP various features application (ii)