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

Commit

Permalink
Merge df55c40 into 99474a4
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalextremist committed Dec 11, 2013
2 parents 99474a4 + df55c40 commit 820cfd1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/reel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
require 'reel/request'
require 'reel/response'
require 'reel/server'
require 'reel/ssl_server'
require 'reel/ssl_server' # will be deleted by #121
require 'reel/server/unix' #required by #123 after #121
require 'reel/websocket'
require 'reel/stream'

Expand Down
18 changes: 18 additions & 0 deletions lib/reel/server/unix.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 820cfd1

Please sign in to comment.