-
Notifications
You must be signed in to change notification settings - Fork 0
/
http2test.js
28 lines (26 loc) · 927 Bytes
/
http2test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* @author: Jason.占友伟 [email protected]
* Created on 16/3/9.
*/
var http2 = require('http2');
var fs = require('fs');
var options = {
key: fs.readFileSync(__dirname + '/tsl/server.pass.key'),
cert: fs.readFileSync(__dirname + '/tsl/server.crt'),
NPNProtocols: ['h2', 'http 1.1', 'http 1.0'],
passphrase: '1234'
};
http2.createServer(options, function (request, response) {
var url = request.url;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
response.setHeader("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
response.setHeader("X-Powered-By", ' 3.2.1');
if (url === '/') {
response.end('Hello! This is HTTP2 Server!');
} else if (url === '/http2test') {
setTimeout(function () {
response.end('http2 success');
}, 300);
}
}).listen(8080);