serviejs / popsicle

Simple HTTP requests for node and the browser
MIT License
246 stars 19 forks source link

Using a proxy / agent option is ignored #142

Open janus-reith opened 3 years ago

janus-reith commented 3 years ago

Using popsicle.fetch the agent option seems to be ignored.

I'm unable to use a proxy with popsicle for that reason, passing agent e.g. to node-fetch works fine. popsicle-proxy-agent which is deprecated and uses a function createTransport which doesn't seem to exist anymore also suggests just passing agent now.

I tried looking at the code of both toFetch and serviejs but got no clue how to accomplish this.

blakeembrey commented 3 years ago

There isn’t any agent option for the fetch function - only things documented in the README. The agent isn’t supported because popsicle uses HTTP2 where possible by default, which doesn’t support HTTP agents. It’s also the reason for deprecating the middleware unfortunately.

One possibility is we add it to https://github.com/serviejs/popsicle-transport-http or revive the plugin you mentioned and it’ll only support HTTP1 for now. I’m actually not entirely sure how to proxy over HTTP2 which is why I haven’t build a generic utility again. Would HTTP1 only be acceptable for now?

Edit: Looking into how the proxy is implemented, I should be able to add proxying with HTTP2 support. I can make an attempt this week or weekend.

janus-reith commented 3 years ago

Thanks for the quick response, and thanks for looking into it! For my specific usecase HTTP1 would probably be fine, I‘m expecting larger bottlenecks on other levels.

Let me know if I can help in any way.

blakeembrey commented 3 years ago

I fell way behind on this but made good progress this weekend. I've refactored some of the underlying HTTP transport in node.js to accept socket creation asynchronously (mostly in https://github.com/serviejs/popsicle-transport-http/commit/b31ab39b750fbaed579f4205f823831285a6dea7). With this in place I can release a new major version and add support for HTTP proxies via a configuration option that just returns a proxy asynchronously. I'll look at creating that plugin this week.