-
-
Notifications
You must be signed in to change notification settings - Fork 744
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
[Bug]: BaseAddress / relative URL formats - HttpClient style vs Refit style #1803
Comments
That's actually not true, there would be no double slashes. On the contrary - it will remove part of the base url. HttpClient actually is smart about combining baseUrl and relativeUrl, it's just not obvious if you don't know about it. But - it is based on RFC, and it matches other implementations, like javascript's URL. That's said, I agree that it's strange that Refit doesn't allow URLs without leading slashes. |
That's not the behavior I saw - if I configure
Then the URL that is called by Refit is I specifically configured the
I agree - if this was documented better then that would already help a lot. |
@hansmbakker |
I just found some more issues related to this. Looking at #1358 (which I now see my issue is a duplicate of), people mention that Refit is not RFC compliant because of this behavior. A few years ago, changing this behavior was refused and using a custom delegating HttpHandler was recommended. If this could be reconsidered, or if this could be documented better, it would be really helpful. Related issues: |
lol I just was tearing my hair out yesterday about HttpClient not working correctly at it's cause of it needing the ending '/' Honestly, I prefer Refits way though as it makes more intuitive sense to me. Additionally, at least Refit immediatly throws an error telling you the problem. HttpClient will work with GetAsJsonAsync using the wrong way and lead you on a merry chase on why POST is failing. Plus, if you use HttpClientExtendedLogging ? Well, that will also cause POST to work cause of how it manipulated the request uri internally I guess RFC compliance is not needed; clear errors and docs are, so I would say MSFT is the one that needs to step up here, personally. Though, I do think that the fact that Refit uses the HttpClientBuilder can cause confusion between the two, so it would be nice for consistency if it was supported Just my two cents as a dev that was spending way too much time on this yesterday :P |
Describe the bug 🐞
Looking at the sources linked below, Refit seems to expect a configuration of
HttpClient
's `BaseAddress and relative URLs in a way that is different than how HttpClient is meant to be used.If I misunderstood those sources - please close this issue.
Unfortunately
HttpClient
is not "smart" about combining theBaseAddress
with relative urls and e.g. if you configure the base address with a trailing slash while also configuring the relative urls with a leading slash, it will result in a double//
which results in a 404 error at runtime.Actual behavior
Refit expects the paths to start with a
/
:refit/Refit/RestMethodInfo.cs
Lines 258 to 261 in 47ce83e
and the samples show things like
c.BaseAddress = new Uri("https://api.github.com")
(missing/
) andGet("/users/{user}")
(leading/
):refit/README.md
Lines 15 to 35 in f77f0f3
Expected behavior
However, the expected HttpClient usage seems to be this
BaseAddress
is expected to end with a/
/
Therefore, the expected situation is either:
Sources
Step to reproduce
https://api.github.com/
and the GET path asusers/{user}
Reproduction repository
https://github.com/reactiveui/refit
The text was updated successfully, but these errors were encountered: