Browse Source

Don't append standard ports to the request header.

Breaks the SSL communication with some servers,
do the same that the other curl, wget, firefox & co clients do.

Fixes #9146
Martin Capitanio 8 years ago
parent
commit
5cabe5f0fc
1 changed files with 12 additions and 2 deletions
  1. 12 2
      core/io/http_client.cpp

+ 12 - 2
core/io/http_client.cpp

@@ -96,7 +96,12 @@ Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector
 	};
 	};
 
 
 	String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n";
 	String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n";
-	request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n";
+	if ((ssl && conn_port == 443) || (!ssl && conn_port == 80)) {
+		// don't append the standard ports
+		request += "Host: " + conn_host + "\r\n";
+	} else {
+		request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n";
+	}
 	bool add_clen = p_body.size() > 0;
 	bool add_clen = p_body.size() > 0;
 	for (int i = 0; i < p_headers.size(); i++) {
 	for (int i = 0; i < p_headers.size(); i++) {
 		request += p_headers[i] + "\r\n";
 		request += p_headers[i] + "\r\n";
@@ -151,7 +156,12 @@ Error HTTPClient::request(Method p_method, const String &p_url, const Vector<Str
 	};
 	};
 
 
 	String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n";
 	String request = String(_methods[p_method]) + " " + p_url + " HTTP/1.1\r\n";
-	request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n";
+	if ((ssl && conn_port == 443) || (!ssl && conn_port == 80)) {
+		// don't append the standard ports
+		request += "Host: " + conn_host + "\r\n";
+	} else {
+		request += "Host: " + conn_host + ":" + itos(conn_port) + "\r\n";
+	}
 	bool add_clen = p_body.length() > 0;
 	bool add_clen = p_body.length() > 0;
 	for (int i = 0; i < p_headers.size(); i++) {
 	for (int i = 0; i < p_headers.size(); i++) {
 		request += p_headers[i] + "\r\n";
 		request += p_headers[i] + "\r\n";