|
|
OVERVIEW |
|
|
|
|
EXAMPLES |
|
|
|
|
COMPONENTS |
|
|
|
|
RELATED |
|
|
|
|
HTTP
HTTP is a package that enable SICStus developers to use the web
as interface to their programs.
The package consist of the following modules:
- http_server - a simple web server where pages can be registered
- http - interface to access HTTP requests and respond to them
- webfile - a simple file server
Using the HTTP server
Initialization
- set_default_port(?Port) - sets the port to use for the web server.
This must be set before the server is started. An uninstantiated variable
means any free port.
- register_page(+Page,+Handler) - registers a page and its
HTTP handler. The handler will be called for each HTTP request accessing a
path starting with the specified path.
- unregister_page(+Page,+Handler) - unregisters the specified page
HTTP handler
- http_request(+HttpRequest,+HttpResponse) - called whenever a
HTTP request is made to the page registered with the handler and is
responsible to respond to the request.
The handler uses the module http to access information in the request
and respond to it.
The module http
HTTP Authentication
With the HTTP server it is simple to use basic authentication to
authenticate users.
- Extract authorization information from the request:
http:authorization(HttpRequest,basic,BasicCookie)
- Decode the base64 encoded cookie:
base64:b64decode(BasicCookie,UserInfo)
- Extract the user and password from the user information:
lists:append(User,[0':|Password],UserInfo)
- Check that the user name and password are correct
If any of the above steps fails, the user is not authenticated and
a challenge must be sent:
AuthField = field('WWW-Authenticate',"Basic realm=\"Test Authentication\""),
http:send_error(HttpResponse,unauthorized,[AuthField])
| Note that basic authentication transmitts any passwords over
Internet in plain text. | |
|
Webfile
Webfile uses the HTTP server to return static files from any specified
file directory.
- add_page(+Page,+Directory) - adds a directory from which
files are served whenever a HTTP request is made with a path starting
with the specified page.
- remove_page(+Page) - removes the specified page and its directory
Example
The code of a simple web server example can be found here:
webserver.pl
|
|