use: (import (igropyr http))

server

procedure: (server get post set listen)

return: unspecified

server turn on the server listening.

The first two arguments to accept a callback procedure, who is run when the server received a GET and POST request.

like:(request do-when-request)

The second two arguments to accept a association list, the server will configured depending the list before open the listening.

The last two lists one is struct with the key of 'staticpath, 'connection and 'keepalive, and the other with the key of 'ip and 'port.

exemple for use server:

(server

(request do-when-get-request)

(request do-when-post-request)

(set)

(listen))

request

procedure: (request callback)

(func list -> string -> string -> string) -> nothing

request accept a procedure that takes three arguments as a callback.

When a GET request received, request will passe three arguments (request_header, path_info, query_string) to the callback.

When a POST request received, request will passe three arguments (request_header, path_info, payload) to the callback.

This callback must return a string which include a standard http header then request calls the Igropyr's C functionl to send it back to client.

response

procedure: (response status type content)

int -> string -> string / list -> string

response accepts three parameters: http status code, return type and content, which status must be a number, type must be a string.

When content is a list, the first element will seted as cookie and the second will seted as response content.

When content is a string, it will send as response content with a empty cookie.

response format these information to a stirng with a standard http header, prepare to use for the request. Usually use to build the callback of request.

sendfile

procedure: (sendfile type path_file)

return: string

sendfile accepts two parameters: MIME type and path_file.

When type is "", the MIME type is automatelly detected.

sendfile usually use to build the callback of request.

set

procedure: (set (name value) ...)

return: association list

set accepts any number of s-expressions which is used to configure server settings.

Valid values ​​for name are:

'staticpath is used to set the server static file path. The corresponding value is string, the default value is"".

'connection is used to set the maximum number of connections. The corresponding value is int, the default value is 1024

'keepalive is used to set the server keep-alive timeout. Corresponding to the value is int, the default value is 5000 (ms), 0 for close the long connections.

The missing settings automatically apply defaults.

listen

procedure: (listen)

procedure: (listen ip)

procedure: (listen port)

procedure: (listen ip port)

return: association list

listen accepts zero to two arguments to set the ip and port that server listen on.

When listen accepts a string argument, its value is used to set the ip.

When listen accepts a int parameter, its value is used to set the port.

When listen accepts two parameters, the values is used to set the listen ip and port by order.

The missing settings automatically apply defaults:ip: 0.0.0.0 port: 80

errorpage

procedure: (errorpage error_code)

procedure: (errorpage error_code error_info)

return: string

errorpage accepts one or two arguments, the first arguments is the status code, the second arguments is an error message.

errorpage Returns prepare a string with standard http headers for easily return error page to the client.

par

procedure: (par router_path request_path)

return: boolean

par is an efficient string fuzzy comparison procedure.

Its first argument accepts the path set by the router, and the second argument accepts the request path.

When the first argument contains "*", the second argument is ignored from the "*" character to the next "/" sign.

so:

(par "/foo" "/foo") => #t

(par "/foo" "/bar") => #f

(par "/*" "/foo") => #t

(par "/foo/*" "/foo/bar") => #t

(par "/*/bar" "/foo/bar") => #t

(par "/f*/bar" "/foo/bar") => #t

(par "/f*/bar" "/boo/bar") => #f

(par "/foo/b*" "/foo/bar") => #t

(par "/foo/b*" "/foo/far") => #f

header-parser

procedure: (header-parser header key)

return: string

header-parser is an efficient implementation for finding the corresponding value in the http-header.

path-parser

procedure: (header-parser path index)

return: string

path-parser return the specific element in the path.

(path-parser "/foo/bar/baz" 0) => "foo"

(path-parser "/foo/bar/baz" 1) => "bar"

(path-parser "/foo/bar/baz" 2) => "baz"

(path-parser "/foo/bar/baz" 3) => ""

results matching ""

    No results matching ""