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

using ipv6 ip will cause IllegalArgumentException("unexpected domain") #33

Open
henry74918 opened this issue May 16, 2017 · 1 comment
Labels

Comments

@henry74918
Copy link

henry74918 commented May 16, 2017

I've faced a exception when using ipv6 ip address.
I'm using okhttp3 3.6.0 with PresistentCookieJar.
When try to connect directly using ivp6 address ex: 2001:b011:400a:156e:211:32ff:fe0f:c06b
The exception occur when SerializableCookie try to read cooke from an inputStream through readObject function

final String domain = (String) in.readObject();
builder.domain(domain);`

It using Cookie.Builder to set domain into cookie.
And inside builder.domain, it checks invalidHostname which can not contains ":"

  private static boolean containsInvalidHostnameAsciiCodes(String hostnameAscii) {
    for (int i = 0; i < hostnameAscii.length(); i++) {
      char c = hostnameAscii.charAt(i);
      // The WHATWG Host parsing rules accepts some character codes which are invalid by
      // definition for OkHttp's host header checks (and the WHATWG Host syntax definition). Here
      // we rule out characters that would cause problems in host headers.
      if (c <= '\u001f' || c >= '\u007f') {
        return true;
      }
      // Check for the characters mentioned in the WHATWG Host parsing spec:
      // U+0000, U+0009, U+000A, U+000D, U+0020, "#", "%", "/", ":", "?", "@", "[", "\", and "]"
      // (excluding the characters covered above).
      if (" #%/:?@[\\]".indexOf(c) != -1) {
        return true;
      }
    }
    return false;
  }

ref:
https://github.com/square/okhttp/blob/master/okhttp/src/main/java/okhttp3/internal/Util.java#L386

But ipv6 address contains colon anyway.
How can I fix this?
Thanks

@franmontiel
Copy link
Owner

Seems that OkHttp Cookies do not support ipv6 domains (at least when constructed using the builder). Might be a good idea to create a issue in their repo.

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

No branches or pull requests

2 participants