Skip to content
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(volo-http): add mime parsing in server, do not always prefer ipv4 in client dns #538

Merged
merged 4 commits into from
Nov 28, 2024

Conversation

yukiiiteru
Copy link
Member

Motivation

This PR fixes two bugs

Form extractor reject mime of form with charset

In the previous implementation, the Form extractor directly compared Content-Type and rejected the form if Content-Type was not application/x-www-form-urlencoded.

But sometimes Content-Type could be application/x-www-form-urlencoded; charset=utf-8, which is actually a valid mime for the form, but we incorrectly rejected it.

DNS resolver always prefer IPv4 addresses

We use the hickory_resolver crate to resolve domain names, but we found that it always prefers IPv4 addresses, which doesn't work if the client is running in an IPv6 only environment.

Solution

  • Check Content-Type by parsing instead of directly comparing the string.
  • Check the first name server, if the address is an IPv4 address we keep preferring IPv4 addresses, if it is an IPv6 address we set the resolver to prefer IPv6 addresses.

In addition, we bump Volo-HTTP to 0.3.0 here.

In the previous implementation, the `Form` extractor directly compared
`Content-Type` and rejected the form if `Content-Type` was not
`application/x-www-form-urlencoded`.

But sometimes `Content-Type` could be
`application/x-www-form-urlencoded; charset=utf-8`, which is actually a
valid mime for the form, but we incorrectly rejected it.

This commit makes the current implementation check `Content-Type` by
parsing instead of directly comparing the string.

Signed-off-by: Yu Li <[email protected]>
We use the `hickory_resolver` crate to resolve domain names, but we
found that it always prefers IPv4 addresses, which doesn't work if the
client is running in an IPv6 only environment.

This commit fixes this by checking the first name server, if the
address is an IPv4 address we keep preferring IPv4 addresses, if it is
an IPv6 address we set the resolver to prefer IPv6 addresses.

Signed-off-by: Yu Li <[email protected]>
@yukiiiteru yukiiiteru requested review from a team as code owners November 27, 2024 14:01
@yukiiiteru yukiiiteru merged commit 661346b into cloudwego:main Nov 28, 2024
13 checks passed
@yukiiiteru yukiiiteru deleted the fix/mime-and-dns branch November 28, 2024 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants