File diff r25654:e264fd698eb2 → r25655:1030dcb7eb52
src/network/core/tcp_http.cpp
Show inline comments
 
@@ -45,7 +45,7 @@ NetworkHTTPSocketHandler::NetworkHTTPSoc
 
	size_t bufferSize = strlen(url) + strlen(host) + strlen(GetNetworkRevisionString()) + (data == nullptr ? 0 : strlen(data)) + 128;
 
	char *buffer = AllocaM(char, bufferSize);
 

	
 
	DEBUG(net, 5, "[tcp/http] Requesting %s%s", host, url);
 
	Debug(net, 5, "[tcp/http] Requesting {}{}", host, url);
 
	if (data != nullptr) {
 
		seprintf(buffer, buffer + bufferSize - 1, "POST %s HTTP/1.0\r\nHost: %s\r\nUser-Agent: OpenTTD/%s\r\nContent-Type: text/plain\r\nContent-Length: %d\r\n\r\n%s\r\n", url, host, GetNetworkRevisionString(), (int)strlen(data), data);
 
	} else {
 
@@ -86,7 +86,7 @@ void NetworkHTTPSocketHandler::CloseSock
 
 * Helper to simplify the error handling.
 
 * @param msg the error message to show.
 
 */
 
#define return_error(msg) { DEBUG(net, 1, msg); return -1; }
 
#define return_error(msg) { Debug(net, 1, msg); return -1; }
 

	
 
static const char * const NEWLINE        = "\r\n";             ///< End of line marker
 
static const char * const END_OF_HEADER  = "\r\n\r\n";         ///< End of header marker
 
@@ -142,7 +142,7 @@ int NetworkHTTPSocketHandler::HandleHead
 
		 * wrong. You can't have gzips of 0 bytes! */
 
		if (len == 0) return_error("[tcp/http] Refusing to download 0 bytes");
 

	
 
		DEBUG(net, 7, "[tcp/http] Downloading %i bytes", len);
 
		Debug(net, 7, "[tcp/http] Downloading {} bytes", len);
 
		return len;
 
	}
 

	
 
@@ -155,7 +155,7 @@ int NetworkHTTPSocketHandler::HandleHead
 
		/* Search the end of the line. This is safe because the header will
 
		 * always end with two newlines. */
 
		*strstr(status, NEWLINE) = '\0';
 
		DEBUG(net, 1, "[tcp/http] Unhandled status reply %s", status);
 
		Debug(net, 1, "[tcp/http] Unhandled status reply {}", status);
 
		return -1;
 
	}
 

	
 
@@ -172,7 +172,7 @@ int NetworkHTTPSocketHandler::HandleHead
 
	char *end_of_line = strstr(uri, NEWLINE);
 
	*end_of_line = '\0';
 

	
 
	DEBUG(net, 7, "[tcp/http] Redirecting to %s", uri);
 
	Debug(net, 7, "[tcp/http] Redirecting to {}", uri);
 

	
 
	int ret = NetworkHTTPSocketHandler::Connect(uri, this->callback, this->data, this->redirect_depth + 1);
 
	if (ret != 0) return ret;
 
@@ -229,7 +229,7 @@ int NetworkHTTPSocketHandler::Receive()
 
			NetworkError err = NetworkError::GetLast();
 
			if (!err.WouldBlock()) {
 
				/* Something went wrong... */
 
				if (!err.IsConnectionReset()) DEBUG(net, 0, "Recv failed: %s", err.AsString());
 
				if (!err.IsConnectionReset()) Debug(net, 0, "Recv failed: {}", err.AsString());
 
				return -1;
 
			}
 
			/* Connection would block, so stop for now */
 
@@ -257,7 +257,7 @@ int NetworkHTTPSocketHandler::Receive()
 

	
 
			if (end_of_header == nullptr) {
 
				if (read == lengthof(this->recv_buffer)) {
 
					DEBUG(net, 1, "[tcp/http] Header too big");
 
					Debug(net, 1, "[tcp/http] Header too big");
 
					return -1;
 
				}
 
				this->recv_pos = read;