feat(http): add content-type override support for http request (#10211)
This commit is contained in:

committed by
Victor Berchet

parent
d455942389
commit
bdb59129d0
@ -90,20 +90,41 @@ export class Request extends Body {
|
||||
}
|
||||
}
|
||||
this._body = requestOptions.body;
|
||||
this.contentType = this.detectContentType();
|
||||
this.method = normalizeMethodName(requestOptions.method);
|
||||
// TODO(jeffbcross): implement behavior
|
||||
// Defaults to 'omit', consistent with browser
|
||||
// TODO(jeffbcross): implement behavior
|
||||
this.headers = new Headers(requestOptions.headers);
|
||||
this.contentType = this.detectContentType();
|
||||
this.withCredentials = requestOptions.withCredentials;
|
||||
this.responseType = requestOptions.responseType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content type enum based on header options.
|
||||
*/
|
||||
detectContentType(): ContentType {
|
||||
switch (this.headers.get('content-type')) {
|
||||
case 'application/json':
|
||||
return ContentType.JSON;
|
||||
case 'application/x-www-form-urlencoded':
|
||||
return ContentType.FORM;
|
||||
case 'multipart/form-data':
|
||||
return ContentType.FORM_DATA;
|
||||
case 'text/plain':
|
||||
case 'text/html':
|
||||
return ContentType.TEXT;
|
||||
case 'application/octet-stream':
|
||||
return ContentType.BLOB;
|
||||
default:
|
||||
return this.detectContentTypeFromBody();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content type of request's body based on its type.
|
||||
*/
|
||||
detectContentType() {
|
||||
detectContentTypeFromBody(): ContentType {
|
||||
if (this._body == null) {
|
||||
return ContentType.NONE;
|
||||
} else if (this._body instanceof URLSearchParams) {
|
||||
|
Reference in New Issue
Block a user