Within a Xamarin app we are having a problem on Android where OkHttp is failing to send requests if they contain cookies where the domain starts with a dot.
Exception: java.lang.IllegalArgumentException
Ex. Message: unexpected domain: .direct.aviva.co.uk
Original stack trace:
======================
java.lang.IllegalArgumentException : unexpected domain: .my.domain.com
at okhttp3.Cookie$Builder.domain(Cookie.kt:297)
at okhttp3.Cookie$Builder.domain(Cookie.kt:287)
As far as I'm aware its valid for a domain to start with a dot but in the past this potentially wasn't allowed, is this correct? Could it be newer versions of OkHttp wouldn't throw this error?
We are using OkHttp 4.9.0.
If you’re constructing the cookie object programmatically, just omit the leading dot. That’s the rule according to the spec that OkHttp implements.
https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.3