boazsegev / facil.io

Your high performance web application C framework

Home Page:http://facil.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to use http_connect with keep-alive

stephenkgu opened this issue · comments

I sent http request body with the first time on_response, and process the returned second time on_response body.

so, how can I keep a http client connection alive to reuse the http socket connection to some server? Can I do that? @boazsegev

Thanks

commented

Hi @stephenkgu ,

Thank you for your question and for opening this issue 🙏🏻

Your question is a very good question and it illuminates a design flaw in the current HTTP client.

In theory, you could try to use the http_pause / http_resume features. They were designed for authoring responses, but they could be used for suspending requests... however, this will probably fail if the server disconnects the keep-alive connection before you can use it again.

I believe what you are looking for is a smarter HTTP client feature, allowing you to send requests and receive results without the need to re-establish connections (even if they were lost).

This is a feature that facil.io 0.7.x doesn't have even though it's possible to write one using the existing facil.io API.

I would love to add this to the roadmap, maybe get it working for facil.io 0.9.0 (maybe even added to an 0.8.x releases)... but sadly I don't have time to work on this.

The pieces for a "smart" client are already available. The HTTP/1.1 parser supports both client mode and server mode. You can easily write your own API / extension to make for a nice, persistent, HTTP client.

If you make something nice, I would appreciate a PR. Maybe I can learn from your design and update the simple client to use a better approach.

Thank you for opening this issue!

Kindly,
Bo.

Thanks, I used facil for few months. It's a great work, plenty of useful features.

But, I have few experiences with http client, and know little with facil. I will try to make a connection reuse client before the 0.9.0(or 0.8.x).

Regards,
stephen