File lib/lib/lib/lib/http_co.lua

HTTP requests using the socket_co library. Copyright (C) 2007 Wolfgang Oertl

Functions

_prepare_request_args (arg) Prepare parameters for a request
_shutdown_channel (arg) The channel is no longer needed, close it.
build_post_request (arg) Given a list of POST variables, produce a string suitable as body for a POST request.
expect_body (arg, code) Determine whether we should expect a body
get_cookies (arg, jar) Given the response of a request, try to identify cookies.
receive_body (arg) Read the whole body, using the appropriate decode function.
receive_headers (ioc, headers) Read the response headers.
receive_status_line (ioc) Read and parse an HTTP response
request (arg) Perform a complete HTTP request.
request_2 (arg) The connection has been established, now send the request and read the response.
request_co (arg) Start a request as new coroutine.
send_body (ioc, arg) Send the request body.
send_headers (ioc, ar) Send all the headers for this request in an unspecified order.
sink_file (arg, chunk) Write the body to a file.
sink_memory (arg, chunk) This sink collects the body in a variable.


Functions

_prepare_request_args (arg)
Prepare parameters for a request

Parameters

  • arg:
_shutdown_channel (arg)
The channel is no longer needed, close it.

Parameters

  • arg:
build_post_request (arg)
Given a list of POST variables, produce a string suitable as body for a POST request. XXX urlencoding not yet done

Parameters

  • arg:
expect_body (arg, code)
Determine whether we should expect a body

Parameters

  • arg:
  • code:
get_cookies (arg, jar)
Given the response of a request, try to identify cookies.

Parameters

  • arg: Request arguments
  • jar: A table what will be filled with cookies from the response headers in arg. key=name, value=value of cookie.

Return value:

nil
receive_body (arg)
Read the whole body, using the appropriate decode function.

Parameters

  • arg: Request structure

Return value:

1 or (nil, msg)
receive_headers (ioc, headers)
Read the response headers.

Parameters

  • ioc:
  • headers:
receive_status_line (ioc)
Read and parse an HTTP response

Parameters

  • ioc:
request (arg)
Perform a complete HTTP request. arg specifies all the parameters.

Parameters

  • arg: A table with all the named parameters as given below. @usage host the host to contact uri the URI to use in the GET/... request headers (optional) a table with key, value pairs for extra headers method (optional) the method source (optional) a source for the body of the request sink (optional) a sink to store the body of the result
request_2 (arg)
The connection has been established, now send the request and read the response.

Parameters

  • arg:
request_co (arg)
Start a request as new coroutine. No return value is given; instead, set the callback function in arg and/or a sink function. See request() for an explanation.

Parameters

  • arg:
send_body (ioc, arg)
Send the request body.

Parameters

  • ioc:
  • arg:
send_headers (ioc, ar)
Send all the headers for this request in an unspecified order. The first letter of the header names is converted to uppercase, this is more beautiful.

Parameters

  • ioc:
  • ar:
sink_file (arg, chunk)
Write the body to a file. Each call provides some more data; when called with NIL, this means the end of input -> close the file.

Parameters

  • arg:
  • chunk:
sink_memory (arg, chunk)
This sink collects the body in a variable. It is the default, unless you specify another function like this: request{sink=...}.

Parameters

  • arg:
  • chunk:

Valid XHTML 1.0!