-
-
Notifications
You must be signed in to change notification settings - Fork 87
Option to have http.server and http.client use UNIX sockets instead of TCP #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
61ae273
4374acf
262c4c2
b04cecf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,33 @@ describe("http.server module", function() | |
local new_headers = require "http.headers".new | ||
local cqueues = require "cqueues" | ||
local cs = require "cqueues.socket" | ||
local function simple_test(tls, version) | ||
local function assert_loop(cq, timeout) | ||
local ok, err, _, thd = cq:loop(timeout) | ||
if not ok then | ||
if thd then | ||
err = debug.traceback(thd, err) | ||
end | ||
error(err, 2) | ||
end | ||
end | ||
local function simple_test(tls, version, path) | ||
local cq = cqueues.new() | ||
local s = server.listen { | ||
host = "localhost"; | ||
port = 0; | ||
} | ||
local options = {} | ||
if path then | ||
options.path = path | ||
else | ||
options.host = "localhost" | ||
options.port = 0 | ||
end | ||
options.version = version | ||
options.tls = tls | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. options doesn't need/want TLS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed tonight that it does; instead it assumes (at least on my system) that it needs to generate a certificate (which breaks atm because certificates are pending). |
||
local s = server.listen(options) | ||
assert(s:listen()) | ||
local _, host, port = s:localname() | ||
local host, port | ||
if not path then | ||
local _ | ||
_, host, port = s:localname() | ||
end | ||
local on_stream = spy.new(function(stream) | ||
stream:get_headers() | ||
stream:shutdown() | ||
|
@@ -22,12 +41,16 @@ describe("http.server module", function() | |
s:close() | ||
end) | ||
cq:wrap(function() | ||
local conn = client.connect { | ||
host = host; | ||
port = port; | ||
tls = tls; | ||
version = version; | ||
} | ||
local client_options = {} | ||
if path then | ||
client_options.path = path | ||
else | ||
client_options.host = host | ||
client_options.port = port | ||
end | ||
client_options.tls = tls | ||
client_options.version = version | ||
local conn = client.connect(client_options) | ||
local stream = conn:new_stream() | ||
local headers = new_headers() | ||
headers:append(":method", "GET") | ||
|
@@ -41,16 +64,16 @@ describe("http.server module", function() | |
assert.truthy(cq:empty()) | ||
assert.spy(on_stream).was.called() | ||
end | ||
it("works with plain http 1.1", function() | ||
it("works with plain http 1.1 using IP", function() | ||
simple_test(false, 1.1) | ||
end) | ||
it("works with https 1.1", function() | ||
it("works with https 1.1 using IP", function() | ||
simple_test(true, 1.1) | ||
end) | ||
it("works with plain http 2.0", function() | ||
it("works with plain http 2.0 using IP", function() | ||
simple_test(false, 2.0) | ||
end); | ||
(require "http.tls".has_alpn and it or pending)("works with https 2.0", function() | ||
(require "http.tls".has_alpn and it or pending)("works with https 2.0 using IP", function() | ||
simple_test(true, 2.0) | ||
end) | ||
it("taking socket from underlying connection is handled well by server", function() | ||
|
@@ -84,4 +107,38 @@ describe("http.server module", function() | |
assert.truthy(cq:empty()) | ||
assert.spy(on_stream).was.called() | ||
end) | ||
--[[ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you move this comment down to above the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added to my todo list, as well as the below comment |
||
-- | ||
-- Until there is a way to generate OpenSSL contexts in this file for | ||
-- UNIX domain sockets, there is no way to use TLS with this. Because | ||
-- of this, the status for using TLS with UNIX domain sockets is | ||
-- pending. | ||
-- | ||
--]] | ||
local socket_path = os.tmpname() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not generate one per test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to? If you remove it in the finally() call, it should be done after the it() call, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that's fine I guess. |
||
os.remove(socket_path) -- in case it was generated automatically | ||
it("works with plain http 1.1 using UNIX socket domain", function() | ||
simple_test(false, 1.1, socket_path) | ||
finally(function() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you need to call |
||
os.remove(socket_path) | ||
end) | ||
end) | ||
pending("works with https 1.1 using UNIX socket domain", function() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this pending? oh, just saw the comment down on line 99. please move it up? |
||
simple_test(true, 1.1, socket_path) | ||
finally(function() | ||
os.remove(socket_path) | ||
end) | ||
end) | ||
it("works with plain http 2.0 using UNIX socket domain", function() | ||
simple_test(false, 2.0, socket_path) | ||
finally(function() | ||
os.remove(socket_path) | ||
end) | ||
end); | ||
pending("works with https 2.0 using UNIX socket domain", function() | ||
simple_test(true, 2.0, socket_path) | ||
finally(function() | ||
os.remove(socket_path) | ||
end) | ||
end) | ||
end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might need to rebase again, as
assert_loop
was factored out.