Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/elcuervo/net-ptth

Reverse HTTP ruby client
https://github.com/elcuervo/net-ptth

Last synced: 3 months ago
JSON representation

Reverse HTTP ruby client

Awesome Lists containing this project

README

        

# Net::PTTH

`Net::HTTP` compatible `PTTH` client

## You misspelled HTTP

No I didn't: http://wiki.secondlife.com/wiki/Reverse_HTTP

## Installation

```bash
gem install net-ptth
```

## Usage

```ruby
require 'net/ptth'
require 'net/http'

ptth = Net::PTTH.new("http://localhost:23045")
request = Net::HTTP::Post.new("/reverse")
ptth.request(request) do |incomming_request|
# Handle the body of the incomming request through the reverse connection
# This will be executed with each new request.
# incomming_request it's a Rack::Request object
# You can close the connection with:
# ptth.close
end
```

## Rack compatiblity

_Remember that letting an app handle the responses it's also in charge of
closing the reverse connection if needed_

An app can be defined to be mounted like rackup will. So you can do things like
this:

```ruby
require 'net/ptth'
require 'net/http'

ptth = Net::PTTH.new("http://localhost:23045")
ptth.app = Cuba.define do
on "dog" do
res.write "Hello? this is dog"
end
end

request = Net::HTTP::Post.new("/reverse")
ptth.request(request)
```

And let the app handle the responses of the reverse connection.
Both Cuba and sinatra were tested