write-bytes returns a number http://docs.racket-lang.org/reference/Byte_and_String_Output.html?q=write-bytes#%28def._%28%28quote._~23~25kernel%29._write-bytes%29%29
and response/output expects the function to return void? http://docs.racket-lang.org/web-server/http.html?q=response%2Foutput#%28def._%28%28lib._web-server%2Fhttp%2Fresponse-structs..rkt%29._response%2Foutput%29%29 On Thu, Oct 20, 2016 at 7:45 AM, Craig Allen <cjalle...@gmail.com> wrote: > Hi guys, > > I'm trying to serve a file using a restful API via dispatcher. The file is > being served but I'm also getting some funky contract errors that I don't > really understand. > > The function is > > (define (generate-zip-response zip-path) > (let* ([size-bs (string->bytes/utf-8 (number->string (file-size > zip-path)))] > [zip-binary (file->bytes zip-path)] > [patch-name-bs (string->bytes/utf-8 patch-name)]) > (response/output > #:mime-type #"application/octet-stream" > #:headers > (list (make-header #"Content-Disposition" > (bytes-append #"attachment; filename=\"" > patch-name-bs #".zip\"")) > (make-header #"Content-Transfer-Encoding" #"binary") > (make-header #"Content-Length" size-bs)) > (lambda (output) (write-bytes zip-binary output))))) > > and the contract error which is printed whenever a file is served is: > > response/output: contract violation > expected: void? > given: 2113471 > in: the range of > the 1st argument of > (->* > ((-> output-port? void?)) > (#:code > number? > #:headers > (listof header?) > #:message > bytes? > #:mime-type > (or/c bytes? #f) > #:seconds > number?) > response?) > contract from: > <pkgs>/web-server-lib/web-server/http/response-structs.rkt > blaming: C:\builder\server-dispatch.rkt > (assuming the contract is correct) > at: <pkgs>/web-server-lib/web-server/http/response-structs.rkt:41.2 > > where 2113471 is the size of the file I am serving. > > Any pointers would be helpful, > > Cheers, > > Craig > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- Jay McCarthy Associate Professor PLT @ CS @ UMass Lowell http://jeapostrophe.github.io "Wherefore, be not weary in well-doing, for ye are laying the foundation of a great work. And out of small things proceedeth that which is great." - D&C 64:33 -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.