Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Removed a warning that was displayed for HEAD requests. #7

Merged
merged 2 commits into from

4 participants

@madjar

application returned too few bytes (0) for specified Content-Length (85506) via app_iter

I kept getting this warning when doing HEAD requests, but it seems normal to me to get no content in a head request. I made waitress check if the request is a HEAD before issuing the warning.

This patch comes with a test, and a little fix to the tests (first of the two commits).

@mcdonc mcdonc merged commit d4ca0df into Pylons:master
@mcdonc
Owner

Thank you!

@merwok

Can I ask if this fix is part of a released version? I ran into it today.

@davidjb

@merwok: seemingly not yet. It's still in the 'Next Release' section of the change log.

@mcdonc
Owner

0.8.3 just released with the fix.

@davidjb

Thanks @mcdonc!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 8 deletions.
  1. +6 −5 waitress/task.py
  2. +15 −3 waitress/tests/test_task.py
View
11 waitress/task.py
@@ -418,11 +418,12 @@ def start_response(status, headers, exc_info=None):
# waiting for more data when there are too few bytes
# to service content-length
self.close_on_finish = True
- self.logger.warning(
- 'application returned too few bytes (%s) '
- 'for specified Content-Length (%s) via app_iter' % (
- self.content_bytes_written, cl),
- )
+ if self.request.command != 'HEAD':
+ self.logger.warning(
+ 'application returned too few bytes (%s) '
+ 'for specified Content-Length (%s) via app_iter' % (
+ self.content_bytes_written, cl),
+ )
finally:
if hasattr(app_iter, 'close'):
app_iter.close()
View
18 waitress/tests/test_task.py
@@ -25,7 +25,7 @@ def test_handler_thread_task_raises(self):
inst.handler_thread(0)
self.assertEqual(inst.stop_count, -1)
self.assertEqual(inst.threads, {})
- self.assertTrue(len(inst.logger.logged), 1)
+ self.assertEqual(len(inst.logger.logged), 1)
def test_set_thread_count_increase(self):
inst = self._makeOne()
@@ -444,7 +444,7 @@ def app(environ, start_response):
inst.logger = DummyLogger()
inst.execute()
self.assertEqual(inst.close_on_finish, True)
- self.assertTrue(len(inst.logger.logged), 1)
+ self.assertEqual(len(inst.logger.logged), 1)
def test_execute_app_returns_too_few_bytes(self):
def app(environ, start_response):
@@ -455,7 +455,19 @@ def app(environ, start_response):
inst.logger = DummyLogger()
inst.execute()
self.assertEqual(inst.close_on_finish, True)
- self.assertTrue(len(inst.logger.logged), 1)
+ self.assertEqual(len(inst.logger.logged), 1)
+
+ def test_execute_app_do_not_warn_on_head(self):
+ def app(environ, start_response):
+ start_response('200 OK', [('Content-Length', '3')])
+ return [b'']
+ inst = self._makeOne()
+ inst.request.command = 'HEAD'
+ inst.channel.server.application = app
+ inst.logger = DummyLogger()
+ inst.execute()
+ self.assertEqual(inst.close_on_finish, True)
+ self.assertEqual(len(inst.logger.logged), 0)
def test_execute_app_returns_closeable(self):
class closeable(list):
Something went wrong with that request. Please try again.