Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect detection of status_code in Request #121

Closed
igrishaev opened this issue Sep 20, 2013 · 8 comments
Closed

Incorrect detection of status_code in Request #121

igrishaev opened this issue Sep 20, 2013 · 8 comments

Comments

@igrishaev
Copy link

When the Response was created from stream, the _status_code__get() method cannot detect status code properly, becourse it tries to sptlit start line and convert first element to int (HTTP/1.1 in my case).

resp = """HTTP/1.1 200 OK
Cache-Control: private, no-store,No-Store
Content-Length: 1024
Content-Type: application/octet-stream
ETag: ""
Server: Microsoft-IIS/7.5
content-disposition: attachment; filename=1kb.txt
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Thu, 19 Sep 2013 13:57:07 GMT

Some data...
"""

s = StringIO()
s.write(resp)
s.seek(0)

r = Response.from_file(s)
print r.status_code

Traceback (most recent call last):
  File "<string>", line 254, in run_nodebug
  File "...", line 45, in <module>
    print r.status_code
  File "C:\Python27\lib\site-packages\webob\response.py", line 272, in _status_code__get
    return int(self._status.split()[0])
ValueError: invalid literal for int() with base 10: 'HTTP/1.1'
@ei-grad
Copy link

ei-grad commented Oct 13, 2015

Webob they said. HTTP Request/Response classes they said. But they just invented their own HTTP Response format without HTTP-Version field... facepalm

@digitalresistor
Copy link
Member

@igrishaev Thanks for the report, will take a look at it.

@ei-grad That isn't helpful at all.

@ei-grad
Copy link

ei-grad commented Oct 13, 2015

  1. "20 Sep 2013"
  2. I just saw a new protocol instead of HTTP in tests, and understood that I can't help there. :-(

@igrishaev
Copy link
Author

Bert, thanks a lot!

@digitalresistor
Copy link
Member

@ei-grad I took over as maintainer pretty recently. A simple bump would have been enough for me to take look at it.

@digitalresistor
Copy link
Member

======================================================================
ERROR: tests.test_response.test_file_with_http_version
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/xistence/Projects/webob/.tox/py33/lib/python3.3/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/Users/xistence/Projects/webob/tests/test_response.py", line 422, in test_file_with_http_version
    eq_(res.status_code, 200)
  File "/Users/xistence/Projects/webob/webob/response.py", line 272, in _status_code__get
    return int(self._status.split()[0])
ValueError: invalid literal for int() with base 10: 'HTTP/1.1'

Using this test:

def test_file_with_http_version():
    inp = io.BytesIO(b'HTTP/1.1 200 OK\r\n\r\nSome data...')

    res = Response.from_file(inp)
    eq_(res.status_code, 200)
    eq_(res.status, '200 OK')

Fix is incoming.

@digitalresistor
Copy link
Member

@igrishaev If you could test master, I would appreciate it. I'll back port it to 1.5 tonight. Sorry you had to wait so long for a fix.

@igrishaev
Copy link
Author

@bertjwregeer I can't test the code the moment, sorry. I've done with the project already =) But the diff looks fine and the tests are well. It seems you can close the issue. Thanks.

digitalresistor added a commit that referenced this issue Oct 30, 2015
When reading a Response from_file we want to make sure that if it
contains an HTTP version in the status line that we strip that off, and
get just the status code and status text by itself.

Closes #121
digitalresistor added a commit that referenced this issue Oct 30, 2015
When reading a Response from_file we want to make sure that if it
contains an HTTP version in the status line that we strip that off, and
get just the status code and status text by itself.

Closes #121
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants