def hook(req, resp, resource, params): length = req.content_length if length is not None and length > limit: msg = ('The size of the request is too large. The body must not ' 'exceed ' + str(limit) + ' bytes in length.') raise falcon.HTTPPayloadTooLarge('Request body is too large', msg)
def validate_payload_size(content_length): """Validates payload size. Method validates payload size, this method used req.content_length to determinate payload size [service] max_log_size = 1048576 **max_log_size** refers to the maximum allowed content length. If it is exceeded :py:class:`falcon.HTTPRequestEntityTooLarge` is thrown. :param content_length: size of payload :exception: :py:class:`falcon.HTTPLengthRequired` :exception: :py:class:`falcon.HTTPRequestEntityTooLarge` """ max_size = CONF.log_publisher.max_log_size LOG.debug('Payload (content-length) is %s', str(content_length)) if content_length >= max_size: raise falcon.HTTPPayloadTooLarge( title='Log payload size exceeded', description='Maximum allowed size is %d bytes' % max_size )
def on_post(self, req, resp): req_json = json.loads(req.bounded_stream.read(), encoding='utf-8') # check json key for key in req_json.keys(): if key not in ['username', 'password']: # return status code 406 not acceptable raise falcon.HTTPNotAcceptable(falcon.HTTP_NOT_ACCEPTABLE) for value in req_json.values(): if len(value) > 64: # return status code 406 not acceptable for value too long raise falcon.HTTPPayloadTooLarge("value too long.") # login to webap for check user acceptable login_status = ap_cache.login(username=req_json['username'], password=req_json['password']) if login_status == error_code.CACHE_WENAP_LOGIN_SUCCESS: # Add random token in to payload and save in redis. token = randStr(32) req_json['token'] = token red_auth_token.set(name="{username}_{token}".format( username=req_json['username'], token=token), value='', ex=config.JWT_EXPIRE_TIME) JWT_token = jwt_auth.get_auth_token(user_payload=req_json) resp.media = { 'token': JWT_token, 'expireTime': (datetime.datetime.utcnow() + datetime.timedelta(seconds=config.JWT_EXPIRE_TIME)).isoformat( timespec='seconds') + "Z" } resp.media['isAdmin'] = False if req_json['username'] in config.NEWS_ADMIN: resp.media['isAdmin'] = True resp.status = falcon.HTTP_200 return True elif login_status == error_code.CACHE_WEBAP_LOGIN_FAIL: resp.status = falcon.HTTP_401 return True elif login_status == error_code.CACHE_WEBAP_SERVER_ERROR: resp.status = falcon.HTTP_503 raise falcon.HTTPServiceUnavailable() else: raise falcon.HTTPBadRequest()
def validate_payload_size(req): """Validates payload size. Method validates sent payload size. It expects that http header **Content-Length** is present. If it does not, method raises :py:class:`falcon.HTTPLengthRequired`. Otherwise values is being compared with :: [service] max_log_size = 1048576 **max_log_size** refers to the maximum allowed content length. If it is exceeded :py:class:`falcon.HTTPRequestEntityTooLarge` is thrown. :param falcon.Request req: current request :exception: :py:class:`falcon.HTTPLengthRequired` :exception: :py:class:`falcon.HTTPRequestEntityTooLarge` """ payload_size = req.content_length max_size = CONF.service.max_log_size LOG.debug('Payload (content-length) is %s', str(payload_size)) if payload_size is None: raise falcon.HTTPLengthRequired( title='Content length header is missing', description='Content length is required to estimate if ' 'payload can be processed') if payload_size >= max_size: raise falcon.HTTPPayloadTooLarge( title='Log payload size exceeded', description='Maximum allowed size is %d bytes' % max_size)
def on_get(self, req, resp): raise falcon.HTTPPayloadTooLarge( title='Request Rejected', description='Request Body Too Large', retry_after=self.retry_after, )
def on_get(self, req, resp): raise falcon.HTTPPayloadTooLarge('Request Rejected', 'Request Body Too Large', retry_after=self.retry_after)
def process_request(self, req: falcon.Request, resp: falcon.Response): length = req.content_length if length is not None and length > self._max_size: msg = ('The size of the request is too large. The body must not ' 'exceed ' + str(self._max_size) + ' bytes in length.') raise falcon.HTTPPayloadTooLarge('Request body is too large', msg)