Don't sent scheme and hostname in request

This commit is contained in:
Jean Flach 2017-09-06 16:01:02 +02:00
parent a8bac0a42e
commit de51966f52
4 changed files with 12 additions and 10 deletions

View File

@ -49,7 +49,7 @@ public:
return false;
pUrl = f.GetUrl();
url = pUrl->Format(true);
url = pUrl->Format(false, true);
wUrl = url;
config.Write("url", wUrl);
} else {

View File

@ -165,7 +165,7 @@ void HttpRequest::AddHeader(const String& key, const String& value)
void HttpRequest::FinishHeaders(void)
{
if (m_State == HttpRequestStart) {
String rqline = RequestMethod + " " + RequestUrl->Format() + " HTTP/1." + (ProtocolVersion == HttpVersion10 ? "0" : "1") + "\n";
String rqline = RequestMethod + " " + RequestUrl->Format(true) + " HTTP/1." + (ProtocolVersion == HttpVersion10 ? "0" : "1") + "\n";
m_Stream->Write(rqline.CStr(), rqline.GetLength());
m_State = HttpRequestHeaders;
}

View File

@ -227,17 +227,19 @@ void Url::SetFragment(const String& fragment) {
m_Fragment = fragment;
}
String Url::Format(bool print_credentials) const
String Url::Format(bool onlyPathAndQuery, bool printCredentials) const
{
String url;
if (!onlyPathAndQuery) {
if (!m_Scheme.IsEmpty())
url += m_Scheme + ":";
if (print_credentials && !GetAuthority().IsEmpty())
if (printCredentials && !GetAuthority().IsEmpty())
url += "//" + GetAuthority();
else if (!GetHost().IsEmpty())
url += "//" + GetHost() + (!GetPort().IsEmpty() ? ":" + GetPort() : "");
}
if (m_Path.empty())
url += "/";

View File

@ -44,7 +44,7 @@ public:
Url();
Url(const String& url);
String Format(bool print_credentials = false) const;
String Format(bool onlyPathAndQuery = false, bool printCredentials = false) const;
String GetScheme(void) const;
String GetAuthority(void) const;