コード例 #1
0
 def test_http_length_required_with_title_and_desc_and_challenges(self):
     try:
         raise falcon.HTTPLengthRequired(title='Test', description='Testdescription')
     except falcon.HTTPLengthRequired as e:
         self.assertEqual('Test', e.title, 'Title should be "Test"')
         self.assertEqual('Testdescription', e.description,
                          'Description should be "Testdescription"')
コード例 #2
0
 def test_http_length_required_no_title_and_desc_and_challenges(self):
     try:
         raise falcon.HTTPLengthRequired()
     except falcon.HTTPLengthRequired as e:
         self.assertEqual(status.HTTP_411, e.title,
                          'The title should be ' + status.HTTP_411 + ', but it is: ' + e.title)
         self.assertEqual(None, e.description, 'The description should be None')
コード例 #3
0
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.HTTPRequestEntityTooLarge(
            title='Log payload size exceeded',
            description='Maximum allowed size is %d bytes' % max_size
        )
コード例 #4
0
ファイル: test_httperror.py プロジェクト: vytas7/falcon
 def on_get(self, req, resp):
     raise falcon.HTTPLengthRequired(title='title',
                                     description='description')