Kong / insomnia

The open-source, cross-platform API client for GraphQL, REST, WebSockets, SSE and gRPC. With Cloud, Local and Git storage.
https://insomnia.rest
Apache License 2.0
34.49k stars 1.95k forks source link

Allow customizing curl DNS cache timeout #2606

Closed iandunn closed 3 years ago

iandunn commented 4 years ago

Problem

1529 describes how libcurl reuses connections for 60 seconds by default. Because of that, switching between local and production hosts is inconvenient, if they share the same hostname.

Setting a Connection: close header doesn't seem to help.

It seems like the way to modify that cache is with the CURLOPT_DNS_CACHE_TIMEOUT option. There doesn't seem to be a way to modify that in Insomnia, so I just have to wait 60 seconds each time I switch environments.

Ideal solution

What about introducing an environment variable that would pass the value along to CURLOPT_DNS_CACHE_TIMEOUT? That would let people set it to 0 if they want to disable the cache, or 120 if they want to extend it, etc.

Setting it per-environment would be good, since some environments can share hostnames while others don't.

Alternate solution

Allow plugins to set CURLOPT_DNS_CACHE_TIMEOUT.

cc @AdityaHarindar, @Shawyeok

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

iandunn commented 3 years ago

Still a problem.

Shawyeok commented 3 years ago

Multiple environments (qa/stage/production etc) share a same domain name will met this problem. @iandunn I found a workaround, here it is:

Send request with ip address instead of domain name, put domain name into Host header.

image image image

iandunn commented 3 years ago

Thanks @Shawyeok. I tried that, but I still get SSL errors. It looks like you're using http rather than https in your screenshots.

Maybe your server is setup to accept both? Mine redirects http to https.

Shawyeok commented 3 years ago

Maybe your server is setup to accept both? Mine redirects http to https.

Yes, we still use http protocol for most internal apis.

but I still get SSL errors.

You can disable Validate certificates in preferences if that's ok for you.

Now Validate certificates setting is effect for entire application, maybe add it in per request settings is more convenient.

iandunn commented 3 years ago

I need to use HTTPS locally to test code that relies on SSL.

I can't disable cert validation because that would be a significant security problem. Even disabling it for a single site would be a problem in situations where production and local environments share the same hostname.