Skip to content

Commit

Permalink
Merge pull request #58 from tarantool/protocol-upgrade
Browse files Browse the repository at this point in the history
protocol upgrade basic implementation
  • Loading branch information
filonenko-mikhail authored Aug 31, 2018
2 parents 9be3e49 + 5b2266f commit 497f858
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
17 changes: 13 additions & 4 deletions http/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ local codes = require('http.codes')

local log = require('log')
local socket = require('socket')
local fiber = require('fiber')
local json = require('json')
local errno = require 'errno'

Expand Down Expand Up @@ -659,7 +658,7 @@ local function process_client(self, s, peer)
break
end
end

if is_eof then
break
end
Expand Down Expand Up @@ -822,6 +821,10 @@ local function process_client(self, s, peer)
end
end

if reason and reason.detach == true then
return reason
end

if p.proto[1] ~= 1 then
break
end
Expand Down Expand Up @@ -1128,8 +1131,14 @@ local function httpd_start(self)
error("httpd: usage: httpd:start()")
end

local server = socket.tcp_server(self.host, self.port, { name = 'http',
handler = function(...) process_client(self, ...) end })
local server = socket.tcp_server(self.host, self.port,
{ name = 'http',
handler = function(...)
local res = process_client(self, ...)
if res and res.detach == true then
res.detach_handler(self, ...)
end
end})
if server == nil then
error(sprintf("Can't create tcp_server: %s", errno.strerror()))
end
Expand Down
37 changes: 36 additions & 1 deletion test/http.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local yaml = require 'yaml'
local urilib = require('uri')

local test = tap.test("http")
test:plan(7)
test:plan(9)
test:test("split_uri", function(test)
test:plan(65)
local function check(uri, rhs)
Expand Down Expand Up @@ -370,4 +370,39 @@ test:test("server requests", function(test)
httpd:stop()
end)

local function cfgservtwo()
local detached = function(httpd, s, peer)
test:test('Detached hook is called', function(test)
test:plan(1)
test:ok(true, 'hook called')
end)
end
local path = os.getenv('LUA_SOURCE_DIR') or './'
path = fio.pathjoin(path, 'test')
local httpd = http_server.new('127.0.0.1', 12346, { app_dir = path,
log_requests = false, log_errors = false })
:route({path = '/ws', name = 'test'},
function()
return {status = 200,
body = 'ok',
detach = true,
detach_handler = detached,
}
end)
return httpd
end

test:test("server requests", function(test)
test:plan(2)

local httpd = cfgservtwo()
httpd:start()

local r = http_client.get('http://127.0.0.1:12346/ws')

test:is(r.status, 200, 'detached 200')
test:is(r.reason, 'Ok', 'detached reason')
end
)

os.exit(test:check() == true and 0 or 1)

0 comments on commit 497f858

Please sign in to comment.