Jump to >

djblets.util.http

class HttpResponseNotAcceptable(content='', *args, **kwargs)[source]

Bases: django.http.response.HttpResponse

status_code = 406[source]
set_last_modified(response, timestamp)[source]

Sets the Last-Modified header in a response based on a DateTimeField.

get_modified_since(request, last_modified)[source]

Checks if a Last-Modified timestamp is newer than the requested HTTP_IF_MODIFIED_SINCE from the browser. This can be used to bail early if no updates have been performed since the last access to the page.

This can take a DateField, datetime, HTTP date-formatted string, or a function for the last_modified timestamp. If a function is passed, it will only be called if the HTTP_IF_MODIFIED_SINCE header is present.

set_etag(response, etag)[source]

Sets the ETag header in a response.

encode_etag(etag)[source]

Encode a string as a SHA1 value, for use in an ETag.

etag_if_none_match(request, etag)[source]

Checks if an ETag matches the If-None-Match header sent by the browser. This can be used to bail early if no updates have been performed since the last access to the page.

etag_if_match(request, etag)[source]

Checks if an ETag matches the If-Match header sent by the browser. This is used by PUT requests to to indicate that the update should only happen if the specified ETag matches the header.

get_http_accept_lists(request)[source]

Returns lists of mimetypes from the request’s Accept header.

This will return two lists, a list of acceptable mimetypes in order of requested priority, and a list of unacceptable mimetypes.

get_http_requested_mimetype(request, supported_mimetypes)[source]

Gets the mimetype that should be used for returning content.

This is based on the client’s requested list of mimetypes (in the HTTP Accept header) and the supported list of mimetypes that can be returned in this request.

If a valid mimetype that can be used is found, it will be returned. Otherwise, None is returned, and the caller is expected to return HttpResponseNotAccepted.

is_mimetype_a(mimetype, parent_mimetype)[source]

Returns whether or not a given mimetype is a subset of another.

This is generally used to determine if vendor-specific mimetypes is a subset of another type. For example, application/vnd.djblets.foo+json is a subset of application/json.

get_url_params_except(query, *params)[source]

Return a URL query string that filters out some params.

This is used often when one wants to preserve some GET parameters and not others.