[racket] #:headers not working with dispatch

From: Guillaume Coré (g at fridim.org)
Date: Sun Nov 17 11:37:14 EST 2013

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
-------------- next part --------------
#lang racket/base

(require web-server/servlet-env
         web-server/templates
         web-server/dispatch
         web-server/servlet)

(define (index req)
  `(p "blabla"))

(define (start request)
  (response/xexpr (index request)
                  #:headers (list (make-header #"Cache-Control" #"max-age=0"))))
(module+ main
         (serve/servlet start
                        #:servlet-path "/"
                        #:servlet-regexp #rx""
                        #:log-file "server.log"
                        #:listen-ip "0.0.0.0"
                        #:launch-browser? #f
                        #:extra-files-paths
                        (list
                          (build-path "htdocs"))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ===>
; $ curl -I localhost:8000/
; HTTP/1.1 200 Okay
; Date: Sun, 17 Nov 2013 16:15:16 GMT
; Last-Modified: Sun, 17 Nov 2013 16:15:16 GMT
; Server: Racket
; Content-Type: text/html; charset=utf-8
; Cache-Control: max-age=0
; Transfer-Encoding: chunked
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-------------- next part --------------
#lang racket/base

(require web-server/servlet-env
         web-server/templates
         web-server/dispatch
         web-server/servlet)


(define-values (site-dispatch site-url)
  (dispatch-rules
    [("") index]))

(define (index req)
  `(p "blabla"))

(define (start request)
  (response/xexpr (site-dispatch request)
                  #:headers (list (make-header #"Cache-Control" #"max-age=0"))))

(module+ main
         (serve/servlet start
                        #:servlet-path "/"
                        #:servlet-regexp #rx""
                        #:log-file "server.log"
                        #:listen-ip "0.0.0.0"
                        #:launch-browser? #f
                        #:extra-files-paths
                        (list
                          (build-path "htdocs"))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ===>
; $ curl -I localhost:8000/
; HTTP/1.1 200 OK
; Date: Sun, 17 Nov 2013 16:16:13 GMT
; Last-Modified: Wed, 13 Nov 2013 07:02:12 GMT
; Server: Racket
; Content-Type: text/html
; Accept-Ranges: bytes
; Content-Length: 853
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 555 bytes
Desc: OpenPGP digital signature
URL: <http://lists.racket-lang.org/users/archive/attachments/20131117/f3962658/attachment-0001.sig>

Posted on the users mailing list.