-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[FIX] sap.ui.model.odata: add request header "X-Requested-With" #3324
Closed
+25
−6
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why should WE do this? Shouldn't it be already done automaticall by jQuery.ajax()?
Their code says the following:
Who am I to know this better? This sound dubious to me. I am not convinced, sorry.
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.
It would make sense that this was indeed taken care of by jQuery.ajax(), but I didn't assume that they should. When I performed some tests I quickly noticed these headers were missing using the v2/v4 OData models.
I just did another test and it shows that these headers are present in bare $.ajax() calls, but not in ajax requests originating from UI5 v2/v4 models.
See network log: https://plnkr.co/edit/16J1TFICxbqETCzaxuZ0?preview
To whitelist your IP for the V2 CORS, click the button over at https://cors-anywhere.herokuapp.com/corsdemo
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.
Have you shared the correct Plunker ID? It is not doing any OData calls in my case and in the code I also cannot see why it should.
With one of our test applications I can see the header
X-Requested-With: XMLHttpRequest
for the batch requests.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.
@uhlmannm The Plunker issues a same-origin request for its JSONModel data. I guess that's what @piejanssens was referring to.
As @ThomasChadzelek already pointed out with the code snippet, jQuery sends the
X-Request-With=XMLHttpRequest
header automatically, if and only if the outgoing request is a same-origin request and when the caller of$.ajax
did not add the header already.The reason for the same-origin condition is that
X-Requested-With
is not a CORS-safelisted header. Adding it to a cross-origin requests will therefore trigger an additional preflight request, which often is unwanted in the general case (e.g. for performance reasons or when the server is not prepared to handle it). Several frameworks therefore removed theX-Requested-With
header again from their defaults (1) or limited it to the same-origin case (jQuery).When there are already other non-safelisted headers (e.g. X-CSRF-Token) and when the server is known to allow the
X-Requested-With
header with CORS or when the server is in the same origin as the current page, then adding the header should be safe.I just wonder how the
ODataModel
could know about the server capabilities.[1] ReactiveX/rxjs#3273 , angular/angular.js#1004