Skip to content

fix(volo-http): add mime parsing in server, do not always prefer ipv4 in client dns#538

Merged
yukiiiteru merged 4 commits intocloudwego:mainfrom
yukiiiteru:fix/mime-and-dns
Nov 28, 2024
Merged

fix(volo-http): add mime parsing in server, do not always prefer ipv4 in client dns#538
yukiiiteru merged 4 commits intocloudwego:mainfrom
yukiiiteru:fix/mime-and-dns

Conversation

@yukiiiteru
Copy link
Copy Markdown
Contributor

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.

Signed-off-by: Yu Li <liyu.yukiteru@bytedance.com>
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 <liyu.yukiteru@bytedance.com>
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 <liyu.yukiteru@bytedance.com>
Signed-off-by: Yu Li <liyu.yukiteru@bytedance.com>
@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
@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