Closed drbh closed 2 years ago
^ also the example above simply closes a connection - but long term I'd like to be able to process POST
requests and send data in the responses. 🙏
Hi @drbh, I'm glad you find message-io useful :)
If I understand well, you are implementing the HTTP server part in message-io, right? Until I know the header Connection: close
is sent by clients in order to tell the server that the connection will be closed after the server response. If you send it from the server to the client I think the behaviour is not specified (unless the client implements some extra mechanism to detect that).
The NetEvent::Accepted
event is dispatched only when the client is connected and before the first client message. In order to respond to the server, the server should send the message after reading it in the NetEvent::Message
. Take into account that an HTTP request could be received spllited in several TCP packets which means several NetEvent::Message
. You will need some decoding mechanism to accumulate the message until the entire HTTP request is received.
In order to close the connection from the server perspective after sending the response, you could use handler.network().remove(endpoint)
.
Regarding the HTTP decoding part, you could use httparse, which tells if a request is completed or patial. The server will wait for more NetEvent::Message
events until the whole received data is considered completed.
I think the issue can be closed, if not, please feel free to reopen it!
After setting up
and then sending
I think I should be able to close an HTTP 1.1 request with the following message.
However the connection just hangs and fails to complete.
@lemunozm do you have any recommendations for handling HTTP requests over TCP?
message-io
is an awesome library and I'd love to replace a current server with it, but I need to be able to process HTTP requests. Thanks in advance!