http.lsp

Module index

source

Module: Http

Author: Jeff Ober
Version: beta
Location: http://static.artfulcode.net/newlisp/http.lsp

A bare-bones HTTP 1.0 library.

Http is an extremely bare-bones HTTP 1.0 library. Not all functionality is implemented. In particular, the ability to parse an HTTP response is not yet finished, but the ability to parse requests and send both requests and responses is finished.

This module has not been rigorously tested. Your mileage may vary.

- § -

Http:parse-request

syntax: (Http:parse-request str-request)
parameter: str-request - an HTTP request received

Parses an HTTP request and returns an association list.

example:
 (parse-request
   (format-request "POST"
                   "/cgi-bin/post_comment.cgi"
                   '(("Host" "www.somesite.com"))
                   "name=Some+Person&comment=Hello+world!"))

 => (("method" "POST")
     ("path" "/cgi-bin/post_comment.cgi")
     ("http-version" "1.0")
     ("headers" (("host" "www.somesite.com")
                 ("content-length" "37") nil)) 
     ("content" ""))

- § -

Http:format-response

syntax: (Http:format-response str-response [int-code [str-content-type [assoc-headers]]])
parameter: str-response - the text of the HTTP response
parameter: int-code - the HTTP response code; default is 200 (success)
parameter: str-content-type - MIME type of response; default is "text/html"
parameter: assoc-headers - association list of headers to add to response

Formats an HTTP/1.0 response.

example:
 (format-request "POST"
                 "/cgi-bin/post_comment.cgi"
                 '(("Host" "www.somesite.com"))
                 "name=Some+Person&comment=Hello+world!"))
 => "HTTP/1.0 200 OK\r\nConnection: close\r\nContent-Type: text/html\r\nDate: Tue, 08 Jul 2008 10:28:03 EDT\r\nContent-Length: 46\r\n\r\n<html><body><h1>Hello world</h2></body></html>"
 
 (format-response binary-file-content 200 "audio/mp3")
 => "HTTP/1.0 200 OK\r\nConnection: close\r\nContent-Type: audio/mp3\r\nDate: Tue, 08 Jul 2008 10:30:09 EDT\r\nContent-Length: 17\r\n\r\n11000101010101..."

- § -

Http:format-request

syntax: (Http:format-request str-method [str-path [assoc-headers [str-content]]])
parameter: str-method - request method (GET, POST, HEAD, or PUT)
parameter: str-path - request path; default is "/"
parameter: assoc-headers - association list of headers to add to request
parameter: str-content - for POST and PUT methods, string containing request content

Formats an appropriate HTTP/1.0 request. Note that you explicitly add the "Host" header if required.

example:
 (format-request "POST"
                 "/cgi-bin/post_comment.cgi"
                 '(("Host" "www.somesite.com"))
                 "name=Some+Person&comment=Hello+world!")
 => "POST /cgi-bin/post_comment.cgi HTTP/1.0\r\nHost: www.somesite.com\r\nContent-Length: 37\r\n\r\nname=Some+Person&comment=Hello+world!\r\n\r\n"

- ∂ -

Artful Code

generated with newLISP  and newLISPdoc
eXTReMe Tracker