[racket] #:headers not working with dispatch

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Tue Nov 19 10:35:43 EST 2013

Hi Guillaume,

Your code works exactly as expected, but you are not testing it properly.

"curl -I" sends a HEAD request, but your dispatch case only responds
to GET requests, because you have left out "#:method" and are using
the default as documented here:

http://docs.racket-lang.org/web-server/dispatch.html?q=dispatch-case#(form._((lib._web-server/dispatch..rkt)._dispatch-rules))

in the last paragraph.

If you run with "curl -v" then you'll send a GET request and see the
headers you expect

Jay



On Sun, Nov 17, 2013 at 9:37 AM, Guillaume Coré <g at fridim.org> wrote:
> Hi,
>
> Here is a simple case where #:headers works (working.rkt attached)
>
> Now the same thing but using dispatch (not_working.rkt attached) does
> not return the header. I'm a bit lost here.
>
>
> I was told on IRC to try to compare the return values of both (start)
> with/without dispatch. I did but both seems to return the expected header :
>
> (define (start request)
>   (response/xexpr (index request)
>                   #:headers (list (make-header #"Cache-Control"
> #"max-age=0"))))
>
> (define (start2 request)
>   (response/xexpr (site-dispatch request)
>                   #:headers (list (make-header #"Cache-Control"
> #"max-age=0"))))
>
>
> (define (url->request u)
>     (make-request #"GET" (string->url u) empty
>                   (delay empty) #f "1.2.3.4" 80 "4.3.2.1"))
>
> (response-headers (start (url->request "http://localhost:8000/")))
> ;-> '(#(struct:header #"Cache-Control" #"max-age=0"))
> (response-headers (start2 (url->request "http://localhost:8000/")))
> ;-> '(#(struct:header #"Cache-Control" #"max-age=0"))
>
> I'm using v5.90.0.10
>
> Any idea ?
>
> Regards,
> Guillaume
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.