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

Upgrade Via HyperRequest Sends Bogus Data At End of Connection #169

Open
git-blame opened this issue Mar 16, 2018 · 0 comments
Open

Upgrade Via HyperRequest Sends Bogus Data At End of Connection #169

git-blame opened this issue Mar 16, 2018 · 0 comments

Comments

@git-blame
Copy link

The example snippet to upgrade a HyperRequest to a websocket client works fine. I'm basing a server on it.

Server::http("0.0.0.0:80").unwrap().handle(move |req: Request, res: Response| {
    match HyperRequest(req).into_ws() {
        Ok(upgrade) => {
...

But there is a problem. At the end of my connection and I return from the handler, a client receives some "bogus" data. This data is due to the fact that the res in the handler is unused. According to the hyper doc
(https://docs.rs/hyper/0.10.6/hyper/server/response/struct.Response.html):

There is a Drop implementation for Response that will automatically write the head and flush the
body, if the handler has not already done so, so that the server doesn't accidentally leave
dangling requests.

My work-around is to flush the stream and wait a bit, hoping that the client has closed the connection upon receiving the Close message.

It would be nice if there was an accept/reject function that writes to res. In this way, res is marked as processed and won't get flushed.

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

No branches or pull requests

1 participant