Server class

A Web server.

When its run method is called, it listens for HTTP requests on the bindPort on its bindAddress, and responds to them with HTTP responses.

Each HTTP request is processed through the pipelines, which is a List of ServerPipeline objects. A ServerPipeline contains a sequence of rules (consisting of a pattern and a handler). If the request matches the pattern, the corresponding handler is invoked. If the handler returns a result it is used for the HTTP response, and subsequent handlers and pipelines are not examined. But if the pipeline has no matches or the matches do not return a result, then the next pipeline is examined. If after the request has been through all the pipelines without producing a result, a NotFoundException is thrown.

If an exception is thrown during processing (either by the application's callbacks or by the package's code) the exception handlers will be invoked. Normally, an application will set the server's exceptionHandler.

It is also possible to set exception handlers on each pipeline, to handle exceptions raised within that pipeline. If there is no pipeline exception handler, or it cannot handle the exception, the exception handler on the server will be invoked.

The urlMaxSize and postMaxSize define limits on the valid requests which can be processed. These are set to reasonable finite values to prevent some types of errors and denial-of-service attacks. Their values can be changed if the application needs to handle large HTTP requests.

A typical application will only have one instance of this class. But it is possible to create multiple instances of this class for an application to process HTTP requests from multiple ports/interfaces.

Constructors

Server({int numberOfPipelines = 1})
Constructor

Properties

basePath String
The base path under which all patterns are under.
getter/setter pair
bindAddress InternetAddress
Bind address for the server.
getter/setter pair
bindPort int
Port number for the server.
getter/setter pair
exceptionHandler ExceptionHandler
Server exception/error handler (high-level).
getter/setter pair
exceptionHandlerRaw ExceptionHandlerRaw
Server exception/error handler (low-level)
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
id String
Identity of the server.
getter/setter pair
isCustomExceptionHandler bool
Indicates if a custom exception handler has been set.
no setter
isCustomRawExceptionHandler bool
Indicates if a custom raw exception handler has been set.
no setter
isSecure bool
Indicates if the Web server is running secured HTTPS or unsecured HTTP.
no setter
numSessions int
Number of active sessions.
no setter
pipelines List<ServerPipeline>
The handler pipelines.
final
postMaxSize int
Maximum size of POST contents before it is rejected.
getter/setter pair
requestCreator RequestCreator
Function used to create a Request object for each HTTP request.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sessionCookieAlways bool
Use cookies to record sessions or not.
getter/setter pair
sessionCookieForceSecure bool
Force the use of secure cookies for the session cookie.
getter/setter pair
sessionCookieName String
The name of the cookie used to track sessions.
getter/setter pair
sessionParamName String
The name of the URL query parameter used to track sessions (if cookies are not used).
getter/setter pair
sessions Iterable<Session>
All active sessions
no setter
urlMaxSize int
Maximum size of a URL path and query before it is rejected.
getter/setter pair
v6Only bool
Indicates how an IPv6 bindAddress treats IPv4 addresses.
getter/setter pair

Methods

internalPath(String externalPath) String
Convert an external path to an internal path.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pipeline(String name) ServerPipeline
Retrieve a pipeline from the server by its name.
run() Future<int>
Starts the Web server with HTTP.
runTLS({required String privateKeyFilename, required String certificateName, required String certChainFilename}) Future<int>
Starts the Web server with HTTPS.
simulate(Request req) Future<SimulatedResponse>
Simulate the processing of a HTTP request.
stop({bool force = false}) Future
Stops the Web server.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited