← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3389: http fixes (the patch in #668548 got only partially applied in r3082)

 

------------------------------------------------------------
revno: 3389
committer: Crise <crise@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2014-01-10 09:21:42 +0200
message:
  http fixes (the patch in #668548 got only partially applied in r3082)
modified:
  dcpp/HttpConnection.cpp
  dcpp/HttpConnection.h


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dcpp/HttpConnection.cpp'
--- dcpp/HttpConnection.cpp	2013-05-16 21:03:53 +0000
+++ dcpp/HttpConnection.cpp	2014-01-10 07:21:42 +0000
@@ -170,8 +170,8 @@
 
 void HttpConnection::on(BufferedSocketListener::Connected) noexcept {
 	dcassert(socket);
-	socket->write("GET " + file + " HTTP/1.1\r\n");
-	socket->write("User-Agent: " APPNAME " v" VERSIONSTRING "\r\n");
+	socket->write(method + " " + file + " HTTP/1.1\r\n");
+	socket->write("User-Agent: " + userAgent + "\r\n");
 
 	string sRemoteServer = server;
 	if(!SETTING(HTTP_PROXY).empty())
@@ -181,9 +181,16 @@
 	}
 
 	socket->write("Host: " + sRemoteServer + "\r\n");
-	socket->write("Connection: close\r\n");	// we'll only be doing one request
-	socket->write("Cache-Control: no-cache\r\n\r\n");
-	if (connType == TYPE_POST) socket->write(requestBody);
+	socket->write("Cache-Control: no-cache\r\n");
+	if(connType == TYPE_POST)
+	{
+		socket->write("Content-Type: application/x-www-form-urlencoded\r\n");
+		socket->write("Content-Length: " + Util::toString(requestBody.size()) + "\r\n");
+	}
+	socket->write("Connection: close\r\n\r\n");	// we'll only be doing one request
+
+	if(connType == TYPE_POST)
+		socket->write(requestBody);
 }
 
 void HttpConnection::on(BufferedSocketListener::Line, const string& aLine) noexcept {
@@ -208,6 +215,7 @@
 		} else socket->setDataMode(chunkSize);
 
 	} else if(connState == CONN_UNKNOWN) {
+		statusLine = boost::trim_copy(aLine);
 		if(aLine.find("200") != string::npos) {
 			connState = CONN_OK;
 		} else if(aLine.find("301") != string::npos || aLine.find("302") != string::npos) {
@@ -215,9 +223,8 @@
 		} else {
 			abortRequest(true);
 			connState = CONN_FAILED;
-			fire(HttpConnectionListener::Failed(), this, str(F_("%1% (%2%)") % boost::trim_copy(aLine) % url));
+			fire(HttpConnectionListener::Failed(), this, str(F_("%1% (%2%)") % statusLine % url));
 		}
-
 	} else if(connState == CONN_MOVED && Util::findSubString(aLine, "Location") != string::npos) {
 		abortRequest(true);
 
@@ -271,7 +278,8 @@
 void HttpConnection::on(BufferedSocketListener::Failed, const string& aLine) noexcept {
 	abortRequest(false);
 	connState = CONN_FAILED;
-	fire(HttpConnectionListener::Failed(), this, str(F_("%1% (%2%)") % boost::trim_copy(aLine) % url));
+	statusLine = boost::trim_copy(aLine);
+	fire(HttpConnectionListener::Failed(), this, str(F_("%1% (%2%)") % statusLine % url));
 }
 
 void HttpConnection::on(BufferedSocketListener::ModeChange) noexcept {

=== modified file 'dcpp/HttpConnection.h'
--- dcpp/HttpConnection.h	2013-05-16 21:03:53 +0000
+++ dcpp/HttpConnection.h	2014-01-10 07:21:42 +0000
@@ -43,6 +43,7 @@
 	void abort();
 
 	const string& getMimeType() const { return mimeType; }
+	const string& getStatus() const { return statusLine; }
 
 	int64_t getSize() const { return size; }
 	int64_t getDone() const { return done; }
@@ -64,6 +65,7 @@
 	string requestBody;
 
 	string mimeType;
+	string statusLine;
 	int64_t size;
 	int64_t done;
 	double speed;