summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2021-01-01 09:10:12 +0000
committerJulian Andres Klode <jak@debian.org>2021-01-01 09:10:12 +0000
commitda468783ecfb0b5a8575b1d91abae193519ef5a7 (patch)
tree70f7170585b9f9c0b5b50a2f6f8d3b22896167f1
parente115b1a0e96da48a400873f292bbce87d1e2c41e (diff)
parent1663774bf309fbd196fd2b9c5c2afdd7a25fd288 (diff)
Merge branch 'http-to-https' into 'master'
aptmethod: fix HTTP->HTTPS request sequences See merge request apt-team/apt!140
-rw-r--r--methods/basehttp.h2
-rw-r--r--methods/connect.cc30
2 files changed, 16 insertions, 16 deletions
diff --git a/methods/basehttp.h b/methods/basehttp.h
index 4a83f319c..62c9963ea 100644
--- a/methods/basehttp.h
+++ b/methods/basehttp.h
@@ -94,7 +94,7 @@ struct ServerState
/** \brief Get the headers before the data */
RunHeadersResult RunHeaders(RequestState &Req, const std::string &Uri);
- bool Comp(URI Other) const {return Other.Host == ServerName.Host && Other.Port == ServerName.Port;};
+ bool Comp(URI Other) const {return Other.Access == ServerName.Access && Other.Host == ServerName.Host && Other.Port == ServerName.Port;};
virtual void Reset();
virtual bool WriteResponse(std::string const &Data) = 0;
diff --git a/methods/connect.cc b/methods/connect.cc
index 57dfb6299..d513a4540 100644
--- a/methods/connect.cc
+++ b/methods/connect.cc
@@ -45,7 +45,7 @@
/*}}}*/
static std::string LastHost;
-static int LastPort = 0;
+static std::string LastService;
static struct addrinfo *LastHostAddr = 0;
static struct addrinfo *LastUsed = 0;
@@ -349,17 +349,14 @@ static ResultState ConnectToHostname(std::string const &Host, int const Port,
{
if (ConnectionAllowed(Service, Host) == false)
return ResultState::FATAL_ERROR;
- // Convert the port name/number
- char ServStr[300];
- if (Port != 0)
- snprintf(ServStr,sizeof(ServStr),"%i", Port);
- else
- snprintf(ServStr,sizeof(ServStr),"%s", Service);
+
+ // Used by getaddrinfo(); prefer port if given, else fallback to service
+ std::string ServiceNameOrPort = Port != 0 ? std::to_string(Port) : Service;
/* We used a cached address record.. Yes this is against the spec but
the way we have setup our rotating dns suggests that this is more
sensible */
- if (LastHost != Host || LastPort != Port)
+ if (LastHost != Host || LastService != ServiceNameOrPort)
{
Owner->Status(_("Connecting to %s"),Host.c_str());
@@ -405,14 +402,14 @@ static ResultState ConnectToHostname(std::string const &Host, int const Port,
while (1)
{
int Res;
- if ((Res = getaddrinfo(Host.c_str(),ServStr,&Hints,&LastHostAddr)) != 0 ||
+ if ((Res = getaddrinfo(Host.c_str(), ServiceNameOrPort.c_str(), &Hints, &LastHostAddr)) != 0 ||
LastHostAddr == 0)
{
if (Res == EAI_NONAME || Res == EAI_SERVICE)
{
if (DefPort != 0)
{
- snprintf(ServStr, sizeof(ServStr), "%i", DefPort);
+ ServiceNameOrPort = std::to_string(DefPort);
DefPort = 0;
continue;
}
@@ -431,17 +428,17 @@ static ResultState ConnectToHostname(std::string const &Host, int const Port,
}
if (Res == EAI_SYSTEM)
_error->Errno("getaddrinfo", _("System error resolving '%s:%s'"),
- Host.c_str(), ServStr);
+ Host.c_str(), ServiceNameOrPort.c_str());
else
_error->Error(_("Something wicked happened resolving '%s:%s' (%i - %s)"),
- Host.c_str(), ServStr, Res, gai_strerror(Res));
+ Host.c_str(), ServiceNameOrPort.c_str(), Res, gai_strerror(Res));
return ResultState::TRANSIENT_ERROR;
}
break;
}
LastHost = Host;
- LastPort = Port;
+ LastService = ServiceNameOrPort;
}
// When we have an IP rotation stay with the last IP.
@@ -469,7 +466,7 @@ static ResultState ConnectToHostname(std::string const &Host, int const Port,
return Result;
if (_error->PendingError() == true)
return ResultState::FATAL_ERROR;
- _error->Error(_("Unable to connect to %s:%s:"), Host.c_str(), ServStr);
+ _error->Error(_("Unable to connect to %s:%s:"), Host.c_str(), ServiceNameOrPort.c_str());
return ResultState::TRANSIENT_ERROR;
}
/*}}}*/
@@ -486,7 +483,10 @@ ResultState Connect(std::string Host, int Port, const char *Service,
if (ConnectionAllowed(Service, Host) == false)
return ResultState::FATAL_ERROR;
- if(LastHost != Host || LastPort != Port)
+ // Used by getaddrinfo(); prefer port if given, else fallback to service
+ std::string ServiceNameOrPort = Port != 0 ? std::to_string(Port) : Service;
+
+ if(LastHost != Host || LastService != ServiceNameOrPort)
{
SrvRecords.clear();
if (_config->FindB("Acquire::EnableSrvRecords", true) == true)