TLDR; How to store use HTTP cookies across multiple requests in an HTTP client?
----
I'm trying to fetch a URL and, say, print the cookies it sets.

Fetching a URL is easily done with `call/input-url`, however it doesn't handle 
HTTP response headers (incl. cookies).
There are `http-conn-open`, `http-conn-send!` and `http-conn-recv!` which, 
happily, let one do all sorts of stuff with HTTP request/response headers.  
Trying to combine them[1] with net-cookies[2], nothing gets set in the cookie 
jar[3].  I tried printing all HTTP response headers to check for cookies but 
there were no "Set-Cookie" headers.

So, what am I doing wrong here? I'd appreciate any hint/help on this.

[1] 
    (let [(conn (http-conn-open SOME_URL #:ssl? #t))]
        (http-conn-send! conn SOME_URI
                         #:method #"POST"
                         #:data post-data)
        (let-values ([(status-line header-list inport) (http-conn-recv! conn)])
          (extract-and-save-cookies!
           (map (λ (x)
                  ;;; I have a feeling this could have been done better.
                  (let [(hs (string-split (bytes->string/latin-1 x) ":"))]
                    (cons (string->bytes/latin-1 (first hs))
                          (string->bytes/latin-1 (second hs)))))
                header-list)
           (string->url SOME_URL))))

[2] http://pkg-build.racket-lang.org/doc/cookies/index.html
[3] (cookie-header SOME-URL) => #f

-- 
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.

Reply via email to