woomera library
Package for implementing Web servers.
HTTP request dispatcher with session management.
Usage
A Web server can be created by:
- Create an instance of Server.
- Getting the ServerPipeline that was created by the server.
- Define handlers for HTTP requests and exception handlers for the pipeline.
- Call the Server.run method on the server.
Simulated HTTP requests for testing
Instead of invoking run
on the server, the Server.simulate method
can be used to test the server.
Create a simulated HTTP request using Request.simulatedGet, Request.simulatedPost or Request.simulated and then pass it to the server's simulate method. The response can then be tested for the expected HTTP response.
This type of testing can be used to supplement testing with a Web browser. It has the advantage of running faster than automating the actions of a Web browser, but it also has the disadvantge that it cannot execute any client-side JavaScript.
Multiple pipelines
Usually, the one ServerPipeline automatically created by the server is sufficient.
For some situations, multiple pipelines can be useful. For example, when it is useful to have a different exception handler for some rules.
Logging
The Logger package is used for logging. The available loggers are named:
- woomera.server
- woomera.request
- woomera.request.header
- woomera.request.param
- woomera.response
- woomera.session
- woomera.static_file - static file handler
- woomera.proxy - proxy handler
Classes
- HEsc
- HTML escaping methods for escaping values for output in HTML. [...]
- Proxy
- Handler for proxying requests to another server. [...]
- Request
- Request class.
- RequestParams
- Represents a collection of parameters. [...]
- RequestParamsMutable
- A mutable RequestParams. [...]
- Response
- Abstract base class for a response. [...]
- ResponseBuffered
- A response where the contents is buffered text. [...]
- ResponseRedirect
- HTTP response that redirects the browser to a URL.
- ResponseStream
- A response where the contents come from a stream. [...]
- Server
- A Web server. [...]
- ServerPipeline
- A pipeline. [...]
- ServerRule
- Represents a rule for processing HTTP requests. [...]
- Session
- Session that is maintained between HTTP requests. [...]
- SimulatedHttpHeaders
- Headers in a simulated request or response
- SimulatedResponse
- Response returned by simulations. [...]
- StaticFiles
- Handler for returning static files and directory listings. [...]
Functions
-
debugHandler(
Request req) → Future< Response> - Request handler which shows out the request parameters to the client. [...]
Enums
- SessionTermination
- Reasons why a session was terminated. [...]
Typedefs
-
ExceptionHandler(
Request r, Object ex, StackTrace st) → Future< Response> - Exception/error handler function type. [...]
-
RequestCreator(
HttpRequest request, String id, Server server) → FutureOr< Request> - Type for a request factory. [...]
-
RequestFactory(
HttpRequest request, String id, Server server) → FutureOr< Request> - Use RequestCreator typedef instead. [...]
-
RequestHandler(
Request req) → Future< Response> - HTTP request handler function type. [...]
Exceptions / Errors
- ExceptionHandlerException
- Exception indicating an exception/error occurred in an exception handler. [...]
- MalformedPathException
- Exception indicating malformed request. [...]
- NotFoundException
- Exception indicating a response could not be created.
- PathTooLongException
- Exception indicating the URL path is too large. [...]
- PostTooLongException
- Exception indicating the contents of the POST request is too large. [...]
- ProxyHandlerException
- Exception indicating an exception/error occurred in the proxy handler.
- WoomeraException
- Base class for all exceptions defined in the Woomera package.