-
Notifications
You must be signed in to change notification settings - Fork 535
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
[Mono.Android] Handle "No authentication challenges found" on HTTP 401 #449
base: main
Are you sure you want to change the base?
Conversation
Pre-KitKat (< API 19), when accessing `Java.Net.HttpURLConnection.ResponseCode` for a 401 response without a `WWW-Authenticate` header, `Java.IO.IOException: No authentication challenges found` is thrown. This commit catches the exception, ensuring a 401 is returned by `AndroidClientHandler`.
Hello! I'm the build bot for the Mono project. I need approval from a Mono team member to build this pull request. A team member should reply with "approve" to approve a build of this pull request, "whitelist" to whitelist this and all future pull requests from this contributor, or "build" to explicitly request a build, even if one has already been done. Contributors can ignore this message. |
} | ||
// Accessing the ResponseCode will throw an IOException if the code is 401 | ||
// and the server has not returned a WWW-Authenticate header on < API 19 | ||
catch (IOException ex) when (ex.Message.Contains("authentication challenges")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering how IOException
compiles when both System.IO
and Java.IO
are in scope, and both of those namespaces have an IOException
type...
I also find it somewhat amusing that the fix to httpConnection.ResponseCode
throwing an exception...is to call it again.
insanity is doing the same thing over and over and expecting a different result.
Oh Android, I ❤️ you so much...
Is it possible to write a test for this? Or, can you provide instructions on what a server would need to do to hit this code path when running on e.g. API-18? We might be able to get a server to behave in the (in?)appropriate way. |
I'll get an updated commit and see if I can add a test for this. I believe calling private HttpEngine getResponse() throws IOException {
initHttpEngine();
if (httpEngine.hasResponse()) {
return httpEngine;
} Updated main PR description. |
build |
@jamie94bc: your unit test failed execution:
I suspect the issue is that we use an API-21 emulator to run the unit tests on the PR builder, and API-21 doesn't need your fix. The assertion thus needs a runtime API level check. |
@jonpryor that's odd, I will try to find some time later this week to look into this 👍 |
Hello! I'm the build bot for Xamarin. I need approval from a Xamarin team member to build this pull request. A team member should reply with "approve" to approve a build of this pull request, "whitelist" to whitelist this and all future pull requests from this contributor, or "build" to explicitly request a build, even if one has already been done. Contributors can ignore this message. |
Pre-KitKat (< API 19), when accessing
Java.Net.HttpURLConnection.ResponseCode
for a 401 response without aWWW-Authenticate
header,Java.IO.IOException: No authentication challenges found
is thrown.This commit catches the exception, ensuring a 401 is returned by
AndroidClientHandler
.Android libcore sources: