<html><body><div>Hi, starting a project of mine, I've setup a dispatch rule and a function to return the response.<br>To make things simple, I've used response/output, with a lambda writing to the output-port.<br>However, I've got the error:<br><br><span style="font-size: 12px;">response/output: contract violation</span><br><span style="font-size: 12px;"> expected: void?</span><br><span style="font-size: 12px;"> given: 11</span><br><span style="font-size: 12px;"> in: the range of</span><br><span style="font-size: 12px;"> the 1st argument of</span><br><span style="font-size: 12px;"> (->*</span><br><span style="font-size: 12px;"> ((-> output-port? void?))</span><br><span style="font-size: 12px;"> (#:code</span><br><span style="font-size: 12px;"> number?</span><br><span style="font-size: 12px;"> #:headers</span><br><span style="font-size: 12px;"> (listof header?)</span><br><span style="font-size: 12px;"> #:message</span><br><span style="font-size: 12px;"> bytes?</span><br><span style="font-size: 12px;"> #:mime-type</span><br><span style="font-size: 12px;"> (or/c bytes? #f)</span><br><span style="font-size: 12px;"> #:seconds</span><br><span style="font-size: 12px;"> number?)</span><br><span style="font-size: 12px;"> response?)</span><br><span style="font-size: 12px;"> contract from: </span><br><span style="font-size: 12px;"> <pkgs>/web-server-lib/web-server/http/response-structs.rkt</span><br><span style="font-size: 12px;"> blaming: /home/amatheus/Dropbox/focus/todagendas/teste.rkt</span><br><span style="font-size: 12px;"> (assuming the contract is correct)</span><br><span style="font-size: 12px;"> at: <pkgs>/web-server-lib/web-server/http/response-structs.rkt:41.2</span><br><span style="font-size: 12px;"> context...:</span><br><span style="font-size: 12px;"> /usr/share/racket/collects/racket/contract/private/blame.rkt:143:0: raise-blame-error16</span><br><span style="font-size: 12px;"> /usr/share/racket/pkgs/web-server-lib/web-server/http/response.rkt:115:12</span><br><br>So I've tried to use a response, with the same lambda, and it worked.<br>From the error message, I changed the lambda to return (void) and then it worked.<br><br>I think maybe the contract is wrong but frankly I don't understand much about contracts.<br><br>I've setup some code that exposes the problem. Navigating to "/working" and "/fixed" works<br>fine; navigating to "/not-working" exposes the problem.<br><br>#lang racket<br>(require web-server/dispatch<br> web-server/servlet-env<br> net/url<br> web-server/http/request-structs<br> web-server/http/response-structs)<br><br>(define (not-working req)<br> (response/output (λ (op) (write-bytes #"Hello world" op))))<br><br>(define (working req)<br> (response<br> 301 #"OK"<br> (current-seconds) TEXT/HTML-MIME-TYPE<br> empty<br> (λ (op) (write-bytes #"Hello world" op))))<br><br>(define (fixed req)<br> (response/output (λ (op) (write-bytes #"Hello world" op) (void))))<br><br>(define (url->request u)<br> (make-request #"GET" (string->url u) empty<br> (delay empty) #f "1.2.3.4" 80 "4.3.2.1"))<br><br>(define-values (agenda-dispatch agenda-url)<br> (dispatch-rules<br> [("working") working]<br> [("not-working") not-working]<br> [("fixed") fixed]))<br><br>(define (main)<br> (serve/servlet agenda-dispatch<br> #:servlet-regexp #rx""<br> #:servlet-path ""))<br><br>(module+ main<br> (main))<br><br>The contracts in response-structs.rkt:<br><br>(provide/contract<br> [struct response<br> ([code number?]<br> [message bytes?]<br> [seconds number?]<br> [mime (or/c false/c bytes?)]<br> [headers (listof header?)]<br> [output (output-port? . -> . void)])]<br> [response/full (-> number? bytes? number? (or/c false/c bytes?) (listof header?) (listof bytes?) response?)]<br> [response/output (->* ((-> output-port? void?))<br> (#:code number?<br> #:message bytes?<br> #:seconds number?<br> #:mime-type (or/c bytes? #f)<br> #:headers (listof header?))<br> response?)]<br> [TEXT/HTML-MIME-TYPE bytes?])<br><br>Is the contract wrong or am I doing something weird?<br><br>Thanks,<br><br>André<br data-mce-bogus="1"></div></body></html>