manpagez: man pages & more
info bigloo
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.13 HTTP

bigloo procedure: http [:in #f] [:out #f] [:socket #f]

[:protocol ’http] [:method ’get] [:timeout 0] [:proxy #f] [:host "localhost"] [:port 80] [:path "/"] [:login #f] [:authorization #f] [:username #f] [:password #f] [:http-version "HTTP/1.1"] [:content-type #f] [:connection "close"] [:header ’((user-agent: "Mozilla/5.0"))] [:args ’()] [:body #f]

Opens an HTTP connection. Returns a socket.

It is an error to specify a header twice. In particular, it is illegal to re-define keyword-ed arguments in the :header list. For instance, it is illegal to include in the :header actual list value a value for the Connection HTTP connection.

(define (wget url)
   
   (define (parser ip status-code header clen tenc)
      (if (not (and (>=fx status-code 200) (<=fx status-code 299)))
	  (case status-code
	     ((401)
	      (raise (instantiate::&io-port-error
			(proc 'open-input-file)
			(msg "Cannot open URL, authentication required")
			(obj url))))
	     ((404)
	      (raise (instantiate::&io-file-not-found-error
			(proc 'open-input-file)
			(msg "Cannot open URL")
			(obj url))))
	     (else
	      (raise (instantiate::&io-port-error
			(proc 'open-input-file)
			(msg (format "Cannot open URL (~a)" status-code))
			(obj url)))))
	  (cond
	     ((not (input-port? ip))
	      (open-input-string ""))
	     (clen
	      (input-port-fill-barrier-set! ip (elong->fixnum clen))
	      ip)
	     (else
	      ip))))
   
   (multiple-value-bind (protocol login host port abspath)
      (url-parse url)
      (let* ((sock (http :host host :port port :login login :path abspath))
	     (ip (socket-input sock))
	     (op (socket-output sock)))
	 (with-handler
	    (lambda (e)
	       (if (isa? e &http-redirection)
                   (with-access::&http-redirection e (url)
		      (wget url))
		   (raise e)))
	    (read-string (http-parse-response ip op parser))))))

The optional argument args is used for post method. The actual value should be a list of lists. Each of these sublists must have two values:

  • the argument name
  • the argument actual value

The argument name can be either a string which is the name of the argument or a list of two elements. In that case, the first element of these list is the argument name. The second element should be a string that denotes additional parameter.

Example:

(http :host "localhost" :port 8080 :method 'post
   :header '((enctype: "multipart/form-data"))
   :args `(("x" "foo") (("foo.scm" "filename=\"foo.scm\"\nContent-type: application/octet-stream" ,(with-input-from-file "foo.scm" read-string))))
   ...)

An http connection blocks until the connection is established. If the optional argument timeout is provided, the connection must be established before the specified time interval elapses. The timeout is expressed in microseconds.

bigloo procedure: http-read-line input-port
bigloo procedure: http-read-crlf input-port

Reads a line or an end-of-line of an HTTP response.

bigloo procedure: http-parse-status-line input-port

Parses the status-line of an HTTP response. This returns a three values:

  • The http version
  • The status code
  • the explanation phrase
bigloo procedure: http-parse-header input-port output-port

Parses the whole header of an HTTP response. It returns multiple values which are:

  • the whole header as an alist.
  • the host given in the host header.
  • the port given host field.
  • the optional content-length header field.
  • the optional transfer-encoding header field.
  • the optional authorization header field.
  • the optional proxy-authorization header field.
  • the optional connection header field.
bigloo procedure: http-parse-response input-port output-port procedure

Parses the whole response of an HTTP request. The argument procedure is invoked with five arguments:

  • the input port to read the characters of the response,
  • the status code,
  • the header of the response,
  • the content length,
  • the type encoding.
bigloo procedure: http-response-body->port input-port output-port

Parses an HTTP response and build an output port that delivers the characters of the content.

bigloo procedure: http-chunks->procedure input-port
bigloo procedure: http-chunks->port input-port
bigloo procedure: http-send-chunks input-port output-port

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on March 31, 2014 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.