-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Overwrite HTTP Host header #40
Overwrite HTTP Host header #40
Conversation
Hi @georgemp, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
@@ -57,6 +57,11 @@ static utility::string_t flatten_http_headers(const http_headers &headers) | |||
utility::string_t flattened_headers; | |||
for(auto iter = headers.begin(); iter != headers.end(); ++iter) | |||
{ | |||
utility::string_t header_name = iter->first; | |||
http_headers::_case_insensitive_cmp cmp; | |||
if (!cmp(header_name, header_names::host) && !cmp(header_names::host, header_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.
Also, our windows http client implementation is in http_client_winhttp.cpp. We should make sure that we dont break anything there when modifying these common files.
I have added some comments. Please take a look. I can merge the changes once they are addressed. |
comparisons 2. Added test case to test overwriting the host header
Hi @kavyako , I have also added a unit test to handle testing (with and without overwriting the http_host_header). Unfortunately, I don't have a windows machine to test against windows at the moment. I hope the changes will not affect windows clients. If there is anything else, you would like me to add, let me know |
The flatten_http_headers() where we add all the headers to the flattened_headers is called by the windows client too. Since we are changing it to skip adding the HOST header, I think it will affect the windows implemenation. |
Hi @kavyako
Since, we are now allowing the user to optionally supply a host header, I am suppressing the duplication that would have otherwise occurred in step 2 above (by just skipping user specified host headers as they are anyway always printed in step 1). So, now on windows, I believe the following would apply
|
I verified the PR on windows and it does break windows clients. Any user specified host header will not be sent with the request, since it has been removed from flatten_http_headers. |
This has been merged to the development branch. Also fixed few build breaks on Windows. |
Currently, cpprestsdk ouputs the host header in the form of 'Host: hostname:port'
Some servers have trouble handling the port number on the host header. It might be useful to allow overriding the host header (like curl does). This PR allows us to specify a host header in our request. If present, it will print that out on the http request. Else, it will default to the current host:port format