Python get content length
28 Python code examples are found related to "
get content length".
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: wsgi.py From lambda-packs with MIT License | 6 votes |
def get_content_length(environ): """Returns the content length from the WSGI environment as integer. If it's not available or chunked transfer encoding is used, ``None`` is returned. .. versionadded:: 0.9 :param environ: the WSGI environ to fetch the content length from. """ if environ.get('HTTP_TRANSFER_ENCODING', '') == 'chunked': return None content_length = environ.get('CONTENT_LENGTH') if content_length is not None: try: return max(0, int(content_length)) except (ValueError, TypeError): pass
Example 2
Source File: common.py From MyLife with MIT License | 6 votes |
def get_stored_content_length(headers): """Return the content length (in bytes) of the object as stored in GCS. x-goog-stored-content-length should always be present except when called via the local dev_appserver. Therefore if it is not present we default to the standard content-length header. Args: headers: a dict of headers from the http response. Returns: the stored content length. """ length = headers.get('x-goog-stored-content-length') if length is None: length = headers.get('content-length') return length
Example 3
Source File: rasp_result.py From openrasp-iast with Apache License 2.0 | 6 votes |
def get_content_length(self): """ 获取当前请求的header的content-length字段 Returns: str, content-length """ result = 0 for header_name in self.rasp_result_dict["context"]["header"]: if header_name.lower() == "content-length": try: result = int( self.rasp_result_dict["context"]["header"][header_name]) except Exception: pass return result
Example 4
Source File: wsgi.py From Building-Recommendation-Systems-with-Python with MIT License | 6 votes |
def get_content_length(environ): """Returns the content length from the WSGI environment as integer. If it's not available or chunked transfer encoding is used, ``None`` is returned. .. versionadded:: 0.9 :param environ: the WSGI environ to fetch the content length from. """ if environ.get("HTTP_TRANSFER_ENCODING", "") == "chunked": return None content_length = environ.get("CONTENT_LENGTH") if content_length is not None: try: return max(0, int(content_length)) except (ValueError, TypeError): pass
Example 5
Source File: framework_base.py From json-logging-python with Apache License 2.0 | 5 votes |
def get_content_length(self, request): """ We can safely assume that request is valid request object.\n The content length of the request. :return: the content length of the request or '-' if it cannot be determined """ raise NotImplementedError
Example 6
Source File: wsgi.py From pyRevit with GNU General Public License v3.0 | 5 votes |
def get_content_length(environ): """Returns the content length from the WSGI environment as integer. If it's not available `None` is returned. .. versionadded:: 0.9 :param environ: the WSGI environ to fetch the content length from. """ content_length = environ.get('CONTENT_LENGTH') if content_length is not None: try: return max(0, int(content_length)) except (ValueError, TypeError): pass
Example 7
Source File: server.py From presto-admin with Apache License 2.0 | 5 votes |
def get_content_length(self): try: headers = self.url_response.info() return int(headers['Content-Length']) except (KeyError, ValueError): # Handle the case when the server does not include # the 'Content-Length' header return None
Example 8
Source File: utilities.py From b2blaze with MIT License | 5 votes |
def get_content_length(file): if hasattr(file, 'name') and os.path.isfile(file.name): return os.path.getsize(file.name) else: raise Exception('Content-Length could not be automatically determined.')
Example 9
Source File: DownloadImpl.py From p2ptv-pi with MIT License | 5 votes |
def get_content_length(self, selected_file = None): if self.dltype == DLTYPE_TORRENT: return self.tdef.get_length(selected_file) if self.dltype == DLTYPE_DIRECT: if self.dd is not None: return self.dd.get_content_length() else: return self.pstate_content_length else: raise ValueError('Unknown download type ' + str(self.dltype))
Example 10
Source File: wsgi.py From ariadne with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_request_content_length(self, environ: dict) -> int: try: content_length = int(environ.get("CONTENT_LENGTH", 0)) if content_length < 1: raise HttpBadRequestError( "Content length header is missing or incorrect" ) return content_length except (TypeError, ValueError): raise HttpBadRequestError("Content length header is missing or incorrect")