{"id":20166215,"url":"https://github.com/utkarsh2102/ruby-excon","last_synced_at":"2026-05-15T07:09:29.682Z","repository":{"id":40531056,"uuid":"232646538","full_name":"utkarsh2102/ruby-excon","owner":"utkarsh2102","description":"This repository is for maintaing the excon gem in Debian.","archived":false,"fork":false,"pushed_at":"2023-03-15T23:16:34.000Z","size":379,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-13T14:53:07.850Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/utkarsh2102.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.txt","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-08T19:53:58.000Z","updated_at":"2023-01-24T17:14:52.000Z","dependencies_parsed_at":"2025-01-13T14:46:51.965Z","dependency_job_id":"525d0448-91e4-41e5-ace5-4da342ba0169","html_url":"https://github.com/utkarsh2102/ruby-excon","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utkarsh2102%2Fruby-excon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utkarsh2102%2Fruby-excon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utkarsh2102%2Fruby-excon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/utkarsh2102%2Fruby-excon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/utkarsh2102","download_url":"https://codeload.github.com/utkarsh2102/ruby-excon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241602139,"owners_count":19989081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T00:42:58.301Z","updated_at":"2026-05-15T07:09:29.640Z","avatar_url":"https://github.com/utkarsh2102.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# excon\n\nUsable, fast, simple Ruby HTTP 1.1\n\nExcon was designed to be simple, fast and performant. It works great as a general HTTP(s) client and is particularly well suited to usage in API clients.\n\n[![Build Status](https://secure.travis-ci.org/geemus/excon.png)](http://travis-ci.org/geemus/excon)\n[![Dependency Status](https://gemnasium.com/geemus/excon.png)](https://gemnasium.com/geemus/excon)\n[![Gem Version](https://fury-badge.herokuapp.com/rb/excon.png)](http://badge.fury.io/rb/excon)\n[![Gittip](http://img.shields.io/gittip/geemus.png)](https://www.gittip.com/geemus/)\n\n## Getting Started\n\nInstall the gem.\n\n```\n$ sudo gem install excon\n```\n\nRequire with rubygems.\n\n```ruby\nrequire 'rubygems'\nrequire 'excon'\n```\n\nThe easiest way to get started is by using one-off requests. Supported one-off request methods are `connect`, `delete`, `get`, `head`, `options`, `post`, `put`, and `trace`. Requests return a response object which has `body`, `headers`, `remote_ip` and `status` attributes.\n\n```ruby\nresponse = Excon.get('http://geemus.com')\nresponse.body       # =\u003e \"...\"\nresponse.headers    # =\u003e {...}\nresponse.remote_ip  # =\u003e \"...\"\nresponse.status     # =\u003e 200\n```\n\nFor API clients or other ongoing usage, reuse a connection across multiple requests to share options and improve performance.\n\n```ruby\nconnection = Excon.new('http://geemus.com')\nget_response = connection.get\npost_response = connection.post(:path =\u003e '/foo')\ndelete_response = connection.delete(:path =\u003e '/bar')\n```\n\nBy default, each connection is non-persistent. This means that each request made against a connection behaves like a\none-off request. Each request will establish a socket connection to the server, then close the socket once the request\nis complete.\n\nTo use a persistent connection, use the `:persistent` option:\n\n```ruby\nconnection = Excon.new('http://geemus.com', :persistent =\u003e true)\n```\n\nThe initial request will establish a socket connection to the server and leave the socket open. Subsequent requests\nwill reuse that socket. You may call `Connection#reset` at any time to close the underlying socket, and the next request\nwill establish a new socket connection.\n\nYou may also control persistence on a per-request basis by setting the `:persistent` option for each request.\n\n```ruby\nconnection = Excon.new('http://geemus.com') # non-persistent by default\nconnection.get # socket established, then closed\nconnection.get(:persistent =\u003e true) # socket established, left open\nconnection.get(:persistent =\u003e true) # socket reused\nconnection.get # socket reused, then closed\n\nconnection = Excon.new('http://geemus.com', :persistent =\u003e true)\nconnection.get # socket established, left open\nconnection.get(:persistent =\u003e false) # socket reused, then closed\nconnection.get(:persistent =\u003e false) # socket established, then closed\nconnection.get # socket established, left open\nconnection.get # socket reused\n```\n\nNote that sending a request with `:persistent =\u003e false` to close the socket will also send `Connection: close` to inform\nthe server the connection is no longer needed. `Connection#reset` will simply close our end of the socket.\n\n\n## Options\n\nBoth one-off and persistent connections support many other options. The final options for a request are built up by starting with `Excon.defaults`, then merging in options from the connection and finally merging in any request options. In this way you have plenty of options on where and how to set options and can easily setup connections or defaults to match common options for a particular endpoint.\n\nHere are a few common examples:\n\n```ruby\n# Custom headers\nExcon.get('http://geemus.com', :headers =\u003e {'Authorization' =\u003e 'Basic 0123456789ABCDEF'})\nconnection.get(:headers =\u003e {'Authorization' =\u003e 'Basic 0123456789ABCDEF'})\n\n# Changing query strings\nconnection = Excon.new('http://geemus.com/')\nconnection.get(:query =\u003e {:foo =\u003e 'bar'})\n\n# POST body encoded with application/x-www-form-urlencoded\nExcon.post('http://geemus.com',\n  :body =\u003e 'language=ruby\u0026class=fog',\n  :headers =\u003e { \"Content-Type\" =\u003e \"application/x-www-form-urlencoded\" })\n\n# same again, but using URI to build the body of parameters\nExcon.post('http://geemus.com',\n  :body =\u003e URI.encode_www_form(:language =\u003e 'ruby', :class =\u003e 'fog'),\n  :headers =\u003e { \"Content-Type\" =\u003e \"application/x-www-form-urlencoded\" })\n\n# request takes a method option, accepting either a symbol or string\nconnection.request(:method =\u003e :get)\nconnection.request(:method =\u003e 'GET')\n\n# expect one or more status codes, or raise an error\nconnection.request(:expects =\u003e [200, 201], :method =\u003e :get)\n\n# this request can be repeated safely, so retry on errors up to 3 times\nconnection.request(:idempotent =\u003e true)\n\n# this request can be repeated safely, retry up to 6 times\nconnection.request(:idempotent =\u003e true, :retry_limit =\u003e 6)\n\n# set longer read_timeout (default is 60 seconds)\nconnection.request(:read_timeout =\u003e 360)\n\n# set longer write_timeout (default is 60 seconds)\nconnection.request(:write_timeout =\u003e 360)\n\n# Enable the socket option TCP_NODELAY on the underlying socket.\n#\n# This can improve response time when sending frequent short\n# requests in time-sensitive scenarios.\n#\nconnection = Excon.new('http://geemus.com/', :tcp_nodelay =\u003e true)\n\n# opt-in to omitting port from http:80 and https:443\nconnection = Excon.new('http://geemus.com/', :omit_default_port =\u003e true)\n\n# set longer connect_timeout (default is 60 seconds)\nconnection = Excon.new('http://geemus.com/', :connect_timeout =\u003e 360)\n\n# opt-out of nonblocking operations for performance and/or as a workaround\nconnection = Excon.new('http://geemus.com/', :nonblock =\u003e false)\n\n# use basic authentication by supplying credentials in the URL or as parameters\nconnection = Excon.new('http://username:password@secure.geemus.com')\nconnection = Excon.new('http://secure.geemus.com',\n  :user =\u003e 'username', :password =\u003e 'password')\n```\n\n## Chunked Requests\n\nYou can make `Transfer-Encoding: chunked` requests by passing a block that will deliver chunks, delivering an empty chunk to signal completion.\n\n```ruby\nfile = File.open('data')\n\nchunker = lambda do\n  # Excon.defaults[:chunk_size] defaults to 1048576, ie 1MB\n  # to_s will convert the nil received after everything is read to the final empty chunk\n  file.read(Excon.defaults[:chunk_size]).to_s\nend\n\nExcon.post('http://geemus.com', :request_block =\u003e chunker)\n\nfile.close\n```\n\nIterating in this way allows you to have more granular control over writes and to write things where you can not calculate the overall length up front.\n\n## Pipelining Requests\n\nYou can make use of HTTP pipelining to improve performance. Instead of the normal request/response cycle, pipelining sends a series of requests and then receives a series of responses. You can take advantage of this using the `requests` method, which takes an array of params where each is a hash like request would receive and returns an array of responses.\n\n```ruby\nconnection = Excon.new('http://geemus.com/')\nconnection.requests([{:method =\u003e :get}, {:method =\u003e :get}])\n```\n\nBy default, each call to `requests` will use a separate persistent socket connection. To make multiple `requests` calls\nusing a single persistent connection, set `:persistent =\u003e true` when establishing the connection.\n\n## Streaming Responses\n\nYou can stream responses by passing a block that will receive each chunk.\n\n```ruby\nstreamer = lambda do |chunk, remaining_bytes, total_bytes|\n  puts chunk\n  puts \"Remaining: #{remaining_bytes.to_f / total_bytes}%\"\nend\n\nExcon.get('http://geemus.com', :response_block =\u003e streamer)\n```\n\nIterating over each chunk will allow you to do work on the response incrementally without buffering the entire response first. For very large responses this can lead to significant memory savings.\n\n## Proxy Support\n\nYou can specify a proxy URL that Excon will use with both HTTP and HTTPS connections:\n\n```ruby\nconnection = Excon.new('http://geemus.com', :proxy =\u003e 'http://my.proxy:3128')\nconnection.request(:method =\u003e 'GET')\n\nExcon.get('http://geemus.com', :proxy =\u003e 'http://my.proxy:3128')\n```\n\nThe proxy URL must be fully specified, including scheme (e.g. \"http://\") and port.\n\nProxy support must be set when establishing a connection object and cannot be overridden in individual requests.\n\nNOTE: Excon will use the environment variables `http_proxy` and `https_proxy` if they are present. If these variables are set they will take precedence over a :proxy option specified in code. If \"https_proxy\" is not set, the value of \"http_proxy\" will be used for both HTTP and HTTPS connections.\n\n## Reusable ports\n\nFor advanced cases where you'd like to reuse the local port assigned to the excon socket in another socket, use the `:reuseaddr` option.\n\n```ruby\nconnection = Excon.new('http://geemus.com', :reuseaddr =\u003e true)\nconnection.get\n\ns = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)\ns.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)\nif defined?(Socket::SO_REUSEPORT)\n  s.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEPORT, true)\nend\n\ns.bind(Socket.pack_sockaddr_in(connection.local_port, connection.local_address))\ns.connect(Socket.pack_sockaddr_in(80, '1.2.3.4'))\nputs s.read\ns.close\n```\n\n## Unix Socket Support\n\nThe Unix socket will work for one-off requests and multiuse connections.  A Unix socket path must be provided separate from the resource path.\n\n```ruby\nconnection = Excon.new('unix:///', :socket =\u003e '/tmp/unicorn.sock')\nconnection.request(:method =\u003e :get, :path =\u003e '/ping')\n\nExcon.get('unix:///ping', :socket =\u003e '/tmp/unicorn.sock')\n```\n\nNOTE: Proxies will be ignored when using a Unix socket, since a Unix socket has to be local.\n\n## Stubs\n\nYou can stub out requests for testing purposes by enabling mock mode on a connection.\n\n```ruby\nconnection = Excon.new('http://example.com', :mock =\u003e true)\n```\n\nOr by enabling mock mode for a request.\n\n```ruby\nconnection.request(:method =\u003e :get, :path =\u003e 'example', :mock =\u003e true)\n```\n\nAdd stubs by providing the request_attributes to match and response attributes to return. Response params can be specified as either a hash or block which will yield with response_params.\n\n```ruby\nExcon.stub({}, {:body =\u003e 'body', :status =\u003e 200})\nExcon.stub({}, lambda {|request_params| :body =\u003e request_params[:body], :status =\u003e 200})\n```\n\nOmitted attributes are assumed to match, so this stub will match *any* request and return an Excon::Response with a body of 'body' and status of 200.  You can add whatever stubs you might like this way and they will be checked against in the order they were added, if none of them match then excon will raise an `Excon::Errors::StubNotFound` error to let you know.\n\nTo remove a previously defined stub, or all stubs:\n\n```ruby\nExcon.unstub({})  # remove first/oldest stub matching {}\nExcon.stubs.clear # remove all stubs\n```\n\nFor example, if using RSpec for your test suite you can clear stubs after running each example:\n\n```ruby\nconfig.after(:each) do\n  Excon.stubs.clear\nend\n```\n\nYou can also modify `Excon.defaults` to set a stub for all requests, so for a test suite you might do this:\n\n```ruby\n# Mock by default and stub any request as success\nconfig.before(:all) do\n  Excon.defaults[:mock] = true\n  Excon.stub({}, {:body =\u003e 'Fallback', :status =\u003e 200})\n  # Add your own stubs here or in specific tests...\nend\n```\n\n## Instrumentation\n\nExcon calls can be timed using the [ActiveSupport::Notifications](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html) API.\n\n```ruby\nconnection = Excon.new(\n  'http://geemus.com',\n  :instrumentor =\u003e ActiveSupport::Notifications\n)\n```\n\nExcon will then instrument each request, retry, and error.  The corresponding events are named excon.request, excon.retry, and excon.error respectively.\n\n```ruby\nActiveSupport::Notifications.subscribe(/excon/) do |*args|\n  puts \"Excon did stuff!\"\nend\n```\n\nIf you prefer to label each event with something other than \"excon,\" you may specify\nan alternate name in the constructor:\n\n```ruby\nconnection = Excon.new(\n  'http://geemus.com',\n  :instrumentor =\u003e ActiveSupport::Notifications,\n  :instrumentor_name =\u003e 'my_app'\n)\n```\n\nIf you don't want to add activesupport to your application, simply define a class which implements the same #instrument method like so:\n\n```ruby\nclass SimpleInstrumentor\n  class \u003c\u003c self\n    attr_accessor :events\n\n    def instrument(name, params = {}, \u0026block)\n      puts \"#{name} just happened.\"\n      yield if block_given?\n    end\n  end\nend\n```\n\nThe #instrument method will be called for each HTTP request, response, retry, and error.\n\nFor debugging purposes you can also use Excon::StandardInstrumentor to output all events to stderr. This can also be specified by setting the `EXCON_DEBUG` ENV var.\n\nSee [the documentation for ActiveSupport::Notifications](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html) for more detail on using the subscription interface.  See excon's instrumentation_test.rb for more examples of instrumenting excon.\n\n## HTTPS/SSL Issues\n\nBy default excon will try to verify peer certificates when using SSL for HTTPS. Unfortunately on some operating systems the defaults will not work. This will likely manifest itself as something like `Excon::Errors::SocketError: SSL_connect returned=1 ...`\n\nIf you have the misfortune of running into this problem you have a couple options. If you have certificates but they aren't being auto-discovered, you can specify the path to your certificates:\n\n```ruby\nExcon.defaults[:ssl_ca_path] = '/path/to/certs'\n```\n\nFailing that, you can turn off peer verification (less secure):\n\n```ruby\nExcon.defaults[:ssl_verify_peer] = false\n```\n\nEither of these should allow you to work around the socket error and continue with your work.\n\n## Getting Help\n\n* [General Documentation](http://excon.io).\n* Ask specific questions on [Stack Overflow](http://stackoverflow.com/questions/tagged/excon).\n* Report bugs and discuss potential features in [Github issues](https://github.com/geemus/excon/issues).\n\n## Contributing\n\nPlease refer to [CONTRIBUTING.md](https://github.com/geemus/excon/blob/master/CONTRIBUTING.md).\n\n## License\n\nPlease refer to [LICENSE.md](https://github.com/geemus/excon/blob/master/LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futkarsh2102%2Fruby-excon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Futkarsh2102%2Fruby-excon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Futkarsh2102%2Fruby-excon/lists"}