{"action":"created","issue":{"url":"https://api.github.com/repos/rest-client/rest-client/issues/453","repository_url":"https://api.github.com/repos/rest-client/rest-client","labels_url":"https://api.github.com/repos/rest-client/rest-client/issues/453/labels{/name}","comments_url":"https://api.github.com/repos/rest-client/rest-client/issues/453/comments","events_url":"https://api.github.com/repos/rest-client/rest-client/issues/453/events","html_url":"https://github.com/rest-client/rest-client/issues/453","id":124823342,"number":453,"title":"Connection reuse","user":{"login":"colinmarc","id":821775,"avatar_url":"https://avatars.githubusercontent.com/u/821775?v=3","gravatar_id":"","url":"https://api.github.com/users/colinmarc","html_url":"https://github.com/colinmarc","followers_url":"https://api.github.com/users/colinmarc/followers","following_url":"https://api.github.com/users/colinmarc/following{/other_user}","gists_url":"https://api.github.com/users/colinmarc/gists{/gist_id}","starred_url":"https://api.github.com/users/colinmarc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colinmarc/subscriptions","organizations_url":"https://api.github.com/users/colinmarc/orgs","repos_url":"https://api.github.com/users/colinmarc/repos","events_url":"https://api.github.com/users/colinmarc/events{/privacy}","received_events_url":"https://api.github.com/users/colinmarc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-01-04T19:37:25Z","updated_at":"2016-08-17T21:17:30Z","closed_at":null,"body":"Hiiiii! Feature request!\r\n\r\nCurrently, rest-client provides no way to reuse a connection for multiple requests - something that's assumed to be supported in the HTTP 1.1 spec:\r\n\r\n> A significant difference between HTTP/1.1 and earlier versions of HTTP is that persistent connections are the default behavior of any HTTP connection. That is, unless otherwise indicated, the client SHOULD assume that the server will maintain a persistent connection, even after error responses from the server.\r\n\r\nObviously, rest-client isn't violating the spec by closing the connection after the first request. But connection reuse is awesome! And it would be an extremely useful feature. I can think of a few ways it could be added:\r\n\r\n - Add a `RestClient::Connection` interface, which keeps a `Net::HTTP` connection open (see [the docs](http://ruby-doc.org/stdlib-2.3.0/libdoc/net/http/rdoc/Net/HTTP.html#class-Net::HTTP-label-How+to+use+Net-3A-3AHTTP) for persistent connections) until the connection object is closed. Code with a reference to that object could then make requests using that connection. `RestClient::Connection` could provide basic thread safety, or even pooling. It could also choose to automatically reconnect or not in the case of certain errors.\r\n\r\n - Use a gem like [net-http-persistent](https://rubygems.org/gems/net-http-persistent/versions/2.9.4) as a drop in replacement for Net::HTTP. The gem internally handles connection pooling, automatic reconnects, and thread safety, but that'd mean adding magical connection reuse by default  to the most basic use-cases of rest-client.\r\n\r\nFor either of those approaches, the new functionality could also be hidden behind an optional param to `execute`: `:persistent => true` or something like that.\r\n\r\nLet me know what you think! If either sounds reasonable to you, let me know and I'd be happy to work on a PR.\r\n\r\nColin"},"comment":{"url":"https://api.github.com/repos/rest-client/rest-client/issues/comments/240551511","html_url":"https://github.com/rest-client/rest-client/issues/453#issuecomment-240551511","issue_url":"https://api.github.com/repos/rest-client/rest-client/issues/453","id":240551511,"user":{"login":"ccoenen","id":124909,"avatar_url":"https://avatars.githubusercontent.com/u/124909?v=3","gravatar_id":"","url":"https://api.github.com/users/ccoenen","html_url":"https://github.com/ccoenen","followers_url":"https://api.github.com/users/ccoenen/followers","following_url":"https://api.github.com/users/ccoenen/following{/other_user}","gists_url":"https://api.github.com/users/ccoenen/gists{/gist_id}","starred_url":"https://api.github.com/users/ccoenen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ccoenen/subscriptions","organizations_url":"https://api.github.com/users/ccoenen/orgs","repos_url":"https://api.github.com/users/ccoenen/repos","events_url":"https://api.github.com/users/ccoenen/events{/privacy}","received_events_url":"https://api.github.com/users/ccoenen/received_events","type":"User","site_admin":false},"created_at":"2016-08-17T21:17:30Z","updated_at":"2016-08-17T21:17:30Z","body":"one could probably test for the existence of `Net::HTTP::Persistent` right [here](https://github.com/rest-client/rest-client/blob/0d8f777fecfc3076df33e8b4009a4cb0519fa2be/lib/restclient/request.rb#L470-L484) and then use one or the other. The programmer would have to require the gem themselves, beforehand."}}
{"actor":{"display_login":"ccoenen"}}