Skip to content

Commit c8a0f7e

Browse files
committed
Update test server.
1 parent 4f75627 commit c8a0f7e

4 files changed

Lines changed: 34 additions & 13 deletions

File tree

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ after_test:
7878
- .appveyor\pack_artifact.bat lua-curl bin-rock
7979

8080
on_failure:
81+
- ps: Stop-Process -Id $TestServer.Id
8182
- 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"; }
8283
- 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"; }
8384

lakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ target('test', install, function()
3232
run_test('test_form.lua')
3333
run_test('test_pause02.c.lua')
3434
run_test('test_curl.lua')
35+
run_test('test_mime.lua')
3536
run_test('test_multi_callback.lua')
3637
run_test('test_multi_nested_callback.lua')
3738

test/server.lua

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local function prequire(m)
44
return err
55
end
66

7-
local uv = prequire "lluv"
7+
local uv = prequire "lluv-"
88
local Pegasus = require (uv and "lluv.pegasus" or "pegasus")
99
local Router = require "pegasus.plugins.router"
1010
local json = require "dkjson"
@@ -37,20 +37,44 @@ local server = Pegasus:new{
3737
host = '127.0.0.1', port = 7090, timout = 10
3838
}
3939

40+
local function recvFullBody(request, T1)
41+
local body, counter = {}, 0
42+
43+
local result, status
44+
while true do
45+
result, status = request:receiveBody()
46+
if result then
47+
counter = 0
48+
body[#body + 1] = result
49+
elseif status ~= 'timeout' then
50+
break
51+
else
52+
counter = counter + 1
53+
if counter > T1 then break end
54+
end
55+
end
56+
57+
return table.concat(body), status
58+
end
59+
4060
r:get('/get', function(request, response)
4161
local headers = request:headers()
4262
local params = request:params()
4363
local path = request:path()
4464
local ip = request.ip
4565

66+
local body, status = recvFullBody(request, 15)
67+
4668
local result = json.encode({
4769
args = params;
4870
headers = headers;
4971
origin = ip;
72+
content = body;
5073
url = 'http://127.0.0.1' .. path;
5174
}, {indent = true})
5275

5376
response:statusCode(200)
77+
response:addHeader('Connection', 'close')
5478
response:contentType('application/json')
5579
response:write(result)
5680
end)
@@ -71,13 +95,7 @@ r:post('/post', function(request, response, params)
7195
local path = request:path()
7296
local ip = request.ip
7397

74-
local body = {}
75-
while true do
76-
local result, status = request:receiveBody()
77-
if result then body[#body + 1] = result
78-
elseif status ~= 'timeout' then break end
79-
end
80-
body = table.concat(body)
98+
local body, status = recvFullBody(request, 15)
8199

82100
local name, data, form = decode_form(body)
83101
if name then
@@ -95,6 +113,7 @@ r:post('/post', function(request, response, params)
95113
}, {indent = true})
96114

97115
response:statusCode(200)
116+
response:addHeader('Connection', 'close')
98117
response:contentType('application/json')
99118
response:write(result)
100119
end)

test/test_mime.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ local utils = require "utils"
1717

1818
local weak_ptr, gc_collect, dump_mime_ = utils.import('weak_ptr', 'gc_collect', 'dump_mime')
1919

20-
local dump_mime_url = 'http://127.0.0.1:7090/post'
20+
local dump_mime_url = 'http://127.0.0.1:7090/get'
2121

2222
local function is_freed(c)
2323
return not not string.find(tostring(c), '%(freed%)')
@@ -246,16 +246,16 @@ function test_data_should_not_unset_on_nil()
246246
assert_match('Content%-Disposition:.-name="test2"', info)
247247
assert_match('X%-Custom%-Header:%s*hello', info)
248248

249-
part:data('!!!', 'text/xml', nil)
249+
part:data('!!!!!', 'text/xml', nil)
250250
info = assert_string(dump_mime(mime))
251-
assert_match('\r\n\r\n!!!', info)
251+
assert_match('\r\n\r\n!!!!!', info)
252252
assert_match('Content%-Type:%s+text/xml', info)
253253
assert_match('Content%-Disposition:.-name="test2"', info)
254254
assert_match('X%-Custom%-Header:%s*hello', info)
255255

256-
part:data('!!!', 'text/xml', nil, nil)
256+
part:data('!!!!!!!', 'text/xml', nil, nil)
257257
info = assert_string(dump_mime(mime))
258-
assert_match('\r\n\r\n!!!', info)
258+
assert_match('\r\n\r\n!!!!!', info)
259259
assert_match('Content%-Type:%s+text/xml', info)
260260
assert_match('Content%-Disposition:.-name="test2"', info)
261261
assert_match('X%-Custom%-Header:%s*hello', info)

0 commit comments

Comments
 (0)