Update test server.
This commit is contained in:
parent
4f75627e5c
commit
c8a0f7ea8e
@ -78,6 +78,7 @@ after_test:
|
||||
- .appveyor\pack_artifact.bat lua-curl bin-rock
|
||||
|
||||
on_failure:
|
||||
- ps: Stop-Process -Id $TestServer.Id
|
||||
- ps: $path = "$env:APPVEYOR_BUILD_FOLDER\server.stderr.txt"; if (Test-Path $path -PathType Leaf) { Push-AppveyorArtifact $path; } else { echo "File $path does not exist"; }
|
||||
- ps: $path = "$env:APPVEYOR_BUILD_FOLDER\server.stdout.txt"; if (Test-Path $path -PathType Leaf) { Push-AppveyorArtifact $path; } else { echo "File $path does not exist"; }
|
||||
|
||||
|
1
lakefile
1
lakefile
@ -32,6 +32,7 @@ target('test', install, function()
|
||||
run_test('test_form.lua')
|
||||
run_test('test_pause02.c.lua')
|
||||
run_test('test_curl.lua')
|
||||
run_test('test_mime.lua')
|
||||
run_test('test_multi_callback.lua')
|
||||
run_test('test_multi_nested_callback.lua')
|
||||
|
||||
|
@ -4,7 +4,7 @@ local function prequire(m)
|
||||
return err
|
||||
end
|
||||
|
||||
local uv = prequire "lluv"
|
||||
local uv = prequire "lluv-"
|
||||
local Pegasus = require (uv and "lluv.pegasus" or "pegasus")
|
||||
local Router = require "pegasus.plugins.router"
|
||||
local json = require "dkjson"
|
||||
@ -37,20 +37,44 @@ local server = Pegasus:new{
|
||||
host = '127.0.0.1', port = 7090, timout = 10
|
||||
}
|
||||
|
||||
local function recvFullBody(request, T1)
|
||||
local body, counter = {}, 0
|
||||
|
||||
local result, status
|
||||
while true do
|
||||
result, status = request:receiveBody()
|
||||
if result then
|
||||
counter = 0
|
||||
body[#body + 1] = result
|
||||
elseif status ~= 'timeout' then
|
||||
break
|
||||
else
|
||||
counter = counter + 1
|
||||
if counter > T1 then break end
|
||||
end
|
||||
end
|
||||
|
||||
return table.concat(body), status
|
||||
end
|
||||
|
||||
r:get('/get', function(request, response)
|
||||
local headers = request:headers()
|
||||
local params = request:params()
|
||||
local path = request:path()
|
||||
local ip = request.ip
|
||||
|
||||
local body, status = recvFullBody(request, 15)
|
||||
|
||||
local result = json.encode({
|
||||
args = params;
|
||||
headers = headers;
|
||||
origin = ip;
|
||||
content = body;
|
||||
url = 'http://127.0.0.1' .. path;
|
||||
}, {indent = true})
|
||||
|
||||
response:statusCode(200)
|
||||
response:addHeader('Connection', 'close')
|
||||
response:contentType('application/json')
|
||||
response:write(result)
|
||||
end)
|
||||
@ -71,13 +95,7 @@ r:post('/post', function(request, response, params)
|
||||
local path = request:path()
|
||||
local ip = request.ip
|
||||
|
||||
local body = {}
|
||||
while true do
|
||||
local result, status = request:receiveBody()
|
||||
if result then body[#body + 1] = result
|
||||
elseif status ~= 'timeout' then break end
|
||||
end
|
||||
body = table.concat(body)
|
||||
local body, status = recvFullBody(request, 15)
|
||||
|
||||
local name, data, form = decode_form(body)
|
||||
if name then
|
||||
@ -95,6 +113,7 @@ r:post('/post', function(request, response, params)
|
||||
}, {indent = true})
|
||||
|
||||
response:statusCode(200)
|
||||
response:addHeader('Connection', 'close')
|
||||
response:contentType('application/json')
|
||||
response:write(result)
|
||||
end)
|
||||
|
@ -17,7 +17,7 @@ local utils = require "utils"
|
||||
|
||||
local weak_ptr, gc_collect, dump_mime_ = utils.import('weak_ptr', 'gc_collect', 'dump_mime')
|
||||
|
||||
local dump_mime_url = 'http://127.0.0.1:7090/post'
|
||||
local dump_mime_url = 'http://127.0.0.1:7090/get'
|
||||
|
||||
local function is_freed(c)
|
||||
return not not string.find(tostring(c), '%(freed%)')
|
||||
@ -246,16 +246,16 @@ function test_data_should_not_unset_on_nil()
|
||||
assert_match('Content%-Disposition:.-name="test2"', info)
|
||||
assert_match('X%-Custom%-Header:%s*hello', info)
|
||||
|
||||
part:data('!!!', 'text/xml', nil)
|
||||
part:data('!!!!!', 'text/xml', nil)
|
||||
info = assert_string(dump_mime(mime))
|
||||
assert_match('\r\n\r\n!!!', info)
|
||||
assert_match('\r\n\r\n!!!!!', info)
|
||||
assert_match('Content%-Type:%s+text/xml', info)
|
||||
assert_match('Content%-Disposition:.-name="test2"', info)
|
||||
assert_match('X%-Custom%-Header:%s*hello', info)
|
||||
|
||||
part:data('!!!', 'text/xml', nil, nil)
|
||||
part:data('!!!!!!!', 'text/xml', nil, nil)
|
||||
info = assert_string(dump_mime(mime))
|
||||
assert_match('\r\n\r\n!!!', info)
|
||||
assert_match('\r\n\r\n!!!!!', info)
|
||||
assert_match('Content%-Type:%s+text/xml', info)
|
||||
assert_match('Content%-Disposition:.-name="test2"', info)
|
||||
assert_match('X%-Custom%-Header:%s*hello', info)
|
||||
|
Loading…
x
Reference in New Issue
Block a user