Object built-in object

Object HttpServer

http server object

http server object is an object that encapsulates TcpServer and HttpHandler combination, which is convenient for quickly setting up a server, and is logically equivalent to:

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

How to create:

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

Inheritance

Constructor

HttpServer

HttpServer constructor, listening on 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 mq.Handler details

HttpServer constructor

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

Call parameters:

  • addr : String, specify the listening address of the http server, if "", listen at 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 mq.Handler details

Member attribute

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 body size, 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 Socket object the server is currently listening to

1
readonly Socket HttpServer.socket;

handler

Handler , the current event processing interface object of the server

1
Handler HttpServer.handler;

Member function

enableCrossOrigin

Allow cross-domain requests

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

Call parameters:

  • allowHeaders : String, specifies the accepted http header fields

start

Start current server

1
HttpServer.start();

stop

Close the socket to stop the running server

1
HttpServer.stop() async;

toString

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

1
String HttpServer.toString();

Return result:

  • String , returns a string representation of the object

toJSON

Returns the JSON 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