Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to add custom cookies using martian and clj-http #84

Closed
bhougland18 opened this issue Apr 29, 2020 · 5 comments
Closed

how to add custom cookies using martian and clj-http #84

bhougland18 opened this issue Apr 29, 2020 · 5 comments

Comments

@bhougland18
Copy link

bhougland18 commented Apr 29, 2020

I apologize for submitting an issue for a question, but how would you add a clj-http cookiestore as an interceptor? I am assuming that is the correct way to accomplish this objective.

To do this using native clj-http one could do:

(def cs (clj-http.cookies/cookie-store))

(def http-client-response
(clj-http.client/get
"https://httpbin.org/cookies"
{:cookie-store cs})))

@oliyh
Copy link
Owner

oliyh commented May 4, 2020

Hi @bhougland18

I would approach it like this:

(defn with-cookie-store [cookie-store]
  {:name ::with-cookie-store
   :enter (fn [ctx]
            (assoc-in ctx [:request :cookie-store] cookie-store))})

(defn build-martian []
  (let [cookie-store (clj-http.cookies/cookie-store)]
    (martian.clj-http/bootstrap-swagger "http://swagger.com/swagger.json"
                                        {:interceptors (cons (with-cookie-store cookie-store)
                                                             martian.clj-http/default-interceptors))))

The entire map built up under the :request key is given to clj-http.client/request so by putting your cookie store in there it should work as required.

Hope this helps

@oliyh
Copy link
Owner

oliyh commented May 11, 2020

Hi @bhougland18 shall I close the issue?

@bhougland18
Copy link
Author

bhougland18 commented May 11, 2020 via email

@oliyh
Copy link
Owner

oliyh commented May 11, 2020

Great, thanks for letting me know.

@oliyh oliyh closed this as completed May 11, 2020
@tommy-mor
Copy link

This helped me, thank you for the snippet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants