From ce22d615fe940444602cf4c167f9ad29361a5d25 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 21 Feb 2002 00:01:32 +0000 Subject: [PATCH] Fix so the Host: header in wxHTTP really works. With virtual hosts it is vital that the original host name given in the URL is used in the Host: header so the sever will use the right vhost config. Previously it was using the value returned from gethostbyaddr which will often not be the same as the hostname in the URL. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14332 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/sckaddr.h | 6 +++++- src/common/http.cpp | 4 ++-- src/common/sckaddr.cpp | 16 ++++++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/wx/sckaddr.h b/include/wx/sckaddr.h index 8f175f4f45..087b9510d0 100644 --- a/include/wx/sckaddr.h +++ b/include/wx/sckaddr.h @@ -64,10 +64,14 @@ public: bool AnyAddress(); wxString Hostname(); + wxString OrigHostname() { return m_origHostname; } unsigned short Service(); virtual int Type() { return wxSockAddress::IPV4; } - virtual wxSockAddress *Clone() const { return new wxIPV4address(*this); } + virtual wxSockAddress *Clone() const; + +private: + wxString m_origHostname; }; #ifdef ENABLE_IPV6 diff --git a/src/common/http.cpp b/src/common/http.cpp index b98d6c83af..0853234490 100644 --- a/src/common/http.cpp +++ b/src/common/http.cpp @@ -181,7 +181,7 @@ bool wxHTTP::Connect(const wxString& host) if (!addr->Service(wxT("http"))) addr->Service(80); - + SetHeader(wxT("Host"), host); return TRUE; @@ -198,7 +198,7 @@ bool wxHTTP::Connect(wxSockAddress& addr, bool WXUNUSED(wait)) wxIPV4address *ipv4addr = wxDynamicCast(&addr, wxIPV4address); if (ipv4addr) - SetHeader(wxT("Host"), ipv4addr->Hostname()); + SetHeader(wxT("Host"), ipv4addr->OrigHostname()); return TRUE; } diff --git a/src/common/sckaddr.cpp b/src/common/sckaddr.cpp index 8e638c3537..4fd8ce90ed 100644 --- a/src/common/sckaddr.cpp +++ b/src/common/sckaddr.cpp @@ -108,13 +108,18 @@ bool wxIPV4address::Hostname(const wxString& name) wxLogWarning( _("Trying to solve a NULL hostname: giving up") ); return FALSE; } - + m_origHostname = name; return (GAddress_INET_SetHostName(m_address, name.mb_str()) == GSOCK_NOERROR); } bool wxIPV4address::Hostname(unsigned long addr) { - return (GAddress_INET_SetHostAddress(m_address, addr) == GSOCK_NOERROR); + bool rv = (GAddress_INET_SetHostAddress(m_address, addr) == GSOCK_NOERROR); + if (rv) + m_origHostname = Hostname(); + else + m_origHostname = ""; + return rv; } bool wxIPV4address::Service(const wxString& name) @@ -151,6 +156,13 @@ unsigned short wxIPV4address::Service() return GAddress_INET_GetPort(m_address); } +wxSockAddress *wxIPV4address::Clone() const +{ + wxIPV4address *addr = new wxIPV4address(*this); + addr->m_origHostname = m_origHostname; + return addr; +} + #if 0 // --------------------------------------------------------------------------- // wxIPV6address -- 2.45.2