Skip to content

Commit 4f75627

Browse files
committed
Replace httpbin.org to local pegasus server
1 parent b723615 commit 4f75627

10 files changed

Lines changed: 187 additions & 23 deletions

File tree

.travis.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,26 @@ before_install:
3939
- pip install --user hererocks
4040
- hererocks here -r^ --$LUA
4141
- source here/bin/activate
42+
- luarocks show lluv > /dev/null 2>&1 || bash .travis/setup_uv.sh
4243

4344
install:
4445
- luarocks make rockspecs/lua-curl-scm-0.rockspec CFLAGS="$LCURL_CC_FLAGS" LIBFLAG="$LCURL_LD_FLAGS"
4546

4647
before_script:
4748
- luarocks show luacov-coveralls > /dev/null 2>&1 || luarocks install luacov-coveralls
48-
- luarocks show lunitx > /dev/null 2>&1 || luarocks install lunitx
49-
- luarocks show luafilesystem > /dev/null 2>&1 || luarocks install luafilesystem
50-
- luarocks show dkjson > /dev/null 2>&1 || luarocks install dkjson --deps-mode=none
49+
- luarocks show lunitx > /dev/null 2>&1 || luarocks install lunitx
50+
- luarocks show luafilesystem > /dev/null 2>&1 || luarocks install luafilesystem
51+
- luarocks show dkjson > /dev/null 2>&1 || luarocks install dkjson --deps-mode=none
52+
- luarocks show pegasus > /dev/null 2>&1 || luarocks install pegasus http.parser
53+
--server=http://luarocks.org/manifests/moteus
54+
- luarocks show pegasus-router > /dev/null 2>&1 || luarocks install pegasus-router
55+
--server=http://luarocks.org/dev
56+
- luarocks show lluv > /dev/null 2>&1 || luarocks install lluv UV_DIR=$TRAVIS_BUILD_DIR/libuv
57+
--server=http://luarocks.org/dev
58+
- luarocks show lluv-pegasus > /dev/null 2>&1 || luarocks install lluv-pegasus
59+
--server=http://luarocks.org/dev --deps-mode=none
60+
- lua test/server.lua &
61+
- curl -s http://127.0.0.1:7090/get
5162

5263
script:
5364
- cd test

.travis/platform.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
if [ -z "${PLATFORM:-}" ]; then
2+
PLATFORM=$TRAVIS_OS_NAME;
3+
fi
4+
5+
if [ "$PLATFORM" == "osx" ]; then
6+
PLATFORM="macosx";
7+
fi
8+
9+
if [ -z "$PLATFORM" ]; then
10+
if [ "$(uname)" == "Linux" ]; then
11+
PLATFORM="linux";
12+
else
13+
PLATFORM="macosx";
14+
fi;
15+
fi

.travis/setup_uv.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /bin/bash
2+
3+
source .travis/platform.sh
4+
5+
cd $TRAVIS_BUILD_DIR
6+
7+
git clone https://github.com/libuv/libuv.git -b v1.x
8+
9+
cd libuv
10+
11+
mkdir -p lib
12+
mkdir -p build
13+
git clone https://chromium.googlesource.com/external/gyp build/gyp
14+
15+
if [ "$PLATFORM" == "macosx" ]; then
16+
./gyp_uv.py -f xcode && xcodebuild -ARCHS="x86_64" -project uv.xcodeproj -configuration Release -target All
17+
cp ./build/Release/libuv.a ./lib;
18+
else
19+
./gyp_uv.py -f make && BUILDTYPE=Release CFLAGS=-fPIC make -C out
20+
cp ./out/Release/libuv.a ./lib;
21+
fi
22+
23+
cd $TRAVIS_BUILD_DIR

appveyor.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ before_test:
5858
- luarocks show dkjson >nul 2>&1 || luarocks install dkjson
5959
- luarocks show luafilesystem >nul 2>&1 || luarocks install luafilesystem
6060
- luarocks show lua-path >nul 2>&1 || luarocks install lua-path
61-
- luarocks show pegasus >nul 2>&1 || luarocks install pegasus http.parser \
61+
- luarocks show pegasus >nul 2>&1 || luarocks install pegasus http.parser
6262
--server=http://luarocks.org/manifests/moteus
63-
- ps: $TestServer = Start-Process lua -ArgumentList test/server.lua -PassThru
64-
- curl -s http://127.0.0.1:7090
63+
- luarocks show pegasus-router >nul 2>&1 || luarocks install pegasus-router
64+
--server=http://luarocks.org/dev
65+
- ps: $TestServer = Start-Process lua -ArgumentList test/server.lua -RedirectStandardOutput "$env:APPVEYOR_BUILD_FOLDER\server.stdout.txt" -RedirectStandardError "$env:APPVEYOR_BUILD_FOLDER\server.stderr.txt" -PassThru
66+
- curl -s http://127.0.0.1:7090/get
6567

6668
test_script:
6769
- echo "Testing..."
@@ -75,5 +77,10 @@ after_test:
7577
- cd %APPVEYOR_BUILD_FOLDER%
7678
- .appveyor\pack_artifact.bat lua-curl bin-rock
7779

80+
on_failure:
81+
- 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"; }
82+
- 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"; }
83+
7884
on_finish:
79-
- ps: Stop-Process -Id $TestServer.Id
85+
- curl -s http://127.0.0.1:7090/get
86+
- ps: Stop-Process -Id $TestServer.Id

msvc/lcurl.vcproj

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="windows-1251"?>
22
<VisualStudioProject
33
ProjectType="Visual C++"
4-
Version="9.00"
4+
Version="9,00"
55
Name="lcurl"
66
ProjectGUID="{200D5C0C-8123-48F6-9EA0-CF0E6A6943F2}"
77
RootNamespace="lcurl"
@@ -41,7 +41,7 @@
4141
<Tool
4242
Name="VCCLCompilerTool"
4343
Optimization="0"
44-
AdditionalIncludeDirectories="$(CPPLIB_DIR)\curl\7.37.1\include;$(LUA_DIR)\include"
44+
AdditionalIncludeDirectories="$(CPPLIB_DIR)\curl\7.56.0\include;$(LUA_DIR)\include"
4545
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LCURL_EXPORTS"
4646
MinimalRebuild="true"
4747
BasicRuntimeChecks="3"
@@ -63,7 +63,7 @@
6363
Name="VCLinkerTool"
6464
AdditionalDependencies="lua5.1.lib libcurl.lib ws2_32.lib"
6565
LinkIncremental="2"
66-
AdditionalLibraryDirectories="&quot;$(CPPLIB_DIR)\curl\7.37.1\lib&quot;;&quot;$(LUA_DIR)\lib&quot;"
66+
AdditionalLibraryDirectories="&quot;$(CPPLIB_DIR)\curl\7.56.0\lib&quot;;&quot;$(LUA_DIR)\lib&quot;"
6767
GenerateDebugInformation="true"
6868
SubSystem="2"
6969
TargetMachine="1"
@@ -189,6 +189,10 @@
189189
RelativePath="..\src\lchttppost.c"
190190
>
191191
</File>
192+
<File
193+
RelativePath="..\src\lcmime.c"
194+
>
195+
</File>
192196
<File
193197
RelativePath="..\src\lcmulti.c"
194198
>
@@ -251,6 +255,10 @@
251255
RelativePath="..\src\lcinfoeasy.h"
252256
>
253257
</File>
258+
<File
259+
RelativePath="..\src\lcmime.h"
260+
>
261+
</File>
254262
<File
255263
RelativePath="..\src\lcmulti.h"
256264
>

test/server.lua

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,102 @@ end
66

77
local uv = prequire "lluv"
88
local Pegasus = require (uv and "lluv.pegasus" or "pegasus")
9+
local Router = require "pegasus.plugins.router"
10+
local json = require "dkjson"
11+
-- local pp = require "pp"
912

10-
local server = Pegasus:new{host = '127.0.0.1', port = 7090}
13+
local function decode_form(form)
14+
return string.match(form, '\r\nContent%-Disposition:%s*form%-data;%s*name="(.-)".-\r\n\r\n(.-)\r\n')
15+
end
16+
17+
local function decode_params(str)
18+
local params = {}
19+
for k, v in string.gmatch(str, '([^=]+)=([^&]+)&?') do
20+
params[k] = v
21+
end
22+
return params
23+
end
24+
25+
local function rand_bytes(n)
26+
local res = {}
27+
for i = 1, n do
28+
res[#res + 1] = string.char(math.random(254))
29+
end
30+
return table.concat(res)
31+
end
32+
33+
local r = Router:new()
34+
35+
local server = Pegasus:new{
36+
plugins = { r };
37+
host = '127.0.0.1', port = 7090, timout = 10
38+
}
39+
40+
r:get('/get', function(request, response)
41+
local headers = request:headers()
42+
local params = request:params()
43+
local path = request:path()
44+
local ip = request.ip
45+
46+
local result = json.encode({
47+
args = params;
48+
headers = headers;
49+
origin = ip;
50+
url = 'http://127.0.0.1' .. path;
51+
}, {indent = true})
52+
53+
response:statusCode(200)
54+
response:contentType('application/json')
55+
response:write(result)
56+
end)
57+
58+
r:get('/bytes/:size', function(request, response, params)
59+
local headers = request:headers()
60+
local size = tonumber(params.size) or 1024
61+
local result = rand_bytes(size)
62+
63+
response:statusCode(200)
64+
response:contentType('application/octet-stream')
65+
response:write(result)
66+
end)
67+
68+
r:post('/post', function(request, response, params)
69+
local headers = request:headers()
70+
local params = request:params()
71+
local path = request:path()
72+
local ip = request.ip
73+
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)
81+
82+
local name, data, form = decode_form(body)
83+
if name then
84+
form = {[name] = data}
85+
else
86+
form = decode_params(body)
87+
end
88+
89+
local result = json.encode({
90+
args = params;
91+
headers = headers;
92+
origin = ip;
93+
form = form;
94+
url = 'http://127.0.0.1' .. path;
95+
}, {indent = true})
96+
97+
response:statusCode(200)
98+
response:contentType('application/json')
99+
response:write(result)
100+
end)
11101

12102
server:start(function(request, response)
103+
local headers = request:headers()
104+
13105
response:statusCode(200)
14106
response:addHeader('Content-Type', 'text/plain')
15107
response:write('Hello from Pegasus')

test/test_curl.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ local utils = require "utils"
2424
-- not sure is it bug or not
2525
local text_plain = utils.is_curl_eq(7,56,0) and 'test/plain' or 'text/plain'
2626

27+
local GET_URL = "http://127.0.0.1:7090/get"
28+
2729
local ENABLE = true
2830

2931
local _ENV = TEST_CASE'version' if ENABLE then
@@ -35,7 +37,7 @@ end
3537

3638
end
3739

38-
local _ENV = TEST_CASE'easy' if ENABLE then
40+
local _ENV = TEST_CASE'easy' if ENABLE then
3941

4042
local e1, e2
4143
function teardown()
@@ -124,7 +126,7 @@ end
124126

125127
local _ENV = TEST_CASE'multi_iterator' if ENABLE then
126128

127-
local url = "http://httpbin.org/get"
129+
local url = GET_URL
128130

129131
local c, t, m
130132

@@ -144,8 +146,7 @@ function teardown()
144146
end
145147

146148
function test_add_handle()
147-
148-
local base_url = 'http://httpbin.org/get?key='
149+
local base_url = url .. '?key='
149150
local urls = {
150151
base_url .. "1",
151152
base_url .. "2",
@@ -196,7 +197,9 @@ function test_add_handle()
196197
end
197198

198199
function test_info_read()
199-
local url = 'http://httpbin.org/get?key=1'
200+
201+
local url = GET_URL .. '?key=1'
202+
200203
c = assert(curl.easy{url=url, writefunction=function() end})
201204
assert_equal(m, m:add_handle(c))
202205

test/test_easy.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ local fname = "./test.download"
3030
local weak_ptr, gc_collect, is_curl_ge, read_file, stream, Stream =
3131
utils.import('weak_ptr', 'gc_collect', 'is_curl_ge', 'read_file', 'stream', 'Stream')
3232

33+
-- local POST_URL = "http://httpbin.org/post"
34+
35+
local POST_URL = "http://127.0.0.1:7090/post"
36+
3337
local ENABLE = true
3438

3539
local _ENV = TEST_CASE'curl error' if ENABLE then
@@ -416,7 +420,7 @@ local _ENV = TEST_CASE'read_stream_callback' if ENABLE and is_curl_ge(7,30,0) th
416420

417421
-- tested on WinXP(x32)/Win8(x64) libcurl/7.37.1 / libcurl/7.30.0
418422

419-
local url = "http://httpbin.org/post"
423+
local url = POST_URL
420424

421425
local m, c, f, t
422426

@@ -865,10 +869,10 @@ end
865869
function test()
866870

867871
do local fields = {}
868-
for i = 1, 100 do fields[#fields + 1] = "key" .. i .. "=value"..i end
872+
for i = 1, 100 do fields[#fields + 1] = string.format('key%d=value%d', i, i) end
869873
fields = table.concat(fields, '&')
870874
c = assert(curl.easy{
871-
url = "http://httpbin.org/post",
875+
url = POST_URL,
872876
postfields = fields,
873877
writefunction = function()end,
874878
})
@@ -884,10 +888,10 @@ function test_unset()
884888
local pfields
885889

886890
do local fields = {}
887-
for i = 1, 100 do fields[#fields + 1] = "key" .. i .. "=value"..i end
891+
for i = 1, 100 do fields[#fields + 1] = string.format('key%d=value%d', i, i) end
888892
fields = table.concat(fields, '&')
889893
c = assert(curl.easy{
890-
url = "http://httpbin.org/post",
894+
url = POST_URL,
891895
postfields = fields,
892896
writefunction = function()end,
893897
})

test/test_mime.lua

Lines changed: 1 addition & 1 deletion
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'
20+
local dump_mime_url = 'http://127.0.0.1:7090/post'
2121

2222
local function is_freed(c)
2323
return not not string.find(tostring(c), '%(freed%)')

test/test_pause02.c.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ local curl = require "lcurl"
66
local WAIT_COUNT = 15
77

88
local SIZE = 10 * 1024
9-
local RESOURCE_URL = "http://httpbin.org/bytes/" .. SIZE
9+
-- local RESOURCE_URL = "http://httpbin.org/bytes/" .. SIZE
10+
local RESOURCE_URL = "http://127.0.0.1:7090/bytes/" .. SIZE
1011

1112
local State = {
1213
PAUSE = 0, -- write function should return CURL_WRITEFUNC_PAUSE

0 commit comments

Comments
 (0)