cjoudrey / gluahttp

gluahttp: an http module for gopher-lua
MIT License
57 stars 23 forks source link

add func NewHttpModuleWithDo, to allow switching between multiple clients per-request #21

Closed ilius closed 6 years ago

ilius commented 6 years ago

We needed to switch between multiple http clients based on the URL/Domain.

So I added NewHttpModuleWithDo, that gets the client.Do function instead of http client. And it will be used later if it's non-nil

erikdubbelboer commented 6 years ago

Whats the advantage of this over using the current NewHttpModule with a http.Client where you set Client.Transport to your own RoundTripper?

ilius commented 6 years ago

This approach is simpler and more flexible. For example we may want to have different timeouts based on the host/domain (from URL). Timeout is part of Client, not Transport.

erikdubbelboer commented 6 years ago

Ok agreed. Maybe it would even be better to remove NewHttpModule(client) as it's the same as NewHttpModuleWithDo(client.Do) but that would break backwards compatibility.

Normally I would ask for separate pull requests for the separate commits as they address different issues but since this a small project I'll allow it :)