summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main/utils.py9
-rw-r--r--packages/views/display.py3
-rw-r--r--packages/views/search.py4
3 files changed, 15 insertions, 1 deletions
diff --git a/main/utils.py b/main/utils.py
index cdd4ff71..8394e5cd 100644
--- a/main/utils.py
+++ b/main/utils.py
@@ -8,6 +8,7 @@ import hashlib
from django.core.cache import cache
from django.db import connections, router
+from django.http import HttpResponse
from django.utils.timezone import now
from django.template.defaultfilters import slugify
@@ -55,6 +56,14 @@ def clear_cache_function(func, args, kwargs):
cache.delete(key)
+def empty_response():
+ empty = HttpResponse('')
+ # designating response as 'streaming' forces ConditionalGetMiddleware to
+ # not add a 'Content-Length: 0' header
+ empty.streaming = True
+ return empty
+
+
def format_http_headers(request):
headers = sorted((k, v) for k, v in request.META.items()
if k.startswith('HTTP_'))
diff --git a/packages/views/display.py b/packages/views/display.py
index 50783835..87424483 100644
--- a/packages/views/display.py
+++ b/packages/views/display.py
@@ -7,6 +7,7 @@ from django.shortcuts import get_object_or_404, redirect, render
from django.utils.timezone import now
from main.models import Package, PackageFile, Arch, Repo
+from main.utils import empty_response
from mirrors.utils import get_mirror_url_for_download
from ..models import Update
from ..utils import get_group_info, PackageJSONEncoder
@@ -126,6 +127,8 @@ def details(request, name='', repo='', arch=''):
pkg = Package.objects.select_related(
'arch', 'repo', 'packager').get(pkgname=name,
repo=repo_obj, arch=arch_obj)
+ if request.method == 'HEAD':
+ return empty_response()
return render(request, 'packages/details.html', {'pkg': pkg})
except Package.DoesNotExist:
# attempt a variety of fallback options before 404ing
diff --git a/packages/views/search.py b/packages/views/search.py
index 0362602e..b3778172 100644
--- a/packages/views/search.py
+++ b/packages/views/search.py
@@ -7,7 +7,7 @@ from django.http import HttpResponse
from django.views.generic import ListView
from main.models import Package, Arch, Repo
-from main.utils import make_choice
+from main.utils import empty_response, make_choice
from ..models import PackageRelation
from ..utils import attach_maintainers, PackageJSONEncoder
@@ -99,6 +99,8 @@ class SearchListView(ListView):
allowed_sort = list(sort_fields) + ["-" + s for s in sort_fields]
def get(self, request, *args, **kwargs):
+ if request.method == 'HEAD':
+ return empty_response()
self.form = PackageSearchForm(data=request.GET,
show_staging=self.request.user.is_authenticated())
return super(SearchListView, self).get(request, *args, **kwargs)