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

HTTP 1.0 response without Content-Length header is not properly handled #159

Closed
emiliedns opened this issue Apr 15, 2020 · 0 comments · Fixed by #167
Closed

HTTP 1.0 response without Content-Length header is not properly handled #159

emiliedns opened this issue Apr 15, 2020 · 0 comments · Fixed by #167

Comments

@emiliedns
Copy link

emiliedns commented Apr 15, 2020

Hello,
First thank you a lot for your work!
Then, when I was writting unittest for my code which is using asks, I ran into (what I think is) a bug.
I used http.server which is HTTP 1.0 by default and which is not sending Content-Length header (spec says server doesn't have to on response if its closes the connection at the end of the message).
asks doesn't seems to cope with that:
Here is an example to reproduce the bug:
(if you uncomment the content-length line all will be fine)

from http.server import HTTPServer, BaseHTTPRequestHandler
import asks
import trio
import threading 
import time
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):

    def do_GET(self):
        print("get")
        response = b'Hello, world!'
        self.send_response(200)
        self.send_header('Content-type', 'text/html')
        #self.send_header('Content-length', len(response))
        self.end_headers()
        self.wfile.write(response)
        return

def start_server(path, port=8000):
    '''Start a simple webserver serving path on port'''
    httpd = HTTPServer(('localhost', 8000), SimpleHTTPRequestHandler)

    """httpd.socket = ssl.wrap_socket(httpd.socket,
                                   keyfile=f"{dir_test}/localhost.key",
                                   certfile=f"{dir_test}/localhost.crt", server_side=True)"""
    httpd.serve_forever()



async def main():
   daemon = threading.Thread(name='daemon_server',
                                  target=start_server,
                                  args=('.', 8000))
   daemon.setDaemon(True)  # Set as a daemon so it will be killed once the main thread is dead.
   daemon.start()
   time.sleep(1)
   r = await asks.get('http://localhost:8000/')
   print(r.content)

if __name__ == '__main__':
   trio.run(main)



I think this issue : #136 may be the same (at first my server was serving ssl and the error was looking the same than that)

Best regards,
Emilie.

@emiliedns emiliedns changed the title HTTP 1.0 response without Content-Length header are not properly handled HTTP 1.0 response without Content-Length header is not properly handled Apr 15, 2020
ehaas added a commit to lagerdata/asks that referenced this issue Jun 25, 2020
HTTP/1.0 responses do not require a Content-Length header; see here:
https://tools.ietf.org/html/rfc1945#section-7.2.2 (content length is implicitly
defined by the closing of the connection)

Therefore if no Content-Length is present, and the response version is 1.0,
read the response body.

Fixes theelous3#159
ehaas added a commit to lagerdata/asks that referenced this issue Jun 25, 2020
HTTP/1.0 responses do not require a Content-Length header; see here:
https://tools.ietf.org/html/rfc1945#section-7.2.2 (content length is implicitly
defined by the closing of the connection)

Therefore if no Content-Length is present, and the response version is 1.0,
read the response body.

Fixes theelous3#159
ehaas added a commit to lagerdata/asks that referenced this issue Jun 30, 2020
HTTP/1.0 responses do not require a Content-Length header; see here:
https://tools.ietf.org/html/rfc1945#section-7.2.2 (content length is implicitly
defined by the closing of the connection)

Therefore if no Content-Length is present, and the response version is 1.0,
read the response body.

Fixes theelous3#159
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant