Object built-in object

Object HttpServer

http Server object

http The server object is TcpServer with HttpHandler Combining encapsulated objects makes it convenient to quickly build a server, which is logically equivalent to:

1 2 3
var svr = new net.TcpServer(addr, port, new http.Handler(function(req) { ... }));

Creation method:

1 2 3 4
var http = require("http"); var svr = new http.Server(80, function(req) { ... });

Inheritance

#lineWidth: 1.5 #font: Helvetica,sans-Serif #fontSize: 10 #leading: 1.6 #.this: fill=lightgray #.class: fill=white [<class>object|toString();toJSON()] [<class>TcpServer|new TcpServer()|socket;handler|start();stop()] [<this>HttpServer|new HttpServer()|maxHeadersCount;maxBodySize;serverName|enableCrossOrigin()] [<class>HttpsServer] [object] <:- [TcpServer] [TcpServer] <:- [HttpServer] [HttpServer] <:- [HttpsServer] TcpServer new TcpServer() socket handler start() stop() HttpServer new HttpServer() maxHeadersCount maxBodySize serverName enableCrossOrigin() object toString() toJSON() HttpsServer

Constructor

HttpServer

HttpServer constructor, listening at all local addresses

1 2
new HttpServer(Integer port, Handler hdlr);

Call parameters:

  • port: Integer, specify http Server listening port
  • hdlr: Handler, http Built-in message processor, processing function, chain processing array, routing object, see details mq.Handler

HttpServer constructor

1 2 3
new HttpServer(String addr, Integer port, Handler hdlr);

Call parameters:

  • addr: String, specify http Server listening address, "" means listening on all addresses of this machine
  • port: Integer, specify http Server listening port
  • hdlr: Handler, http Built-in message processor, processing function, chain processing array, routing object, see details mq.Handler

HttpServer constructor

1 2
new HttpServer(String addr, Handler hdlr);

Call parameters:

  • addr: String, specify http Server listening address, "" means listening on all addresses of this machine
  • hdlr: Handler, http Built-in message processor, processing function, chain processing array, routing object, see details mq.Handler

Member attributes

maxHeadersCount

Integer, query and set the maximum number of request headers, the default is 128

1
Integer HttpServer.maxHeadersCount;

maxBodySize

Integer, query and set the maximum size of the body, in MB, the default is 64

1
Integer HttpServer.maxBodySize;

serverName

String, query and set the server name, the default is: fibjs/0.x.0

1
String HttpServer.serverName;

socket

Socket, The server is currently listening Socket Object

1
readonly Socket HttpServer.socket;

handler

Handler, Server current event processing interface object

1
Handler HttpServer.handler;

Member function

enableCrossOrigin

Allow cross-domain requests

1
HttpServer.enableCrossOrigin(String allowHeaders = "Content-Type");

Call parameters:

  • allowHeaders: String, specified to accept http Header field

start

Start the current server

1
HttpServer.start();

stop

Close the socket to terminate the running server

1
HttpServer.stop() async;

toString

Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics

1
String HttpServer.toString();

Return result:

  • String, Returns the string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object

1
Value HttpServer.toJSON(String key = "");

Call parameters:

  • key: String, unused

Return result:

  • Value, Returns a value containing JSON serializable