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

Client use aiohttp, will be hang up ,when server return 304 #505

Closed
AttentionZ opened this issue Sep 14, 2015 · 4 comments · Fixed by #549
Closed

Client use aiohttp, will be hang up ,when server return 304 #505

AttentionZ opened this issue Sep 14, 2015 · 4 comments · Fixed by #549
Labels

Comments

@AttentionZ
Copy link

As http rfc2616( http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html):
4.4 Message Length
1.Any response message which "MUST NOT" include a message-body (such as the 1xx, 204, and 304 responses and any response to a HEAD request) is always terminated by the first empty line after the header fields, regardless of the entity-header fields present in the message.

So, server return 304 without content-length header .but aiohttp client will waiting for content-length.

@asvetlov
Copy link
Member

Sorry, I don't understand what part of aiohttp is broken.
Code sample (properly formed unittest or even Pull Request are my favorites) may help very well.

@carlcarl
Copy link
Contributor

carlcarl commented Oct 3, 2015

Here I find out an example, the client output should be '' instead of 'test' because it is 304 response. requests package also gets '' output. I can help to give a PR.

Server:

import socket

# Standard socket stuff:
host = ''
port = 7777
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((host, port))
sock.listen(1)

# Loop forever, listening for requests:
while True:
    csock, caddr = sock.accept()
    req = csock.recv(1024)  # get the request, 1kB max
    print(req)
    csock.send(
        b'HTTP/1.1 304 NOT MODIFIED\r\n' +
        b'Connection: keep-alive\r\n' +
        b'\r\ntest'
    )
    csock.close()

client:

import asyncio
import aiohttp


@asyncio.coroutine
def fetch_page(url):
    response = yield from aiohttp.request('GET', url)
    return (yield from response.read())

content = asyncio.get_event_loop().run_until_complete(
    fetch_page('http://127.0.0.1:7777')
)
print(content)

@asvetlov
Copy link
Member

asvetlov commented Oct 3, 2015

Got it.
Not critical issue but worth to be fixed.

carlcarl added a commit to carlcarl/aiohttp that referenced this issue Oct 3, 2015
carlcarl added a commit to carlcarl/aiohttp that referenced this issue Oct 3, 2015
@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants