This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
docs($http): correct and clarify default transforms #15906
Merged
Merged
Changes from 1 commit
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 hidden or 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 hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,12 +266,6 @@ function $HttpProvider() { | |
* {@link ng.$cacheFactory `$cacheFactory`} to enable or disable caching of HTTP responses | ||
* by default. See {@link $http#caching $http Caching} for more information. | ||
* | ||
* - **`defaults.xsrfCookieName`** - {string} - Name of cookie containing the XSRF token. | ||
* Defaults value is `'XSRF-TOKEN'`. | ||
* | ||
* - **`defaults.xsrfHeaderName`** - {string} - Name of HTTP header to populate with the | ||
* XSRF token. Defaults value is `'X-XSRF-TOKEN'`. | ||
* | ||
* - **`defaults.headers`** - {Object} - Default headers for all $http requests. | ||
* Refer to {@link ng.$http#setting-http-headers $http} for documentation on | ||
* setting default headers. | ||
|
@@ -280,15 +274,38 @@ function $HttpProvider() { | |
* - **`defaults.headers.put`** | ||
* - **`defaults.headers.patch`** | ||
* | ||
* - **`defaults.jsonpCallbackParam`** - `{string}` - the name of the query parameter that passes the name of the | ||
* callback in a JSONP request. The value of this parameter will be replaced with the expression generated by the | ||
* {@link $jsonpCallbacks} service. Defaults to `'callback'`. | ||
* | ||
* - **`defaults.paramSerializer`** - `{string|function(Object<string,string>):string}` - A function | ||
* used to the prepare string representation of request parameters (specified as an object). | ||
* If specified as string, it is interpreted as a function registered with the {@link auto.$injector $injector}. | ||
* Defaults to {@link ng.$httpParamSerializer $httpParamSerializer}. | ||
* | ||
* - **`defaults.jsonpCallbackParam`** - `{string}` - the name of the query parameter that passes the name of the | ||
* callback in a JSONP request. The value of this parameter will be replaced with the expression generated by the | ||
* {@link $jsonpCallbacks} service. Defaults to `'callback'`. | ||
* - **`defaults.transformRequest`** - | ||
* `{Array<function(data, headersGetter)>|function(data, headersGetter)}` - | ||
* An array of functions (or a single function) which are applied to the request data. | ||
* By default, this is an array with one request transformation function: | ||
* | ||
* - If the `data` property of the request configuration object contains an object, serialize it | ||
* into JSON format. | ||
* | ||
* - **`defaults.transformResponse`** - | ||
* `{Array<function(data, headersGetter, status)>|function((data, headersGetter, status))}` - | ||
* An array of functions (or a single function) which are applied to the response data. By default, | ||
* this is an array which applies one response transformation function that does two things: | ||
* | ||
* - If XSRF prefix is detected, strip it | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think "XSRF prefix" is accurate. The prefix won't prevent an XSRF afaict, it will just prevent a potential XSRF vulnerability to be combined with other vulnerabilities. EDIT: I see you've copied it from elsewhere. I'm not 100% sure, so I don't feel strongly about it 😁 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering about this too .. let's keep it for now |
||
* (see {@link ng.$http#security-considerations Security Considerations in the $http docs}). | ||
* - If the `Content-Type` is `application/json` or the response looks like JSON, | ||
* deserialize it using a JSON parser. | ||
* | ||
* - **`defaults.xsrfCookieName`** - {string} - Name of cookie containing the XSRF token. | ||
* Defaults value is `'XSRF-TOKEN'`. | ||
* | ||
* - **`defaults.xsrfHeaderName`** - {string} - Name of HTTP header to populate with the | ||
* XSRF token. Defaults value is `'X-XSRF-TOKEN'`. | ||
* | ||
**/ | ||
var defaults = this.defaults = { | ||
|
@@ -552,15 +569,18 @@ function $HttpProvider() { | |
* | ||
* AngularJS provides the following default transformations: | ||
* | ||
* Request transformations (`$httpProvider.defaults.transformRequest` and `$http.defaults.transformRequest`): | ||
* Request transformations (`$httpProvider.defaults.transformRequest` and `$http.defaults.transformRequest`) is | ||
* an array with one function that does the following: | ||
* | ||
* - If the `data` property of the request configuration object contains an object, serialize it | ||
* into JSON format. | ||
* | ||
* Response transformations (`$httpProvider.defaults.transformResponse` and `$http.defaults.transformResponse`): | ||
* Response transformations (`$httpProvider.defaults.transformResponse` and `$http.defaults.transformResponse`) is | ||
* an array with one function that does the following: | ||
* | ||
* - If XSRF prefix is detected, strip it (see Security Considerations section below). | ||
* - If JSON response is detected, deserialize it using a JSON parser. | ||
* - If the `Content-Type` is `application/json` or the response looks like JSON, | ||
* deserialize it using a JSON parser. | ||
* | ||
* | ||
* ### Overriding the Default Transformations Per Request | ||
|
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 double
((
/))
infunction((...))
?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.
Probably a typo