Fork me on GitHub
#clj-http
<
2022-05-10
>
Bhougland12:05:56

How can I accept these cookies:

Bhougland12:05:58

May 10, 2022 8:23:08 AM org.apache.http.client.protocol.ResponseProcessCookies processCookies WARNING: Invalid cookie header: "Set-Cookie: AWSALB=LTy2kdai5cSMLrDecSgJBGmKDPDBTIYsW8Uky4skVcYsib8IOeNivSDURlsNo40qx2q296dErIJ0ar3/FbGy7wBZfaCFJY2M5XRUIgNsAC50nK0Y886/v42ha0WJ; Expires=Tue, 17 May 2022 12:23:09 GMT; Path=/". Invalid 'expires' attribute: Tue, 17 May 2022 12:23:09 GMT May 10, 2022 8:23:08 AM org.apache.http.client.protocol.ResponseProcessCookies processCookies WARNING: Invalid cookie header: "Set-Cookie: AWSALBCORS=LTy2kdai5cSMLrDecSgJBGmKDPDBTIYsW8Uky4skVcYsib8IOeNivSDURlsNo40qx2q296dErIJ0ar3/FbGy7wBZfaCFJY2M5XRUIgNsAC50nK0Y886/v42ha0WJ; Expires=Tue, 17 May 2022 12:23:09 GMT; Path=/; SameSite=None; Secure". Invalid 'expires' attribute: Tue, 17 May 2022 12:23:09 GMT

jumar12:05:36

It looks like the cookie spec is hardcoded here in clj-http: https://github.com/dakrone/clj-http/blob/3.x/src/clj_http/cookies.clj#L13-L16 Do you use clj-http on the client you need it to process / set cookies on the client?

Bhougland12:05:46

I am building a client application that will use Openapi to send updates to the server.

Bhougland12:05:12

Setting these cookies is required for the SAML2 authentication

jumar12:05:45

I'm not sure how to do it with clj-http but in https://github.com/elastic/support-diagnostics/issues/233 they suggest using this:

HttpClient httpClient = HttpClients.custom()
        .setDefaultRequestConfig(RequestConfig.custom()
                .setCookieSpec(CookieSpecs.STANDARD).build())
        .build();
But redefine cookie-spec ?

Bhougland13:05:20

;; Cookies can be completely configurable with a custom spec by adding a
;; function to return a cookie spec for parsing the cookie. For example, if you
;; wanted to configure a spec provider to have a certain compatibility level:
(client/post ""
             {:cookie-spec
              (fn [http-context]
                (println "generating a new cookie spec")
                (.create
                 (org.apache.http.impl.cookie.RFC6265CookieSpecProvider.
                  org.apache.http.impl.cookie.RFC6265CookieSpecProvider$CompatibilityLevel/IE_MEDIUM_SECURITY
                  (PublicSuffixMatcherLoader/getDefault))
                 http-context))})
;; Or a version with relaxed compatibility
(client/post ""
             {:cookie-spec
              (fn [http-context]
                (println "generating a new cookie spec")
                (.create
                 (org.apache.http.impl.cookie.RFC6265CookieSpecProvider.
                  org.apache.http.impl.cookie.RFC6265CookieSpecProvider$CompatibilityLevel/RELAXED
                  (PublicSuffixMatcherLoader/getDefault))
                 http-context))})

jumar13:05:50

Ah, nice!

Bhougland13:05:54

I guess I just don't know Java well enough to know how to use this :cookie-spec to achive the answer the guy gave on github

Bhougland13:05:15

or Clojure for that matter (I am a newb)

jumar13:05:01

Hmm, I got an expected answer?

(require '[clj-http.cookies :as http-cookies])
(http-cookies/decode-cookie
 "Set-Cookie: AWSALB=LTy2kdai5cSMLrDecSgJBGmKDPDBTIYsW8Uky4skVcYsib8IOeNivSDURlsNo40qx2q296dErIJ0ar3/FbGy7wBZfaCFJY2M5XRUIgNsAC50nK0Y886/v42ha0WJ; Expires=Tue, 17 May 2022 12:23:09 GMT; Path=/")
;; => ["Set-Cookie: AWSALB" {:discard false, :expires #inst "2022-05-17T12:23:09.000-00:00", :path "/", :secure false, :value "LTy2kdai5cSMLrDecSgJBGmKDPDBTIYsW8Uky4skVcYsib8IOeNivSDURlsNo40qx2q296dErIJ0ar3/FbGy7wBZfaCFJY2M5XRUIgNsAC50nK0Y886/v42ha0WJ", :version 0}]

jumar13:05:22

which version of clj-http are you using?

Bhougland13:05:19

clj-http "3.12.3"
it happens when I am using the cookie-store feature

Bhougland13:05:55

This set cookies is being returned in the response

jumar13:05:33

What you shared above I think should do the job. It looks very similar to cookie-spec function used by clj-http.

jumar13:05:54

I would just use this:

(defn cookie-spec ^org.apache.http.cookie.CookieSpec [http-context]
  (.create
   (RFC6265CookieSpecProvider.)
   http-context
   #_(BasicHttpContext.)))

(http/get ""
          {:cookie-spec cookie-spec})

Bhougland13:05:47

I will give this a whirl. I really want to thank you for your time!

jumar13:05:05

No problem, I didn't help that much O:-)

Bhougland13:05:42

Syntax error (IllegalArgumentException) compiling new at (C:\Users\benja\AppData\Local\Temp\form-init16040719483634482323.clj:8:5). Unable to resolve classname: RFC6265CookieSpecProvider

Bhougland13:05:10

Yea!! Thank you so much, I verified that the cookies made it to the cookie-store and I wasn't presented with any warnings.

Bhougland12:05:43

I don't understand the cookie-policy documentation

Bhougland12:05:40

I did see someone else in the Java world also ran into this issue here: https://github.com/elastic/support-diagnostics/issues/233