thorneliu opened a new issue, #1940:
URL: https://github.com/apache/incubator-brpc/issues/1940

   **Describe the bug (描述bug)**
   In brpc::PROTOCOL_HTTP, we will set the host field by service_name when 
   - host is not explicitly set 
   - host is not set in the url
   ```
       if (_options.protocol == brpc::PROTOCOL_HTTP) {
           URI& uri = cntl->http_request().uri();
           if (uri.host().empty() && !_service_name.empty()) {
               uri.SetHostAndPort(_service_name);
           }
       }
   ```
   However, when the channel is inited via na_url shceme = `list` or `file`, 
such `_service_name` is not valid host field and sometimes we
   get `400 BadRequest` 
   
   **To Reproduce (复现方法)**
   Init a channel with ipport list and http_request uri with relative path, eg:
   
   ```
       brpc::Channel channel;
       brpc::ChannelOptions opt;
       opt.protocol = brpc::PROTOCOL_HTTP;
   
       std::string server("list://127.0.0.1:8000,127.0.0.1:8001");
       std::string lb("rr");
       const int ret = channel.Init(server.c_str(), lb.c_str(), &opt);
   
       brpc::Controller cntl;
       cntl.http_request().uri() = "/dummy";
       channel.CallMethod(nullptr, &cntl, nullptr, nullptr, nullptr);
   ```
   
   In the http request, the `host` field will be set as :
   host: 127.0.0.1:8000,127.0.0.1:8001
   
   Similarly, when the ns_url is a `file:/conf/hosts`, the host field in HTTP 
requeset will be:
   host: conf 
   
   **Expected behavior (期望行为)**
   host should be set as remote_side IP+Port in the senarios above
   
   **Versions (各种版本)**
   OS:  Ubuntu 20.04
   Compiler:  g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
   brpc: latest  59f5d772db2ec3d280ee3fbd881e078544590f3b
   protobuf: 3.6.1
   
   **Additional context/screenshots (更多上下文/截图)**
   
![issue](https://user-images.githubusercontent.com/10826201/193369676-c9474395-19fb-4320-ae1e-6b0930fb30cf.png)
   
   


-- 
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]

Reply via email to