diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ff82ee..358c3a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # Changelog + * [Unreleased] Apply the `timeout` option to persistent connections * [Unreleased] Add Image API support * [Unreleased] Add Markdown search and archive output support * [Unreleased] Raise `SerpApiError` for non-200 text responses, including 404 responses from `get('/invalid')` diff --git a/README.md b/README.md index b15ba15..db019cb 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ results = client.search( | `api_key` | None | Your SerpApi API key. Use an environment variable rather than committing it to source control. | | `engine` | None | The search engine used by default, such as `google` or `google_maps`. | | `persistent` | `true` | Reuses the HTTP connection between requests. Call `client.close` when finished. | -| `timeout` | `120` | Timeout in seconds for non-persistent HTTP requests. | +| `timeout` | `120` | Timeout in seconds for HTTP requests. | | `async` | `false` | Submits searches without waiting for them to complete. It can be set on the client or per search. | | `symbolize_names` | `true` | Returns JSON object keys as symbols. Pass `false` to a search to receive string keys. | diff --git a/README.md.erb b/README.md.erb index b15ba15..db019cb 100644 --- a/README.md.erb +++ b/README.md.erb @@ -110,7 +110,7 @@ results = client.search( | `api_key` | None | Your SerpApi API key. Use an environment variable rather than committing it to source control. | | `engine` | None | The search engine used by default, such as `google` or `google_maps`. | | `persistent` | `true` | Reuses the HTTP connection between requests. Call `client.close` when finished. | -| `timeout` | `120` | Timeout in seconds for non-persistent HTTP requests. | +| `timeout` | `120` | Timeout in seconds for HTTP requests. | | `async` | `false` | Submits searches without waiting for them to complete. It can be set on the client or per search. | | `symbolize_names` | `true` | Returns JSON object keys as symbols. Pass `false` to a search to receive string keys. | diff --git a/lib/serpapi/client.rb b/lib/serpapi/client.rb index c872291..2667dc7 100644 --- a/lib/serpapi/client.rb +++ b/lib/serpapi/client.rb @@ -100,7 +100,7 @@ def initialize(params = {}) # create connection socket return unless persistent? - @socket = HTTP.persistent("https://#{BACKEND}") + @socket = HTTP.timeout(timeout).persistent("https://#{BACKEND}") end # perform a search using SerpApi.com diff --git a/spec/serpapi/client/client_spec.rb b/spec/serpapi/client/client_spec.rb index 8384d3b..724eaf3 100644 --- a/spec/serpapi/client/client_spec.rb +++ b/spec/serpapi/client/client_spec.rb @@ -159,6 +159,10 @@ expect(client.persistent).to be true end + it 'applies the timeout to the persistent socket' do + expect(client.socket.default_options.timeout_options).to eq(global_timeout: 10) + end + it 'makes a search request with valid parameters' do results = client.search(q: 'Coffee', location: 'Austin, TX') expect(results.size).to be > 5