@ -771,41 +771,41 @@ class ProxyingHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
index = LPInReleaseIndex(mirror, suite,
index = LPInReleaseIndex(mirror, suite,
cache=self.server.inrelease_cache)
cache=self.server.inrelease_cache)
inrelease = index.get_inrelease_for_timestamp(
self.server.snapshot_stamp)
try:
if inrelease is None:
inrelease = index.get_inrelease_for_timestamp(
self.__send_error(404, "No InRelease file found for given "
self.server.snapshot_stamp)
"mirror, suite and timestamp.")
except LPInReleaseIndexError as e:
return
inrelease = None
if inrelease is not None:
if target == "InRelease":
if target == "InRelease":
# If target is InRelease, send back contents directly.
# If target is InRelease, send back contents directly.
data = inrelease.data.encode("utf-8")
data = inrelease.data.encode("utf-8")
self.log_message(
self.log_message(
"Inject InRelease '{}'".format(inrelease.hash))
"Inject InRelease '{}'".format(inrelease.hash))
self.send_response(200)
self.send_response(200)
self.send_header("Content-Length", len(data))
self.send_header("Content-Length", len(data))
self.end_headers()
self.end_headers()
if verb == "GET":
if verb == "GET":
self.wfile.write(data)
self.wfile.write(data)
return
return
else:
else:
# If target hash is listed, then redirect to by-hash URL.
# If target hash is listed, then redirect to by-hash URL.
hash_ = inrelease.get_hash_for(target)
hash_ = inrelease.get_hash_for(target)
if hash_:
if hash_:
self.log_message(
self.log_message(
"Inject {} for {}".format(hash_, target))
"Inject {} for {}".format(hash_, target))
target_path = target.rsplit("/", 1)[0]
target_path = target.rsplit("/", 1)[0]
path = "{}/dists/{}/{}/by-hash/SHA256/{}"\
path = "{}/dists/{}/{}/by-hash/SHA256/{}"\
.format(base, suite, target_path, hash_)
.format(base, suite, target_path, hash_)
try:
try:
client = http.client.HTTPConnection(host)
client = http.client.HTTPConnection(host)
@ -839,6 +839,12 @@ class ProxyingHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
self.end_headers()
self.end_headers()
shutil.copyfileobj(response, self.wfile)
shutil.copyfileobj(response, self.wfile)
def __send_error(self, status, message):
"""Return an HTTP error status and a message in the response body."""
self.send_response(status)
self.send_header("Content-Type", "text/plain; charset=utf-8")
self.wfile.write(message.encode("utf-8"))
class MagicHTTPProxy(socketserver.ThreadingMixIn, http.server.HTTPServer):
class MagicHTTPProxy(socketserver.ThreadingMixIn, http.server.HTTPServer):
"""Tiny HTTP server using ProxyingHTTPRequestHandler instances to provide
"""Tiny HTTP server using ProxyingHTTPRequestHandler instances to provide