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

simplify http-server example #56

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kortschak
Copy link
Contributor

I was working on an HTTP endpoint that requires a POST body, but found it difficult to understand how to hold the httpx package in a way that allowed me to obtain the body contents as the request type does not expose the content length and does not allow a read to io.EOF of the net conn.

If I attempt to read the contents of buf to completion after the headers have been read, I get a "curl: (52) Empty reply from server" from the test client and see level=ERROR msg=Stack.RecvEth err="dropped packet" and poll error: dropped packet in the server logs.

This appears to be due to the request waiting on the response because the buffer believes the conn still has data; I see this: level=ERROR msg="read body" err="i/o timeout". It seems I need to know the content length to be able to know when to stop.

To get around this I tried using the standard library's net/http package in the servers code and it works. This change is the equivalent change for the http-server example.

Note that while it works (and in the server that I am writing that prompted this does not cause any poll error: dropped packet error to be emitted, I do see that happening in the server example. I have been unable to see how the two programs differ in a way that would explain this. The error is coming from (*TCPListener).recv.

@soypat
Copy link
Owner

soypat commented Jan 6, 2025

I'd like to add this as a separate example. I'd expect the net/http library to be heavy on allocations as expected from a stdlib package. maybe rename example to http-server-stdlib

@kortschak
Copy link
Contributor Author

That seems reasonable. It would be good then to expand the httpx API to allow safe collection of request bodies.

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 this pull request may close these issues.

2 participants