
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
astro-em-http-request
Advanced tools
= EM-HTTP-Client
EventMachine based HTTP Request interface. Supports streaming response processing, uses Ragel HTTP parser.
Screencast / Demo of using EM-HTTP-Request:
== Getting started
gem update --system gem install gemcutter gem tumble
gem install em-http-request
irb:0> require 'em-http'
== Simple client example
EventMachine.run { http = EventMachine::HttpRequest.new('http://127.0.0.1/').get :query => {'keyname' => 'value'}, :timeout => 10
http.callback {
p http.response_header.status
p http.response_header
p http.response
EventMachine.stop
}
}
== Multi request example Fire and wait for multiple requess to complete via the MultiRequest interface.
EventMachine.run { multi = EventMachine::MultiRequest.new
# add multiple requests to the multi-handler
multi.add(EventMachine::HttpRequest.new('http://www.google.com/').get)
multi.add(EventMachine::HttpRequest.new('http://www.yahoo.com/').get)
multi.callback {
p multi.responses[:succeeded]
p multi.responses[:failed]
EventMachine.stop
}
}
== Basic-Auth example Full basic author support. For OAuth, check examples/oauth-tweet.rb file.
EventMachine.run { http = EventMachine::HttpRequest.new('http://www.website.com/').get :head => {'authorization' => ['user', 'pass']}
http.errback { failed }
http.callback {
p http.response_header
EventMachine.stop
}
}
== POST example EventMachine.run { http1 = EventMachine::HttpRequest.new('http://www.website.com/').post :body => {"key1" => 1, "key2" => [2,3]} http2 = EventMachine::HttpRequest.new('http://www.website.com/').post :body => "some data"
# ...
}
== Streaming body processing Allows you to consume an HTTP stream of content in real-time. Each time a new piece of conent is pushed to the client, it is passed to the stream callback for you to operate on.
EventMachine.run { http = EventMachine::HttpRequest.new('http://www.website.com/').get http.stream { |chunk| print chunk }
# ...
}
== Proxy example Full transparent proxy support with support for SSL tunneling.
EventMachine.run { http = EventMachine::HttpRequest.new('http://www.website.com/').get :proxy => { :host => 'www.myproxy.com', :port => 8080, :authorization => ['username', 'password'] # authorization is optional }
== WebSocket example Bi-directional communication with WebSockets: simply pass in a ws:// resource and the client will negotiate the connection upgrade for you. On successfull handshake the callback is invoked, and any incoming messages will be passed to the stream callback. The client can also send data to the server at will by calling the "send" method!
http://www.igvita.com/2009/12/22/ruby-websockets-tcp-for-the-browser/
EventMachine.run { http = EventMachine::HttpRequest.new("ws://yourservice.com/websocket").get :timeout => 0
http.errback { puts "oops" } http.callback { puts "WebSocket connected!" http.send("Hello client") }
http.stream { |msg| puts "Recieved: #{msg}" http.send "Pong: #{msg}" } }
FAQs
Unknown package
We found that astro-em-http-request demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.