| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.12 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] [:header '((user-agent: "Mozilla/5.0"))] [:args '()] [:body #f]
Opens an HTTP connection. Returns a socket.
(define (wget urt) (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 (string-append "http://" string))))) ((404) (raise (instantiate::&io-file-not-found-error (proc 'open-input-file) (msg "Cannot open URL") (obj (string-append "http://" string))))) (else (raise (instantiate::&io-port-error (proc 'open-input-file) (msg (format "Cannot open URL (~a)" status-code)) (obj (string-append "http://" string)))))) (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 (&http-redirection? e) (wget (&http-redirection-url e)) (raise e))) (read-string (http-parse-response ip op parser))))))
- 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. This is an alist.
- 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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
