

Running this: #lang racket
(require racket/runtime-path
web-server/http/id-cookie)
(define-runtime-path cookie-salt.bin "cookie-salt.bin")
(define cookie-salt (make-secret-salt/file cookie-salt.bin))
(make-id-cookie #"aname" #"avalue"
#:key cookie-salt)
gives me the error: ; expected: string?
; given: #"aname"
; in: an and/c case of
; the name argument of
; (->i
; ((name (and/c string? cookie-name?))
; (data-or-key
; (maybe-key)
; (if (unsupplied-arg? maybe-key)
; bytes?
; (and/c string? cookie-value?))))
Since the documentation of cookie-name?
says: > Returns #t if v is a valid cookie name (represented as a string or a byte string), #f otherwise. I expected using a byte-string to be ok.

The contract says (and/c string? cookie-name?))
so I see why, I get the error. But is it intentional?

Same goes for the value argument.

@soegaard2 Thanks for this report! When I updated web-server/http/id-cookie
to use the new net/cookies
with RFC 6265 support instead of the deprecated net/cookie
, there were some inconsistencies with what contracts allowed byte-strings (e.g. https://github.com/RenaissanceBug/racket-cookies/commit/c745ee51e9a4914d232380abe65332d91d88f7f8)—I expect I just missed this one when fixing them. I will open a GitHub issue and try to patch this soon, or you can if you want.

Go ahead!

The id-cookies are great btw.

Yes, I am a big fan.

Though FYI, @soegaard2, byte-strings are just immediately passed to bytes->string/utf-8
.

Oh? I thought, I could save a few conversion if I used byte-strings. The binding value is byte string, so I just passed it along unchanged.

cookie-name
and cookie-value
are guaranteed to produce strings, and net/cookies
manipulates them as strings internally: https://github.com/RenaissanceBug/racket-cookies/blob/master/net-cookies-lib/net/cookies/server.rkt

The headers must be byte strings?