Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
Fix #109.
Browse files Browse the repository at this point in the history
  • Loading branch information
EinMByte committed Feb 3, 2016
1 parent 695c114 commit 5792af6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
15 changes: 10 additions & 5 deletions src/core/util/HTTP.cpp
Expand Up @@ -67,7 +67,7 @@ std::string HttpsDownload(
LogPrint(eLogInfo, "Connected to ", uri.m_Host, ":", uri.m_Port);
// Send header
std::stringstream sendStream;
sendStream << HttpHeader(uri.m_Path, uri.m_Host, "1.1");
sendStream << HttpHeader(uri.m_Path, uri.m_Host, "1.1") << "\r\n";
socket.write_some(buffer(sendStream.str()));
// Read response / download
std::stringstream readStream;
Expand Down Expand Up @@ -101,11 +101,16 @@ std::string HttpsDownload(

URI::URI(
const std::string& uri) {
m_PortString = "443";
m_Port = 443;
m_Path = "";
m_Query = "";
ParseURI(uri);
if (m_Protocol == "https") {
m_PortString = "443";
m_Port = 443;
} else {
m_PortString = "80";
m_Port = 80;
}
}

void URI::ParseURI(
Expand Down Expand Up @@ -155,7 +160,7 @@ void URI::ParseURI(
try {
m_Port = boost::lexical_cast<decltype(m_Port)>(m_PortString);
} catch (const exception& e) {
m_Port = 443;
// Keep the default port
}
}
// Parse query, assuming it's valid input
Expand All @@ -175,7 +180,7 @@ std::string HttpHeader(
"Host: " + host + "\r\n" +
"Accept: */*\r\n" +
"User-Agent: Wget/1.11.4\r\n" +
"Connection: close\r\n\r\n";
"Connection: close\r\n";
return header;
}

Expand Down
17 changes: 8 additions & 9 deletions src/core/util/HTTP.h
Expand Up @@ -60,11 +60,10 @@ namespace http {
/**
* @return the result of the download, or an empty string if it fails
*/
std::string HttpsDownload(
const std::string& address);
std::string HttpsDownload(const std::string& address);

/**
* @class URI provides functionality for parsing URIs
* Provides functionality for parsing URIs
*/
class URI {
/**
Expand All @@ -76,10 +75,10 @@ class URI {
* Note: fragments are not parsed by this function (if they should
* ever be needed in the future).
*
* @param string URI
* @param uri the URI to be parsed
* @warning the default port is 80, for HTTPS it is 443
*/
void ParseURI(
const std::string& uri);
void ParseURI(const std::string& uri);
public:
std::string m_Protocol, m_Host, m_Path, m_PortString, m_Query;
int m_Port;
Expand All @@ -88,8 +87,9 @@ class URI {
};

/**
* Header for HTTPS requests.
* Header for HTTP requests.
* @return a string of the complete header
* @warning this function does NOT append an additional \r\n
*/
std::string HttpHeader(
const std::string& path,
Expand All @@ -99,8 +99,7 @@ std::string HttpHeader(
/**
* @return the content of the given HTTP stream without headers
*/
std::string GetHttpContent(
std::istream& response);
std::string GetHttpContent(std::istream& response);

/**
* Merge chunks of an HTTP response.
Expand Down

0 comments on commit 5792af6

Please sign in to comment.