Skip to content

Commit

Permalink
fix(server): return correct headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ericswpark committed Dec 13, 2023
1 parent 17a2c45 commit 05a4772
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions server/core/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import humanize
from auditlog.registry import auditlog
from constance import config
Expand Down Expand Up @@ -396,6 +398,9 @@ def human_readable_timedelta(self):
humanize.i18n.deactivate()
return humanize.naturaltime(date.today() - self.build_date)

def zip_file_basename(self):
return os.path.basename(self.zip_file.name)


# Statistics model
class Statistics(models.Model):
Expand Down
11 changes: 10 additions & 1 deletion server/downloads/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import time

from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.urls import reverse
Expand Down Expand Up @@ -63,7 +66,13 @@ def download_check_view(request, codename, file_name):

response = HttpResponse()
response["X-Accel-Redirect"] = f"/internal/media/{build.zip_file.name}"
response["Content-Type"] = ""
response["Last-Modified"] = time.strftime(
"%a,%e %b %Y %H:%M:%S %Z", time.gmtime(os.path.getmtime(build.zip_file.name))
)
response[
"Content-Disposition"
] = f'attachment; filename="{build.zip_file_basename()}"'
response["Content-Type"] = "application/octet-stream"

if build.is_archived:
limit_speed = config.SHIPPER_DOWNLOADS_ARCHIVE_THROTTLE * 1000 * 1000
Expand Down

0 comments on commit 05a4772

Please sign in to comment.