API¶
revproxy.views¶
-
class
revproxy.views.
DiazoProxyView
(*args, **kwargs)[source]¶ Bases:
revproxy.views.ProxyView
,django.views.generic.base.ContextMixin
-
diazo_rules
¶
-
diazo_theme_template
= 'diazo.html'¶
-
html5
= False¶
-
-
class
revproxy.views.
ProxyView
(*args, **kwargs)[source]¶ Bases:
django.views.generic.base.View
View responsable by excute proxy requests, process and return their responses.
-
add_remote_user
= False¶
-
default_content_type
= 'application/octet-stream'¶
-
get_proxy_request_headers
(request)[source]¶ Get normalized headers for the upstream
Gets all headers from the original request and normalizes them. Normalization occurs by removing the prefix
HTTP_
and replacing and_
by-
. Example:HTTP_ACCEPT_ENCODING
becamesAccept-Encoding
.New in version 0.9.1.
Parameters: request – The original HTTPRequest instance Returns: Normalized headers for the upstream
-
get_request_headers
()[source]¶ Return request headers that will be sent to upstream.
The header REMOTE_USER is set to the current user if the view’s add_remote_user property is True
New in version 0.9.8.
-
retries
= None¶
-
rewrite
= ()¶
-
upstream
¶
-
revproxy.response¶
-
revproxy.response.
DEFAULT_AMT
= 65536¶ Default number of bytes that are going to be read in a file lecture
-
revproxy.response.
get_django_response
(proxy_response, strict_cookies=False)[source]¶ This method is used to create an appropriate response based on the Content-Length of the proxy_response. If the content is bigger than MIN_STREAMING_LENGTH, which is found on utils.py, than django.http.StreamingHttpResponse will be created, else a django.http.HTTPResponse will be created instead
Parameters: - proxy_response – An Instance of urllib3.response.HTTPResponse that will create an appropriate response
- strict_cookies – Whether to only accept RFC-compliant cookies
Returns: Returns an appropriate response based on the proxy_response content-length
revproxy.transformer¶
-
revproxy.transformer.
DIAZO_OFF_REQUEST_HEADER
= 'HTTP_X_DIAZO_OFF'¶ String used to verify if request has a ‘HTTP_X_DIAZO_OFF’ header
-
revproxy.transformer.
DIAZO_OFF_RESPONSE_HEADER
= 'X-Diazo-Off'¶ String used to verify if request has a ‘X-Diazo-Off’ header
-
class
revproxy.transformer.
DiazoTransformer
(request, response)[source]¶ Bases:
object
Class used to make a diazo transformation on a request or a response
-
transform
(rules, theme_template, is_html5, context_data=None)[source]¶ Method used to make a transformation on the content of the http response based on the rules and theme_templates passed as paremters
Parameters: - rules – A file with a set of diazo rules to make a transformation over the original response content
- theme_template – A file containing the template used to format the the original response content
- is_html5 – A boolean parameter to identify a html5 doctype
Returns: A response with a content transformed based on the rules and theme_template
-
-
revproxy.transformer.
HAS_DIAZO
= False¶ Variable used to identify if diazo is available
-
revproxy.transformer.
asbool
(value)[source]¶ Function used to convert certain string values into an appropriated boolean value.If value is not a string the built-in python bool function will be used to convert the passed parameter
Parameters: value – an object to be converted to a boolean value Returns: A boolean value
-
revproxy.transformer.
doctype_re
= re.compile(b'^<!DOCTYPE\\s[^>]+>\\s*', re.MULTILINE)¶ Regex used to find the doctype-header in a html content
revproxy.utils¶
-
revproxy.utils.
DEFAULT_CHARSET
= 'latin-1'¶ Variable that represent the default charset used
-
revproxy.utils.
HTML_CONTENT_TYPES
= ('text/html', 'application/xhtml+xml')¶ List containing string constants that represents possible html content type
-
revproxy.utils.
IGNORE_HEADERS
= ('HTTP_ACCEPT_ENCODING', 'HTTP_HOST', 'HTTP_REMOTE_USER')¶ List containing string constant that are used to represent headers that can be ignored in the required_header function
-
revproxy.utils.
MIN_STREAMING_LENGTH
= 4096¶ Variable used to represent a minimal content size required for response to be turned into stream
Parser for HTTP header set-cookie The return from this function will be used as parameters for django’s response.set_cookie method. Because set_cookie doesn’t have parameter comment, this cookie attribute will be ignored.
Parameters: - cookie_string – A string representing a valid cookie
- strict_cookies – Whether to only accept RFC-compliant cookies
Returns: A dictionary containing the cookie_string attributes
-
revproxy.utils.
encode_items
(items)[source]¶ Function that encode all elements in the list of items passed as a parameter
Parameters: items – A list of tuple Returns: A list of tuple with all items encoded in ‘utf-8’
-
revproxy.utils.
get_charset
(content_type)[source]¶ Function used to retrieve the charset from a content-type.If there is no charset in the content type then the charset defined on DEFAULT_CHARSET will be returned
Parameters: content_type – A string containing a Content-Type header Returns: A string containing the charset
-
revproxy.utils.
is_html_content_type
(content_type)[source]¶ Function used to verify if the parameter is a proper html content type
Parameters: content_type – String variable that represent a content-type Returns: A boolean value stating if the content_type is a valid html content type
-
revproxy.utils.
normalize_request_headers
(request)[source]¶ Function used to transform header, replacing ‘HTTP_’ to ‘’ and replace ‘_’ to ‘-‘
Parameters: request – A HttpRequest that will be transformed Returns: A dictionary with the normalized headers
-
revproxy.utils.
required_header
(header)[source]¶ Function that verify if the header parameter is a essential header
Parameters: header – A string represented a header Returns: A boolean value that represent if the header is required
-
revproxy.utils.
should_stream
(proxy_response)[source]¶ Function to verify if the proxy_response must be converted into a stream.This will be done by checking the proxy_response content-length and verify if its length is bigger than one stipulated by MIN_STREAMING_LENGTH.
Parameters: proxy_response – An Instance of urllib3.response.HTTPResponse Returns: A boolean stating if the proxy_response should be treated as a stream