Ticket #9943: http-methods-and-statuses.diff

File http-methods-and-statuses.diff, 5.7 KB (added by zhirsch, 6 years ago)
  • django/http/__init__.py

     
    393393            raise Exception("This %s instance cannot tell its position" % self.__class__)
    394394        return sum([len(chunk) for chunk in self._container])
    395395
    396 class HttpResponseRedirect(HttpResponse):
    397     status_code = 302
    398 
     396class _HttpResponseRedirection(HttpResponse):
    399397    def __init__(self, redirect_to):
    400398        HttpResponse.__init__(self)
    401399        self['Location'] = iri_to_uri(redirect_to)
    402400
    403 class HttpResponsePermanentRedirect(HttpResponse):
     401class HttpResponseContinue(HttpResponse):
     402    status_code = 100
     403
     404class HttpResponseSwitchingProtocols(HttpResponse):
     405    status_code = 101
     406
     407class HttpResponseCreated(HttpResponse):
     408    status_code = 201
     409
     410class HttpResponseAccepted(HttpResponse):
     411    status_code = 202
     412
     413class HttpResponseNonAuthoritativeInformation(HttpResponse):
     414    status_code = 203
     415
     416class HttpResponseNoContent(HttpResponse):
     417    status_code = 204
     418
     419class HttpResponseResetContent(HttpResponse):
     420    status_code = 205
     421
     422class HttpResponsePartialContent(HttpResponse):
     423    status_code = 206
     424
     425class HttpResponseMultipleChoices(HttpResponse):
     426    status_code = 300
     427
     428class HttpResponsePermanentRedirect(_HttpResponseRedirection):
    404429    status_code = 301
     430HttpResponseMovedPermanently = HttpResponsePermanentRedirect
    405431
     432class HttpResponseRedirect(_HttpResponseRedirection):
     433    status_code = 302
     434HttpResponseFound = HttpResponseRedirect
     435
     436class HttpResponseSeeOther(_HttpResponseRedirection):
     437    status_code = 303
     438
     439class HttpResponseNotModified(HttpResponse):
     440    status_code = 304
     441
     442class HttpResponseUseProxy(_HttpResponseRedirection):
     443    status_code = 305
     444
     445class HttpResponseTemporaryRedirect(HttpResponse):
     446    status_code = 307
     447
    406448    def __init__(self, redirect_to):
    407449        HttpResponse.__init__(self)
    408450        self['Location'] = iri_to_uri(redirect_to)
    409451
    410 class HttpResponseNotModified(HttpResponse):
    411     status_code = 304
    412 
    413452class HttpResponseBadRequest(HttpResponse):
    414453    status_code = 400
    415454
    416 class HttpResponseNotFound(HttpResponse):
    417     status_code = 404
     455class HttpResponseUnauthorized(HttpResponse):
     456    status_code = 401
    418457
    419458class HttpResponseForbidden(HttpResponse):
    420459    status_code = 403
    421460
     461class HttpResponseNotFound(HttpResponse):
     462    status_code = 404
     463
    422464class HttpResponseNotAllowed(HttpResponse):
    423465    status_code = 405
    424466
    425467    def __init__(self, permitted_methods):
    426468        HttpResponse.__init__(self)
    427469        self['Allow'] = ', '.join(permitted_methods)
     470HttpResponseMethodNotAllowed = HttpResponseNotAllowed
    428471
     472class HttpResponseProxyAuthenticationRequired(HttpResponse):
     473    status_code = 407
     474
     475class HttpResponseRequestTimeout(HttpResponse):
     476    status_code = 408
     477
     478class HttpResponseConflict(HttpResponse):
     479    status_code = 409
     480
    429481class HttpResponseGone(HttpResponse):
    430482    status_code = 410
    431483
    432     def __init__(self, *args, **kwargs):
    433         HttpResponse.__init__(self, *args, **kwargs)
     484class HttpResponseLengthRequired(HttpResponse):
     485    status_code = 411
    434486
     487class HttpResponsePreconditionFailed(HttpResponse):
     488    status_code = 412
     489
     490class HttpResponseRequestEntityTooLarge(HttpResponse):
     491    status_code = 413
     492
     493class HttpResponseRequestURITooLong(HttpResponse):
     494    status_code = 414
     495
     496class HttpResponseUnsupportedMediaType(HttpResponse):
     497    status_code = 415
     498
     499class HttpResponseRequestedRangeNotSatisfiable(HttpResponse):
     500    status_code = 416
     501
     502class HttpResponseExpectationFailed(HttpResponse):
     503    status_code = 417
     504
    435505class HttpResponseServerError(HttpResponse):
    436506    status_code = 500
     507HttpResponseInternalServerError = HttpResponseServerError
    437508
    438     def __init__(self, *args, **kwargs):
    439         HttpResponse.__init__(self, *args, **kwargs)
     509class HttpResponseNotImplemented(HttpResponse):
     510    status_code = 501
    440511
     512class HttpResponseBadGateway(HttpResponse):
     513    status_code = 502
     514
     515class HttpResponseServiceUnavailable(HttpResponse):
     516    status_code = 503
     517
     518class HttpResponseGatewayTimeout(HttpResponse):
     519    status_code = 504
     520
     521class HttpResponseHTTPVersionNotSupported(HttpResponse):
     522    status_code = 505
     523
    441524# A backwards compatible alias for HttpRequest.get_host.
    442525def get_host(request):
    443526    return request.get_host()
  • django/views/decorators/http.py

     
    3232        return wraps(func)(inner)
    3333    return decorator
    3434
     35# Pre-define a specific decorator for each method listed in the HTTP/1.1 RFC:
     36# http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.8
     37
     38_require_doc = "Decorator to require that a view only accept the %s method."
     39
     40require_CONNECT = require_http_methods(["CONNECT"])
     41require_CONNECT.__doc__ = _require_doc % "CONNECT"
     42
     43require_DELETE = require_http_methods(["DELETE"])
     44require_DELETE.__doc__ = _require_doc % "DELETE"
     45
    3546require_GET = require_http_methods(["GET"])
    36 require_GET.__doc__ = "Decorator to require that a view only accept the GET method."
     47require_GET.__doc__ = _require_doc % "GET"
    3748
     49require_HEAD = require_http_methods(["HEAD"])
     50require_HEAD.__doc__ = _require_doc % "HEAD"
     51
     52require_OPTIONS = require_http_methods(["OPTIONS"])
     53require_OPTIONS.__doc__ = _require_doc % "OPTIONS"
     54
    3855require_POST = require_http_methods(["POST"])
    39 require_POST.__doc__ = "Decorator to require that a view only accept the POST method."
    40  No newline at end of file
     56require_POST.__doc__ = _require_doc % "POST"
     57
     58require_PUT = require_http_methods(["PUT"])
     59require_PUT.__doc__ = _require_doc % "PUT"
     60
     61require_TRACE = require_http_methods(["TRACE"])
     62require_TRACE.__doc__ = _require_doc % "TRACE"
Back to Top