-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Set hostname rather than ip when channel Init by hostname but not host in http_requst().uri() #1529
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dab62e4
Set host not ip when not in url
guodongxiaren 95606cc
ParseHostname
guodongxiaren 486de0d
update PraseHostname && add ut
guodongxiaren 5085c5e
update _hostname to _service_name
guodongxiaren a5c72a0
set port
guodongxiaren 3cd4840
rm ParseHostname and restore http_message.cpp
guodongxiaren b1ebfe5
reduce ParseUrl() for Init()
guodongxiaren 93b4efe
update en/http_client.mp
guodongxiaren 1d04a27
redesign InitSingle
guodongxiaren a3c02fa
update docs
guodongxiaren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,7 +115,9 @@ If user already sets `Host` header(case insensitive), framework makes no change. | |
|
||
If user does not set `Host` header and the URL has host, for example http://www.foo.com/path, the http request contains "Host: www.foo.com". | ||
|
||
If user does not set host header and the URL does not have host as well, for example "/index.html?name=value", framework sets `Host` header with IP and port of the target server. A http server at 10.46.188.39:8989 should see `Host: 10.46.188.39:8989`. | ||
If user does not set host header and the URL does not have host as well, for example "/index.html?name=value", but if the address initialized by the channel contains domain name. framework sets `Host` header with domain name of the target server. if this address is "http://www.foo.com", this http server should see `Host: www.foo.com`. if this address is "http://www.foo.com:8989", this http server should be see `Host: www.foo.com`. | ||
|
||
If user does not set host header and the URL does not have host as well, for example "/index.html?name=value", and the address initialized by the channel doesn't contain domain name. framework sets `Host` header with IP and port of the target server. A http server at 10.46.188.39:8989 should see `Host: 10.46.188.39:8989`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 改了 |
||
|
||
The header is named ":authority" in h2. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
最后这个Host是不是应该是"Host: www.foo.com:8989"?
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.
不是。在http_message.cpp中:
URL不包含host,但是channel初始化的时候包含的情况,我给uri的host字段赋了值。会走到:
if (!uri.host().empty())
的if 逻辑中。但是下面的uri.port() 是-1,所以不会把:port
追加到host中。我前面有个commit是改了http_message.cpp,改成:
从remote_side中拿port拼接到Host字段。不过你说可能有兼容性问题,所以我又去掉了。
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.
Hi, 我之前说的谦容性问题是,实现将Host: www.aa.com 变成了 Host: www.aa.com:80。现在这样实现的话 www.aa.com和www.aa.com:8899对应到请求全部都是Host: www.aa.com,不太符合预期 https://datatracker.ietf.org/doc/html/rfc2616#section-14.23
符合谦容性的实现是:
要想个办法把ParseUrl出来的port,也在set_host的时候顺便set_port,这样http_message.cpp就不用改了。简单看了下,似乎把parse出来的port追加到_service_name后面,然后替换set_host为uri.SetHostAndPort(_service_name)就可以了。看看可行么?
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.
有一点问题,如果调用的是 channel.Init("www.aa.com", 8899),那么对方收到的Host还是不包含端口号的。因为InitSingle中解析的原始地址,是Init的第一个参数。
感觉不存在十全十美的解决方案,我感觉还是要在CallMethod的时候,当uri不包含host的时候,把host和port都拼上。不影响uri中包含host时的处理逻辑。
另外一个方案就是在两个Init重载中,记录一下(新增bool成员变量存储标记,或者直接存原始port),InitSingle中判断是否单独设置了port参数。