This module provides a HTTP server based on Pythonesk dispatch of
a server object. The class of the server object need only
implement a predicate dispatch/4 with the Pythonesk convention
that the receiver appears in the first argument. The server can be
started by providing the server object that will be responsible
for handling HTTP requests:

?- run_http(<object>, <port>), fail; true.

The server currently implements a minimal subset of the HTTP/1.1
protocol restricted to GET method. The server will read the
request line and the header lines. The server is able to generate
error messages through the predicate dispatch_error/2. The server
will generate a 404 error when dispatch/4 failed. The following
HTTP/1.1 errors have been realized:

The predicate http_parameter/3 can be used by the server object
to access URI query parame-ters. The predicates response_text/3,
response_binary/3 and html_escape/2 can be used to generate
dynamic content by the server object. The predicates
dispatch_text/3 and dispatch_binary/3 can be used by the server
object to deliver static content.

101 Switching Protocols: Server object can start web
socket worker.

200 Ok: Server object delivers content and optionally
meta-data.

302 Found: Server object redirects to new location.

304 Not Modified: Server object notifies that
meta-data did not change.

The web server also supports the above HTTP/1.1 codes, which
might have additional response headers. The predicate
dispatch_upgrade/2 will automatically generate a web socket accept
key and can be used to implement upgrade/4. The predicate
dispatch_redirect/2 requires a location, whereas the predicate
dispatch_head/2 requires meta-data.

The following HTTP server predicates are provided:

run_http(O, P):

The predicate runs a web server with object O at port P.

http_parameter(R, N, V):

The predicate succeeds in V with the value of the parameter
named N from the request R.

http_header(R, N, V):

The predicate succeeds in V with the value of the header named
N from the request R.

dispatch_error(E, O):

The predicate sends the error code E to the socket O. The
error codes from 4xx and 5xx are supported.