Ticket #31810: request_headers.diff

File request_headers.diff, 1.9 KB (added by bcail, 4 years ago)

test showing the issue

  • tests/test_client/tests.py

    diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py
    index 03bb658952..cfdaf794af 100644
    a b class ClientTest(TestCase):  
    872872        response = self.client.post('/upload_view/', data={'named_temp_file': test_file})
    873873        self.assertEqual(response.content, b'named_temp_file')
    874874
     875    def test_request_headers(self):
     876        response = self.client.get('/request_headers/', **{'someheader': 'some header value'})
     877        response_text = response.content.decode('utf8')
     878        self.assertEqual(response_text, 'someheader: some header value; someheader_meta: some header value')
     879
    875880
    876881@override_settings(
    877882    MIDDLEWARE=['django.middleware.csrf.CsrfViewMiddleware'],
  • tests/test_client/urls.py

    diff --git a/tests/test_client/urls.py b/tests/test_client/urls.py
    index 1bc552ba5d..0d4688eef3 100644
    a b urlpatterns = [  
    4747    path('nesting_exception_view/', views.nesting_exception_view),
    4848    path('django_project_redirect/', views.django_project_redirect),
    4949    path('two_arg_exception/', views.two_arg_exception),
     50    path('request_headers/', views.request_headers),
    5051
    5152    path('accounts/', RedirectView.as_view(url='login/')),
    5253    path('accounts/no_trailing_slash', RedirectView.as_view(url='login/')),
  • tests/test_client/views.py

    diff --git a/tests/test_client/views.py b/tests/test_client/views.py
    index 034ca6908c..8aa41f8539 100644
    a b class TwoArgException(Exception):  
    394394
    395395def two_arg_exception(request):
    396396    raise TwoArgException('one', 'two')
     397
     398
     399def request_headers(request):
     400    someheader = request.headers.get('someheader', None)
     401    someheader_meta = request.META.get('someheader', None)
     402    content = f'someheader: {someheader}; someheader_meta: {someheader_meta}'
     403    return HttpResponse(content)
Back to Top