-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
Support customisation of supported protocols #4901
Comments
Hi @realityfilter,
that overrides the default protocol on the platform can resolve this issue? If it's Ok I can create a PR. |
Thank you very much for the effort. For me the naming is a bit misleading. Currently requests with 'capacitor://' protocol are leading to exceptions because of 'capacitor' is not in the fixed set of protocols for the platform. I would like to register additional valid protocols either in the instance or per request. The name useProtocol is suggesting, that requests not specifying a protocol should use this one. That is not the intention.
This is because we might have no need for a global axios instance and we target urls with different protocols. |
Axios uses url lib to parse an URL, so I can pass protocol by default from the url base, here is an example. Look at tag protocol.
It resolves this issue or should we proceed to add a new feature? |
This is the problematic section: Lines 240 to 245 in cd8989a
The changelog states: Version 0.27.1:
So I think it is better to add a new feature? |
It's a better idea to add a new feature, adding Creating an instance
Instance methods
Global axios defaults
I'll make the changes to this feature. |
That is exactly what is needed. Thank you very much. |
@realityfilter, There's some example that I can use to test with the client and server that can reproduce the issue #4901 (comment)? |
describe('axios', () => {
it('should know protocol capacitor', async () => {
try {
await axios.get('capacitor://localhost/test.js')
} catch (e) {
console.log(e)
expect(e.code).not.toBe('ERR_BAD_REQUEST')
expect(e.message).not.toBe('Unsupported protocol capacitor:')
}
})
}) |
Has a limitation on one of the libraries used by axios. On line https://github.com/WillianAgostini/axios/blob/871ef051124fa9f02dcc05c67f29ff9ce3e681b5/lib/adapters/http.js#L292 has a call to lib |
That would be no problem in this use case. |
I have a use case that requires handling custom protocols and redirect. The SIOPv2 spec uses redirects with Right now I solved it by simply setting maxRedirects to 0 and then catching the error Simple example: let reqURI = "";
await axios
.post(path, undefined, {
maxRedirects: 0,
})
.catch((err) => {
if (err.response.status === 302) {
// We should have been redirected to "openid://?response_type=id_token..."
reqURI = err.response.headers.location;
} else {
throw err;
}
}); I don't need any features to be added (I think at least) but I thought you guys should know the use case exists. |
@WillianAgostini, Is there a PR already? Or can we help with something to add this feature? I'm having the same issue with a custom protocol on Lines 240 to 245 in cd8989a
Thanks in advance! |
Hi @dhondtlaurens |
Any reason why the test case of @realityfilter is not enough? Because this is not a capacitor-specific problem. All requests with a different URL scheme (protocol) are impacted, so the test should only check the following things:
Any thoughts on this? |
Does this work? I have a custom protocol after redirect. I also think |
I am looking into |
I truly don't think register protocol is the way. We should be able to handle any valid protocol, like @honungsburk 's use case. |
Issue is that any protocol is valid. |
Hi! Are there any movements on this issue? It is very necessary to use a custom protocol, like - vkcors://, but not with new versions. You have to use only the old version 0.26.1, which still has support for custom protocols. Please add the ability to use custom protocols. Thank you. |
Thank you very match for your solution |
Hello! Are there any changes planned on this issue? Thank you. |
@alevys Hello! Maybe you found some alternative solution? |
Is your feature request related to a problem? Please describe.
Since version 0.27.0 the supported protocols are a fixed set specified in platform.
axios/lib/platform/browser/index.js
Line 42 in cd8989a
We are using axios in a capacitor app that uses the special capacitor protocol.
Describe the solution you'd like
We need an option to specify additional supported protocols.
Describe alternatives you've considered
Use version 0.26.2 as a workaround.
The text was updated successfully, but these errors were encountered: