Skip to content

Commit

Permalink
Merge pull request #50 from aishek/add-timeout-options
Browse files Browse the repository at this point in the history
add http timeout options
  • Loading branch information
zaru authored May 25, 2018
2 parents 412b228 + 750d03f commit 87a6b8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ post "/push" do
subject: "mailto:[email protected]",
public_key: ENV['VAPID_PUBLIC_KEY'],
private_key: ENV['VAPID_PRIVATE_KEY']
}
},
ssl_timeout: 5, # value for Net::HTTP#ssl_timeout=, optional
open_timeout: 5, # value for Net::HTTP#open_timeout=, optional
read_timeout: 5 # value for Net::HTTP#read_timeout=, optional
)
end
```
Expand Down
4 changes: 4 additions & 0 deletions lib/webpush/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def initialize(message: "", subscription:, vapid:, **options)
def perform
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.ssl_timeout = @options[:ssl_timeout] unless @options[:ssl_timeout].nil?
http.open_timeout = @options[:open_timeout] unless @options[:open_timeout].nil?
http.read_timeout = @options[:read_timeout] unless @options[:read_timeout].nil?

req = Net::HTTP::Post.new(uri.request_uri, headers)
req.body = body
resp = http.request(req)
Expand Down

0 comments on commit 87a6b8e

Please sign in to comment.