-
-
Notifications
You must be signed in to change notification settings - Fork 51
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 several bugs on HttpNativeImpl
#626
Conversation
8b61ea4
to
dbe520a
Compare
HttpNativeImpl
src/http/http-axios-impl.ts
Outdated
headers['Content-Type'] ?? 'application/json', | ||
(headers['Content-Type'] ?? 'application/json') | ||
.get('Content-Type') | ||
.replace(/\s*;.*$/, ""), |
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.
I'd like to avoid repeating this code in both axios-impl
and native-impl
because I'm going to keep maintaining both implementations until fetch
is well supported on Node.js.
How about adding something like getContentType(headers): string
to BaseHttp
class so that they can call the shared inherited method?
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.
That sounds way better. I'm going to extract duplicated code into a common method.
src/http/http-native-impl.ts
Outdated
@@ -37,11 +47,14 @@ export class HttpNativeImpl extends BaseHttp implements Http { | |||
body: body as string, | |||
}); | |||
const text = await response.text(); | |||
const contentType = response.headers |
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.
This block-scoped variable contentType
has the same name and role as the variable in line 30.
dbe520a
to
f277388
Compare
@neet I did my best to address everything you reviewed. Could you take a look again? |
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.
Looks great, kudos @dahlia!
🎉 This PR is included in version 4.3.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Trim content type parameters from HTTP responses
Previously,
request()
method fromHttpAxiosImpl
&HttpNativeImpl
sometimes threw an error like below:It happened when a response from server contains
Content-Type
header with some parameters, e.g.,application/json; charset=utf-8
.It might be better to make
deserialize()
method fromSerializerNodejsImpl
&SerializerNativeImpl
to trim parameters from their input, but I trim parameters from response content types instead. If you leave a comment on this I'm going to address that.On
HttpNativeImpl.request<T>()
's return typeAlso there's one more fix on
HttpNativeImpl.request<T>()
method. It should returnResponse<T>
, but actually returnedT
instead. I addressed this bug as well.Let
HttpNativeImpl
set an appropriate boundary formultipart/form-data
The standard
fetch()
API automatically configures an arbitrary boundary formultipart/form-data
when its body isFormData
. However, the boundary can be omitted ifContent-Type
header is manually set. I madeHttpNativeImpl
to leaveContent-Type
header unset when it'smultipart/form-data
so that the underlyingfetch()
can determine an appropriate boundary for the form data.