Question

Is there an easier way of getting the content of an HTTP 404 response than directly accessing the host via tcp?

This is a sample of a 404 response with content:

HTTP/1.1 404 Object Not Found
Server: CouchDB/1.3.0 (Erlang OTP/R15B03)
Date: Wed, 24 Jul 2013 08:32:50 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 41
Cache-Control: must-revalidate

{"error":"not_found","reason":"missing"}
Was it helpful?

Solution

The Rebol HTTP scheme really isn't designed with this in mind, it's geared toward reading content the way you would in a browser, not services over HTTP.

In saying that, you can hack the protocol to subvert how Rebol 2 handles different response codes:

in-http-scheme: func [does [block!]][
    do bind :does bind? last body-of get in system/schemes/http/handler 'open
]

in-http-scheme [
    remove-each [code response] response-actions [find [400 403 404] code]
    append response-actions [400 success 403 success 404 success]
]

The caveat here is that the HTTP protocol has to have been initiated (any http port opened/read). response-actions can still be accessed when http has not been initiated:

select body-of get in system/schemes/http/handler 'open quote response-actions:

You can get the last response line thus:

in-http-scheme [response-line]

Alternatively you are going to need a scheme designed for services over HTTP. I have a REST protocol (two versions, one that uses cURL, and one that uses a customised HTTP scheme that works, but isn't as good). Though are for Rebol 2. I have plans for a Rebol 3 version.

OTHER TIPS

Christopher Ross-Gill has created a REST protocol for Rebol which allows simple access to all headers and even handles OAuth. Have a look at the details here.

http://www.ross-gill.com/page/REST_Protocol

Unfortunately it is only for Rebol 2 at the moment and it depends on the use of curl for the http requests.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top