-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conditionally allows relative path for baseUrl
#2087
Comments
You should write |
The frontend does not necessarily know the full path. |
How do the instance be able to make requests if the full path is unavailable? |
Web applications can request the same origin using relative paths. |
Dio won't know your origin unless you define so. It's not a Web application. Closing as intended and won't fix. |
Not so sure, this may actually be a valid request for Flutter Web platform. |
The problem is not that Dio doesn't know something, but it just stops users from using relative paths with an assert. You cannot as that it is not a web app, because Dio can indeed be used as a client in a web application. As for me, it's quite strange to forbid the usage of something that is a part of the specification for no reason, especially when the actual request functionality works and the problem is in an unnecessary assert statement. Or is there a reason why it is forbidden? |
It could be possible to resolve by However, it's also available when you're setting the |
Yes, if you look at the initial issue, it is possible to bypass the assert using the setter for baseUrl after the BaseOptions is created. But if it's so, why the asset is there in the first place? |
I have the opposite opinion here. Dio is not in any form, an application. As you declared, it can only be used in a Web application.
Could you provide a reproducible example that it can run without the assertion?
You can use the blame view to determine when it's been introduced to find out the cause. |
I created a repo with the minimal reproducible example of both the exception and the supposed behaviour. Its README describes the steps to reproduce both situations.
diox/#18 has an issue of #1373 connected, but it's still unclear why |
baseUrl
in BaseOptionsbaseUrl
Resolves #2087. ### New Pull Request Checklist - [x] I have read the [Documentation](https://pub.dev/documentation/dio/latest/) - [x] I have searched for a similar pull request in the [project](https://github.com/cfug/dio/pulls) and found none - [x] I have updated this branch with the latest `main` branch to avoid conflicts (via merge from master or rebase) - [x] I have added the required tests to prove the fix/feature I'm adding - [x] I have updated the documentation (if necessary) - [x] I have run the tests without failures - [x] I have updated the `CHANGELOG.md` in the corresponding package
Package
dio
Version
5.4.0
Operating-System
Web
Output of
flutter doctor -v
No response
Dart Version
3.1.5
Steps to Reproduce
Run the following snippet with
dart run
:Expected Result
A new Dio instance is created with the given
baseUrl
and can be used as usual.It is a normal situation for web apps to separate their API under a separate endpoint group:
https://example.com/api/...
.Actual Result
The code above produces the following Assertion Error:
The exception can be avoided if one changes the
baseUrl
in the BaseOptions after it was created:Which is quite strange and not expected solution.
The text was updated successfully, but these errors were encountered: