x-socket-id header default causing issues.
Why is the X-Socket-Id set per default?
This causes a shitload of problems with most API's and it would be more beneficial to add it whenever you need to call a socket endpoint, rather than to remove it when it causes problems.
The Github API for example does not allow it in their preflight response. For Axios I have to do this all over the place now:
axios.get('user/repos', {
transformRequest: [function (data, headers) {
delete headers['X-Socket-Id'];
return data;
}]
})
I have same issue - L5 + UploadCare widget @latest + Echo @latest
As result UploadCare don't work
Failed to load https://upload.uploadcare.com/base/?jsonerrors=1: Request header field X-Socket-Id is not allowed by Access-Control-Allow-Headers in preflight response.
I can't unset X-Socket-Id from all 3rd party libs.
Same issue here.
Also experiencing issues with this in our app (specifically affecting Opt In Monster for customers that have us + them installed)
I was able to fix this by putting the interceptor code above the window.echo and remove the headers for the url which did not like it.
Vue.http.interceptors.push(function (request, next) {
//some api's dont like the X-CSFR-token or Pusher token.. remove it..
const removeAuthHeaders = request.url.includes("openiban.com");
request.headers['Access-Control-Allow-Origin'] = '*';
if (removeAuthHeaders){
request.headers.delete('Access-Control-Request-Headers')
request.headers.delete('X-Socket-ID');
}
else {
request.headers.set('X-CSRF-TOKEN', Laravel.csrfToken);
}
next(function(response) {
});
});
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'KEYYY',
cluster: 'CLUSTER',
encrypted: true
});
#157 fixed
Experiencing this too as I try to geocode with Google's API.
Temporary workaround is to just unset this header like this:
$.ajaxSetup({
beforeSend: function() {}
})
After creating new Echo's instance.
The x-socket-id header is required in order for Laravel to identify the socket which has caused an event to trigger. Without this, features like broadcast(new SomeEvent)->toOthers() wouldn't work.
If you don't want to send it in your headers, just take it out before you send the request.
@ImJustToNy your fix is dangerous, you won't ever be able to broadcast()->toOthers() if you do that. Fine if it works for you but the right way to do this is to wrap external requests in a separate API abstraction and remove that particular header from the request before sending rather than doing it "globally".
@rohan-deshpande, yeah, you're right but I think echo's way of forcing it to user is incorrect. In my particular example, external lib (uploadcare) wasn't able to send request to it's CDN because of this header which was injected into jQuery's ajax method that this library uses. Took me a little while figuring what's going on. In my opinion it should be turned off by default.
Echo doesn’t truly force you if you have control over your request layer.
For example I am building something with React, I’m not using jQuery, I use fetch for API requests.
Echo has provides a bunch of things to cater for Vue, jQuery or axios where it automatically intercepts request headers, so yeah I think that’s kind of not the best approach as it will bleed into other parts of the application.
Perhaps some options where you would define certain endpoints or domains where the x-socket-id is required (or the opposite) would be better.
For example I am building something with React, I’m not using jQuery, I use fetch for API requests.
And I'm using axios, which is a default/external lib. they shouldn't break how it works.
As also mentioned above; you don't always have control over external libs. astonished this issue has been open for this long already without any indication of something going to happen.
I think we may provide a config option for this. I think the reason why the PR was closed was because it's changed to opt-in. If we'd have a new PR which was opt-out then I think it could be accepted.
@driesvints Actually I believe the issue is not just it being opt-out/in.
Echo should not break usage of an external library.
but the right way to do this is to wrap external requests in a separate API abstraction and remove that particular header from the request before sending rather than doing it "globally".
That's exactly what Laravel should be doing; instead of expecting 3th party libs to do this. A lot of optimizers will check if a lib already exists globally and not include it again (which is likely why the uploadcare lib that @ImJustToNy uses broke). I understand the reasons behind it but if the override is preserved it should at least check for a matching hostname before adding headers that break CORS configurations. (just my 2 cents)
i have same issue using axios
any updates about that issue, I've lost my mind trying fixing this one
If anybody is wondering, the name of the option has been changed to: withoutInterceptors.
@CaelanStewart, yeah its strange that they did the same and now its feature
A good option to this would be using the native function fetch() to make requests in Javascript.
It solved my problem.
withoutInterceptor
A good option to this would be using the native function
fetch()to make requests in Javascript.It solved my problem.
This saved my day. I have had the same problem for 5 days. Thank you.