-
Notifications
You must be signed in to change notification settings - Fork 187
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
Preemptive authentication does not work when only setting the host #285
Comments
Note that this also affects |
There is also this in the documentation. |
I'm going to close this. Not sure this is a real issue. If it is, we can reopen. |
Uh, this is definitely a real issue in production, which is why I found this issue report. We tried using a URL of the form If it does (testing still pending here), |
@kkofler Sounds good. Thanks for the update. Once you test and find a solution, a PR is much appreciated. |
This is so old, I don't remember why we ended up with -1 there... it does seem like a huge amount of code smell to do that, but I have a feeling it was to work around some issue in HttpClient which may or may not be long resolved. Again, happy to accept a PR if you can figure this all out. |
It is possible that you might actually need to add cache entries both for -1 and for the real default port, though I hope not. |
We are going to try: URL baseURL = …;
int port = baseURL().getPort();
sardine.enablePreemptiveAuthentication(baseURL.getHost(), port >= 0 ? port : 80, port >= 0 ? port : 443); as a local workaround. If that works out, I will send a PR implementing this (the magic in the ternaries) within |
We have tested it: The |
In SardineImpl.enablePreemptiveAuthentication(String, int, int, Charset), do not pass -1 to the HttpHost constructor. The later cache lookup is always done with an explicit port, so port -1 never matches and the entry does nothing. Instead, we need to use the default port explicitly, then it will work, even when connecting with a URL that does not include the port. Since the other overloads delegate to this one, this fixes all overloads to do the right thing, in particular, the enablePreemptiveAuthentication(String) (hostname-only) and enablePreemptiveAuthentication(URL) (when using a URL without an explicit port) ones. Fixes lookfirst#285.
See PR #348, now with correct issue references. |
Fix preemptive authentication without explicit port (#285)
public void enablePreemptiveAuthentication(String hostname)
populates the AuthCache using the port numbers -1 and preemptive authentication does not happen when using the default ports 80/443.
It works by calling Sardine#enablePreemptiveAuthentication(host, 80, 443);
The text was updated successfully, but these errors were encountered: