-
Notifications
You must be signed in to change notification settings - Fork 3k
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
AJAX Content-Type Handling. #2837
Comments
Is there a reason why we can't let browser detect it automatically ? That's what |
Fixed by #4453? |
Not really. I maybe shouldn't have combined two problems in a single issue, but the primary problem here is that I found the serialising behaviour unintuitive coming from XHR. The default type of There are default rules for how to type and serialise the request body in the case of XHR which could be replicated. I'm not aware of arguments against the default XHR behaviour, but for the lack of any better documentation it seems it would be advantageous for the RxJS AJAX to conform to 'legacy' behaviour. That PR should at least make it straight-forward to override the default behaviour which is a decent improvement. |
…pe where possible - Ajax will now allow default behavior as defined in the specs: - https://xhr.spec.whatwg.org/#the-send()-method - https://fetch.spec.whatwg.org/#concept-bodyinit-extract - if the `body` is set to: `Blob`, `ArrayBuffer`, any array buffer view (like a byte sequence, e.g. `Uint8Array`, etc), `FormData`, `URLSearchParams`, `string`, or `ReadableStream`, default handling is use. If the `body` is otherwise `typeof` `"object"`, then it will be converted to JSON via `JSON.stringify`, and the `Content-Type` header will be set to `application/json;charset=utf-8`. All other types will emit an error. - Updates tests. - Puts the behavior inline with axios, et al. resolves ReactiveX#2837
…pe where possible - Ajax will now allow default behavior as defined in the specs: - https://xhr.spec.whatwg.org/#the-send()-method - https://fetch.spec.whatwg.org/#concept-bodyinit-extract - if the `body` is set to: `Blob`, `ArrayBuffer`, any array buffer view (like a byte sequence, e.g. `Uint8Array`, etc), `FormData`, `URLSearchParams`, `string`, or `ReadableStream`, default handling is use. If the `body` is otherwise `typeof` `"object"`, then it will be converted to JSON via `JSON.stringify`, and the `Content-Type` header will be set to `application/json;charset=utf-8`. All other types will emit an error. - Updates tests. - Puts the behavior in-line with Axios, et al. resolves ReactiveX#2837 BREAKING CHANGE: `ajax` body serialization will now use default XHR behavior in all cases. If the body is a `Blob`, `ArrayBuffer`, any array buffer view (like a byte sequence, e.g. `Uint8Array`, etc), `FormData`, `URLSearchParams`, `string`, or `ReadableStream`, default handling is use. If the `body` is otherwise `typeof` `"object"`, then it will be converted to JSON via `JSON.stringify`, and the `Content-Type` header will be set to `application/json;charset=utf-8`. All other types will emit an error. BREAKING CHANGE: The `Content-Type` header passed to `ajax` configuration no longer has any effect on the serialization behavior of the AJAX request.
…pe where possible - Ajax will now allow default behavior as defined in the specs: - https://xhr.spec.whatwg.org/#the-send()-method - https://fetch.spec.whatwg.org/#concept-bodyinit-extract - if the `body` is set to: `Blob`, `ArrayBuffer`, any array buffer view (like a byte sequence, e.g. `Uint8Array`, etc), `FormData`, `URLSearchParams`, `string`, or `ReadableStream`, default handling is use. If the `body` is otherwise `typeof` `"object"`, then it will be converted to JSON via `JSON.stringify`, and the `Content-Type` header will be set to `application/json;charset=utf-8`. All other types will emit an error. - Updates tests. - Puts the behavior in-line with Axios, et al. resolves ReactiveX#2837 BREAKING CHANGE: `ajax` body serialization will now use default XHR behavior in all cases. If the body is a `Blob`, `ArrayBuffer`, any array buffer view (like a byte sequence, e.g. `Uint8Array`, etc), `FormData`, `URLSearchParams`, `string`, or `ReadableStream`, default handling is use. If the `body` is otherwise `typeof` `"object"`, then it will be converted to JSON via `JSON.stringify`, and the `Content-Type` header will be set to `application/json;charset=utf-8`. All other types will emit an error. BREAKING CHANGE: The `Content-Type` header passed to `ajax` configuration no longer has any effect on the serialization behavior of the AJAX request.
…pe where possible - Ajax will now allow default behavior as defined in the specs: - https://xhr.spec.whatwg.org/#the-send()-method - https://fetch.spec.whatwg.org/#concept-bodyinit-extract - if the `body` is set to: `Blob`, `ArrayBuffer`, any array buffer view (like a byte sequence, e.g. `Uint8Array`, etc), `FormData`, `URLSearchParams`, `string`, or `ReadableStream`, default handling is use. If the `body` is otherwise `typeof` `"object"`, then it will be converted to JSON via `JSON.stringify`, and the `Content-Type` header will be set to `application/json;charset=utf-8`. All other types will emit an error. - Updates tests. - Puts the behavior in-line with Axios, et al. resolves ReactiveX#2837 BREAKING CHANGE: `ajax` body serialization will now use default XHR behavior in all cases. If the body is a `Blob`, `ArrayBuffer`, any array buffer view (like a byte sequence, e.g. `Uint8Array`, etc), `FormData`, `URLSearchParams`, `string`, or `ReadableStream`, default handling is use. If the `body` is otherwise `typeof` `"object"`, then it will be converted to JSON via `JSON.stringify`, and the `Content-Type` header will be set to `application/json;charset=utf-8`. All other types will emit an error. BREAKING CHANGE: The `Content-Type` header passed to `ajax` configuration no longer has any effect on the serialization behavior of the AJAX request.
…pe where possible - Ajax will now allow default behavior as defined in the specs: - https://xhr.spec.whatwg.org/#the-send()-method - https://fetch.spec.whatwg.org/#concept-bodyinit-extract - if the `body` is set to: `Blob`, `ArrayBuffer`, any array buffer view (like a byte sequence, e.g. `Uint8Array`, etc), `FormData`, `URLSearchParams`, `string`, or `ReadableStream`, default handling is use. If the `body` is otherwise `typeof` `"object"`, then it will be converted to JSON via `JSON.stringify`, and the `Content-Type` header will be set to `application/json;charset=utf-8`. All other types will emit an error. - Updates tests. - Puts the behavior in-line with Axios, et al. resolves #2837 BREAKING CHANGE: `ajax` body serialization will now use default XHR behavior in all cases. If the body is a `Blob`, `ArrayBuffer`, any array buffer view (like a byte sequence, e.g. `Uint8Array`, etc), `FormData`, `URLSearchParams`, `string`, or `ReadableStream`, default handling is use. If the `body` is otherwise `typeof` `"object"`, then it will be converted to JSON via `JSON.stringify`, and the `Content-Type` header will be set to `application/json;charset=utf-8`. All other types will emit an error. BREAKING CHANGE: The `Content-Type` header passed to `ajax` configuration no longer has any effect on the serialization behavior of the AJAX request.
When sending data using the AJAX methods the existing code attempts to serialise the data using its own rules which do not match the XHR serialisation rules. For my use notably it doesn't automatically handle XML Document objects which XHR does. I'm not sure why the decision was made to make 'application/x-www-form-urlencoded' the default content type, and while the serialisation code is helpful I feel it should be opt in rather than the default behaviour.
Additionally, when checking to see if the user has supplied a 'Content-Type' header to override the default behaviour it only does a case-sensitive check despite the fact that HTTP headers are case insensitive. It should instead either normalise user provided headers, or else do case insensitive checks for relevant headers, or else it should be clearly documented that it will interrogate specific headers in a case insensitive fashion. See:
rxjs/src/observable/dom/AjaxObservable.ts
Lines 201 to 211 in 7bb8280
At the very least clearly documenting the default serialisation behaviour and how to use 'Content-Type' to override the default behaviour is required.
The text was updated successfully, but these errors were encountered: