This repository has been archived by the owner on Dec 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |