[REBOL] Re: HTTP response header
From: tim-johnsons:web at: 23-Mar-2006 16:23
* Hallvard Ystad <hallvard.ystad-gmail.com> [060323 14:40]:
That could be handy.
Thanks
Here's what I did:
get-html-response: def[ "Get HTML response headers."
request[url!] /with attr[word!] "get single header attribute"][
res: open request
either res[
either with
[probe res/locals/headers/:attr]
[probe res/locals]
close res
][none]
]
> (Sorry for duplicates of this email, if any)
>
> Dixit Tim Johnson (22.07 23.03.2006):
>
> Hi:
> Is there a way to get the HTTP response header?
>
> Here's the output from make money! .2 :
>
> You could have a look at this script from the rebol.org library:
>
http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=http-get.r&sid=k8wk
>
> ...or use the following script that I use, but it's based on
>
http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=url-handler.r:
>
> REBOL [
> Title: "URL fetcher returning both content and headers of a URL"
> File: %fetch-url.r
> Author: [ "HY" ]
> Date: 1-Jan-2005
> History: [
> 1-Jan-2005 {Extracted the function into it's own file.}
> ]
> ]
>
> do %url-handler.r
>
> fetch-url: func [ full-url [string! url!] /headers header-block /local site
> ] [
>
> to-fetch: url-handler to-string full-url
>
> if not headers [header-block: [connection: close] ]
>
> ;to-insert: rejoin [ "GET " to-fetch/as-string/from-path-only "
> HTTP/1.1^/Host: " to-fetch/host "^/" ]
> to-insert: rejoin [ "GET " to-fetch/as-string/from-path-only "
> HTTP/1.0^/Host: " to-fetch/host "^/" ]
>
> foreach [key value] header-block [
> append to-insert rejoin [ key ": " value "^/" ]
> ]
>
> append to-insert "^/"
>
> port: open/lines [
> scheme: 'tcp
> host: to-fetch/host
> port-id: 80
> ]
>
> print "[Vi sender:]"
> print form to-insert
>
> insert port to-insert
>
> header: make block! 10
> while [ not empty? reply: first port ] [
> parse reply [
> [copy name [thru #":"] (name: load name) | copy name [to end] (print
> form name)]
> [copy value to newline | copy value to end] (if value [append header
> reduce [name value]])
> ]
> ]
>
> either [ not empty? content: first port ] [content: copy port] [print
> "EMPTY!"]
>
> close port
>
> reduce [header content]
> ]
>
> a: fetch-url http://www.rebol.com/
>
> print mold first a
>
> print "^/^/===^/^/"
>
> ;print second a
> halt
> ; END OF SCRIPT
>
> HY
> Pr=E6tera censeo Carthaginem esse delendam
>
> --
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
Tim Johnson <tim-johnsons-web.com>
http://www.alaska-internet-solutions.com