How can I accept these cookies:
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
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?
I am building a client application that will use Openapi to send updates to the server.
Setting these cookies is required for the SAML2 authentication
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 ?;; 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))})
Ah, nice!
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
or Clojure for that matter (I am a newb)
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}]
which version of clj-http are you using?
clj-http "3.12.3"
it happens when I am using the cookie-store featureThis set cookies is being returned in the response
What you shared above I think should do the job.
It looks very similar to cookie-spec function used by clj-http.
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})
I will give this a whirl. I really want to thank you for your time!
No problem, I didn't help that much O:-)
Syntax error (IllegalArgumentException) compiling new at (C:\Users\benja\AppData\Local\Temp\form-init16040719483634482323.clj:8:5). Unable to resolve classname: RFC6265CookieSpecProvider
Oh, you need to import it first: here's my code: https://github.com/jumarko/clojure-experiments/blob/master/src/clojure_experiments/networking.clj#L96-L113 The import: https://github.com/jumarko/clojure-experiments/blob/master/src/clojure_experiments/networking.clj#L11-L13
Yea!! Thank you so much, I verified that the cookies made it to the cookie-store and I wasn't presented with any warnings.
👍
I don't understand the cookie-policy documentation
I did see someone else in the Java world also ran into this issue here: https://github.com/elastic/support-diagnostics/issues/233