guodongxiaren commented on a change in pull request #1529: URL: https://github.com/apache/incubator-brpc/pull/1529#discussion_r698107898
########## File path: docs/cn/http_client.md ########## @@ -114,7 +114,9 @@ URL的一般形式如下图: 若用户没有填且URL中包含host,比如http://www.foo.com/path,则http request中会包含"Host: www.foo.com"。 -若用户没有填且URL不包含host,比如"/index.html?name=value",则框架会以目标server的ip和port为Host,地址为10.46.188.39:8989的http server将会看到"Host: 10.46.188.39:8989"。 +若用户没有填且URL不包含host,比如"/index.html?name=value",但如果Channel初始化的地址包含域名,则框架会以域名作为Host,比如"http://www.foo.com",该http server将会看到"Host: www.foo.com"。如果地址是"http://www.foo.com:8989",则该http server将会看到"Host: www.foo.com"。 + Review comment: 不是。在http_message.cpp中: ```cpp if (h->GetHeader("host") == NULL) { os << "Host: "; if (!uri.host().empty()) { os << uri.host(); if (uri.port() >= 0) { os << ':' << uri.port(); } } else if (remote_side.port != 0) { os << remote_side; } os << BRPC_CRLF; } ``` URL不包含host,但是channel初始化的时候包含的情况,我给uri的host字段赋了值。会走到:`if (!uri.host().empty())`的if 逻辑中。但是下面的uri.port() 是-1,所以不会把`:port` 追加到host中。 我前面有个commit是改了http_message.cpp,改成: ```cpp if (h->GetHeader("host") == NULL) { os << "Host: "; if (!uri.host().empty()) { os << uri.host(); if (uri.port() >= 0) { os << ':' << uri.port(); } else if (remote_side.port != 0) { // 加了这个逻辑 os << ':' << remote_side.port; } } else if (remote_side.port != 0) { os << remote_side; } os << BRPC_CRLF; } ``` 从remote_side中拿port拼接到Host字段。不过你说可能有兼容性问题,所以我又去掉了。 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
