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

Commit

Permalink
Moved Server::UNIX code into its own branch to allow #121 to move for…
Browse files Browse the repository at this point in the history
…ward.
  • Loading branch information
//de committed Dec 11, 2013
1 parent 99474a4 commit dabd7ad
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
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 dabd7ad

Please sign in to comment.