mirror of
https://github.com/django/django.git
synced 2025-08-03 02:23:12 +00:00
Fixed #23606 -- Implemented Client and RequestFactory trace() methods.
Thanks KevinEtienne for the suggestion.
This commit is contained in:
parent
713f23492a
commit
28634394f5
7 changed files with 115 additions and 6 deletions
|
@ -5,7 +5,10 @@ from django.core import mail
|
|||
from django.forms import fields
|
||||
from django.forms.forms import Form, ValidationError
|
||||
from django.forms.formsets import formset_factory, BaseFormSet
|
||||
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound
|
||||
from django.http import (
|
||||
HttpResponse, HttpResponseRedirect, HttpResponseNotFound,
|
||||
HttpResponseNotAllowed, HttpResponseBadRequest,
|
||||
)
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template import Context, Template
|
||||
from django.utils.decorators import method_decorator
|
||||
|
@ -20,6 +23,31 @@ def get_view(request):
|
|||
return HttpResponse(t.render(c))
|
||||
|
||||
|
||||
def trace_view(request):
|
||||
"""
|
||||
A simple view that expects a TRACE request and echoes its status line.
|
||||
|
||||
TRACE requests should not have an entity; the view will return a 400 status
|
||||
response if it is present.
|
||||
"""
|
||||
if request.method.upper() != "TRACE":
|
||||
return HttpResponseNotAllowed("TRACE")
|
||||
elif request.body:
|
||||
return HttpResponseBadRequest("TRACE requests MUST NOT include an entity")
|
||||
else:
|
||||
protocol = request.META["SERVER_PROTOCOL"]
|
||||
t = Template(
|
||||
'{{ method }} {{ uri }} {{ version }}',
|
||||
name="TRACE Template",
|
||||
)
|
||||
c = Context({
|
||||
'method': request.method,
|
||||
'uri': request.path,
|
||||
'version': protocol,
|
||||
})
|
||||
return HttpResponse(t.render(c))
|
||||
|
||||
|
||||
def post_view(request):
|
||||
"""A view that expects a POST, and returns a different template depending
|
||||
on whether any POST data is available
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue