-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
resp.content.read(chunk_size)
returns HTTP headers instead of just body.
#3329
Comments
GitMate.io thinks the contributor most likely able to help you is @asvetlov. Possibly related issues are #2711 (No content), #2062 (Content-Length header), #2183 ('None' in HTTP headers), #813 (Why uppercase HTTP headers?), and #14 (HttpResponse doesn't parse response body without Content-Length header and Connection: close). |
It's not a chunked encoded body but |
Its not form data. Its a large XML payload. |
Check |
Sorry, I'm confused. I want the body, not the headers. Essentially, I want to be able to loop over body chunks to write out the data file, without headers. |
Here is the code (a test using @pytest.mark.asyncio
async def test_listing_fetch(aresponses):
# custom handler to respond with chunks
async def my_handler(request):
LOGGER.debug('in handler')
my_boundary = 'boundary'
xmlfile_path = Path(__file__).resolve().parent.joinpath('6729.xml')
LOGGER.debug('xml file path = {xmlfile_path}')
resp = aresponses.Response(status=200,
reason='OK',
)
resp.enable_chunked_encoding()
await resp.prepare(request)
xmlfile = open(xmlfile_path, 'rb')
LOGGER.debug('opened xml file for serving')
with MultipartWriter('application/xml', boundary=my_boundary) as mpwriter:
mpwriter.append(xmlfile)
LOGGER.debug('appended chunk')
await mpwriter.write(resp, close_boundary=False)
LOGGER.debug('wrote chunk')
xmlfile.close()
return resp
aresponses.add('foo.com', '/feed/6715', 'get', response=my_handler)
with isolated_filesystem():
l = Listing('http://foo.com/feed/6715')
await l.fetch()
assert l._path.joinpath(l._filename).is_file() |
Please read about multipart encoding first: https://en.wikipedia.org/wiki/MIME#Multipart_messages Your mocked server is invalid: P.S. |
So how to make a server then that emulates support for Range headers? Here is a HEAD request on the server I'm trying to emulate:
How can I make Thanks for your help. |
It should respond like this when a Range: request is given:
Is this type of server supported in aiohttp? using |
The latest response is neither streaming nor multipart. It is just a regular response with truncated body: I'm closing the issue because it is not about aiohttp bugs/improvements but teaching @bradwood HTTP protocol. Please use another site for it. Maybe StackOverflow fits better. |
I don't need to be taught about the HTTP protocol on this forum. @asvetlov. I am perfectly capable of reading wikipedia and RFCs just like you. I am asking about aiohttp support for this. Does it support it, or not? Please refer me to the documentation, if so, or tell me that it doesn't. Did you not read this?
FWIW, while I may have made a mistake in interpretation earlier, I don't appreciate your comment about teaching me HTTP. There is no need for rudeness. I've been reading your responses to many people on this forum - you are extremely rude with many of them. You like to tell them to read wikipedia, instead of actually being helpful. Its condescending and unhelpful. In many cases, these questions are as a result of poorly documented examples of how Look, don't get me wrong, I appreciate your contribution to the community, but it would be much better if (a) the docs were improved so that answers could be found without raising tickets and (b) if you were less dismissing and insulting to people who have legitimate questions about the codebase, not the protocol. |
|
Ok great -- this is helpful - I will do that. I thought there might be a higher level API that did this, as it the case for Streams and Multipart -- so not an unreasonable question IMHO.
Ok, well initially I thought it was a bug, rather than a usage query and I'd assert that insofar as the way in which something can be used, or not used, is part of it's development agenda. If you make something that is difficult to use, or understand, then surely it's a (usability) bug?
Ok -- fair enough... I think the Robustness Principle should apply here too... I honestly thought this was a bug/weakness in the API which was a legitimate query. While I don't know every HTTP RFC by heart, I do think I know enough about it to ask relevant questions about
When time permits, and I've got a working example for this topic, I'll try to do exactly that. |
Sorry for my attitude and thanks for understanding. |
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. |
Long story short
I am doing a chunked download from a Range enabled HTTP server and it appears to be including HTTP headers, rather than just the body.
Am i using the library incorrectly, or is this a bug?
How do I get only chunks of the body, excluding the HTTP headers and the
--boundary
delimiter?Thanks!
Expected behaviour
I expected that only pieces of the HTTP body would be returned when calling
resp.content.read(chunk_size)
Actual behaviour
The chunks come down correctly, but the headers and boundary delimiters are present in the resulting file.
Steps to reproduce
Here is the code in question:
and here is the head of the resulting file:
Your environment
The text was updated successfully, but these errors were encountered: