Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Commit

Permalink
Merge branch 'unix_server' into 0.6.0-milestone
Browse files Browse the repository at this point in the history
  • Loading branch information
//de committed Mar 24, 2015
2 parents a68ceee + 8cf2294 commit 508faf3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/reel.rb
Expand Up @@ -14,6 +14,7 @@
require 'reel/server'
require 'reel/server/http'
require 'reel/server/https'
require 'reel/server/unix'

require 'reel/websocket'
require 'reel/stream'
Expand Down
4 changes: 4 additions & 0 deletions lib/reel/request/body.rb
Expand Up @@ -29,6 +29,10 @@ def each
end
end

def empty?
to_str.empty?
end

# Eagerly consume the entire body as a string
def to_str
return @contents if @contents
Expand Down
18 changes: 18 additions & 0 deletions lib/reel/server/unix.rb
@@ -0,0 +1,18 @@
module Reel
class Server
class UNIX < Server

# Create a new Reel HTTPS server
#
# @option options [String] socket path to bind to
# @option options [Fixnum] backlog of requests to accept
#
# @return [Reel::Server::UNIX] Reel UNIX server actor
def initialize(socket_path, options={}, &callback)
server = Celluloid::IO::UNIXServer.new(socket_path)
options[:socket_path] = socket_path
super(server, options, &callback)
end
end
end
end
39 changes: 39 additions & 0 deletions spec/reel/unix_server_spec.rb
@@ -0,0 +1,39 @@
require 'spec_helper'
require 'net/http'

describe Reel::Server::UNIX do
let(:endpoint) { URI(example_url) }
let(:response_body) { "ohai thar" }

it 'allows connections over UNIX sockets' do
ex = nil

handler = proc do |connection|
begin
request = connection.request
request.method.should eq 'GET'
connection.respond :ok, self.response_body
rescue => ex
end
end

Dir::Tmpname.create('reel-sock') do |path|
begin
server = Reel::Server::UNIX.new(path, &handler)
sock = Net::BufferedIO.new Celluloid::IO::UNIXSocket.new(path)
request = Net::HTTP::Get.new('/')

request.exec(sock, '1.1', path)

response = Net::HTTPResponse.read_new(sock)
response.reading_body(sock, request.response_body_permitted?) { }

expect(response.body).to eq(self.response_body)
ensure
server.terminate if server && server.alive?
end
end

raise ex if ex
end
end

0 comments on commit 508faf3

Please sign in to comment.