Replace `httpbin.org` to local pegasus server

master
Alexey Melnichuk 2017-10-19 14:39:07 +03:00
parent b723615c05
commit 4f75627e5c
10 changed files with 187 additions and 23 deletions

View File

@ -39,15 +39,26 @@ before_install:
- pip install --user hererocks
- hererocks here -r^ --$LUA
- source here/bin/activate
- luarocks show lluv > /dev/null 2>&1 || bash .travis/setup_uv.sh
install:
- luarocks make rockspecs/lua-curl-scm-0.rockspec CFLAGS="$LCURL_CC_FLAGS" LIBFLAG="$LCURL_LD_FLAGS"
before_script:
- luarocks show luacov-coveralls > /dev/null 2>&1 || luarocks install luacov-coveralls
- luarocks show lunitx > /dev/null 2>&1 || luarocks install lunitx
- luarocks show luafilesystem > /dev/null 2>&1 || luarocks install luafilesystem
- luarocks show dkjson > /dev/null 2>&1 || luarocks install dkjson --deps-mode=none
- luarocks show lunitx > /dev/null 2>&1 || luarocks install lunitx
- luarocks show luafilesystem > /dev/null 2>&1 || luarocks install luafilesystem
- luarocks show dkjson > /dev/null 2>&1 || luarocks install dkjson --deps-mode=none
- luarocks show pegasus > /dev/null 2>&1 || luarocks install pegasus http.parser
--server=http://luarocks.org/manifests/moteus
- luarocks show pegasus-router > /dev/null 2>&1 || luarocks install pegasus-router
--server=http://luarocks.org/dev
- luarocks show lluv > /dev/null 2>&1 || luarocks install lluv UV_DIR=$TRAVIS_BUILD_DIR/libuv
--server=http://luarocks.org/dev
- luarocks show lluv-pegasus > /dev/null 2>&1 || luarocks install lluv-pegasus
--server=http://luarocks.org/dev --deps-mode=none
- lua test/server.lua &
- curl -s http://127.0.0.1:7090/get
script:
- cd test

15
.travis/platform.sh Normal file
View File

@ -0,0 +1,15 @@
if [ -z "${PLATFORM:-}" ]; then
PLATFORM=$TRAVIS_OS_NAME;
fi
if [ "$PLATFORM" == "osx" ]; then
PLATFORM="macosx";
fi
if [ -z "$PLATFORM" ]; then
if [ "$(uname)" == "Linux" ]; then
PLATFORM="linux";
else
PLATFORM="macosx";
fi;
fi

23
.travis/setup_uv.sh Normal file
View File

@ -0,0 +1,23 @@
#! /bin/bash
source .travis/platform.sh
cd $TRAVIS_BUILD_DIR
git clone https://github.com/libuv/libuv.git -b v1.x
cd libuv
mkdir -p lib
mkdir -p build
git clone https://chromium.googlesource.com/external/gyp build/gyp
if [ "$PLATFORM" == "macosx" ]; then
./gyp_uv.py -f xcode && xcodebuild -ARCHS="x86_64" -project uv.xcodeproj -configuration Release -target All
cp ./build/Release/libuv.a ./lib;
else
./gyp_uv.py -f make && BUILDTYPE=Release CFLAGS=-fPIC make -C out
cp ./out/Release/libuv.a ./lib;
fi
cd $TRAVIS_BUILD_DIR

View File

@ -58,10 +58,12 @@ before_test:
- luarocks show dkjson >nul 2>&1 || luarocks install dkjson
- luarocks show luafilesystem >nul 2>&1 || luarocks install luafilesystem
- luarocks show lua-path >nul 2>&1 || luarocks install lua-path
- luarocks show pegasus >nul 2>&1 || luarocks install pegasus http.parser \
- luarocks show pegasus >nul 2>&1 || luarocks install pegasus http.parser
--server=http://luarocks.org/manifests/moteus
- ps: $TestServer = Start-Process lua -ArgumentList test/server.lua -PassThru
- curl -s http://127.0.0.1:7090
- luarocks show pegasus-router >nul 2>&1 || luarocks install pegasus-router
--server=http://luarocks.org/dev
- 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
- curl -s http://127.0.0.1:7090/get
test_script:
- echo "Testing..."
@ -75,5 +77,10 @@ after_test:
- cd %APPVEYOR_BUILD_FOLDER%
- .appveyor\pack_artifact.bat lua-curl bin-rock
on_failure:
- 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"; }
on_finish:
- ps: Stop-Process -Id $TestServer.Id
- curl -s http://127.0.0.1:7090/get
- ps: Stop-Process -Id $TestServer.Id

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Version="9,00"
Name="lcurl"
ProjectGUID="{200D5C0C-8123-48F6-9EA0-CF0E6A6943F2}"
RootNamespace="lcurl"
@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="$(CPPLIB_DIR)\curl\7.37.1\include;$(LUA_DIR)\include"
AdditionalIncludeDirectories="$(CPPLIB_DIR)\curl\7.56.0\include;$(LUA_DIR)\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LCURL_EXPORTS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@ -63,7 +63,7 @@
Name="VCLinkerTool"
AdditionalDependencies="lua5.1.lib libcurl.lib ws2_32.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;$(CPPLIB_DIR)\curl\7.37.1\lib&quot;;&quot;$(LUA_DIR)\lib&quot;"
AdditionalLibraryDirectories="&quot;$(CPPLIB_DIR)\curl\7.56.0\lib&quot;;&quot;$(LUA_DIR)\lib&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
@ -189,6 +189,10 @@
RelativePath="..\src\lchttppost.c"
>
</File>
<File
RelativePath="..\src\lcmime.c"
>
</File>
<File
RelativePath="..\src\lcmulti.c"
>
@ -251,6 +255,10 @@
RelativePath="..\src\lcinfoeasy.h"
>
</File>
<File
RelativePath="..\src\lcmime.h"
>
</File>
<File
RelativePath="..\src\lcmulti.h"
>

View File

@ -6,10 +6,102 @@ end
local uv = prequire "lluv"
local Pegasus = require (uv and "lluv.pegasus" or "pegasus")
local Router = require "pegasus.plugins.router"
local json = require "dkjson"
-- local pp = require "pp"
local server = Pegasus:new{host = '127.0.0.1', port = 7090}
local function decode_form(form)
return string.match(form, '\r\nContent%-Disposition:%s*form%-data;%s*name="(.-)".-\r\n\r\n(.-)\r\n')
end
local function decode_params(str)
local params = {}
for k, v in string.gmatch(str, '([^=]+)=([^&]+)&?') do
params[k] = v
end
return params
end
local function rand_bytes(n)
local res = {}
for i = 1, n do
res[#res + 1] = string.char(math.random(254))
end
return table.concat(res)
end
local r = Router:new()
local server = Pegasus:new{
plugins = { r };
host = '127.0.0.1', port = 7090, timout = 10
}
r:get('/get', function(request, response)
local headers = request:headers()
local params = request:params()
local path = request:path()
local ip = request.ip
local result = json.encode({
args = params;
headers = headers;
origin = ip;
url = 'http://127.0.0.1' .. path;
}, {indent = true})
response:statusCode(200)
response:contentType('application/json')
response:write(result)
end)
r:get('/bytes/:size', function(request, response, params)
local headers = request:headers()
local size = tonumber(params.size) or 1024
local result = rand_bytes(size)
response:statusCode(200)
response:contentType('application/octet-stream')
response:write(result)
end)
r:post('/post', function(request, response, params)
local headers = request:headers()
local params = request: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 name, data, form = decode_form(body)
if name then
form = {[name] = data}
else
form = decode_params(body)
end
local result = json.encode({
args = params;
headers = headers;
origin = ip;
form = form;
url = 'http://127.0.0.1' .. path;
}, {indent = true})
response:statusCode(200)
response:contentType('application/json')
response:write(result)
end)
server:start(function(request, response)
local headers = request:headers()
response:statusCode(200)
response:addHeader('Content-Type', 'text/plain')
response:write('Hello from Pegasus')

View File

@ -24,6 +24,8 @@ local utils = require "utils"
-- not sure is it bug or not
local text_plain = utils.is_curl_eq(7,56,0) and 'test/plain' or 'text/plain'
local GET_URL = "http://127.0.0.1:7090/get"
local ENABLE = true
local _ENV = TEST_CASE'version' if ENABLE then
@ -35,7 +37,7 @@ end
end
local _ENV = TEST_CASE'easy' if ENABLE then
local _ENV = TEST_CASE'easy' if ENABLE then
local e1, e2
function teardown()
@ -124,7 +126,7 @@ end
local _ENV = TEST_CASE'multi_iterator' if ENABLE then
local url = "http://httpbin.org/get"
local url = GET_URL
local c, t, m
@ -144,8 +146,7 @@ function teardown()
end
function test_add_handle()
local base_url = 'http://httpbin.org/get?key='
local base_url = url .. '?key='
local urls = {
base_url .. "1",
base_url .. "2",
@ -196,7 +197,9 @@ function test_add_handle()
end
function test_info_read()
local url = 'http://httpbin.org/get?key=1'
local url = GET_URL .. '?key=1'
c = assert(curl.easy{url=url, writefunction=function() end})
assert_equal(m, m:add_handle(c))

View File

@ -30,6 +30,10 @@ local fname = "./test.download"
local weak_ptr, gc_collect, is_curl_ge, read_file, stream, Stream =
utils.import('weak_ptr', 'gc_collect', 'is_curl_ge', 'read_file', 'stream', 'Stream')
-- local POST_URL = "http://httpbin.org/post"
local POST_URL = "http://127.0.0.1:7090/post"
local ENABLE = true
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
-- tested on WinXP(x32)/Win8(x64) libcurl/7.37.1 / libcurl/7.30.0
local url = "http://httpbin.org/post"
local url = POST_URL
local m, c, f, t
@ -865,10 +869,10 @@ end
function test()
do local fields = {}
for i = 1, 100 do fields[#fields + 1] = "key" .. i .. "=value"..i end
for i = 1, 100 do fields[#fields + 1] = string.format('key%d=value%d', i, i) end
fields = table.concat(fields, '&')
c = assert(curl.easy{
url = "http://httpbin.org/post",
url = POST_URL,
postfields = fields,
writefunction = function()end,
})
@ -884,10 +888,10 @@ function test_unset()
local pfields
do local fields = {}
for i = 1, 100 do fields[#fields + 1] = "key" .. i .. "=value"..i end
for i = 1, 100 do fields[#fields + 1] = string.format('key%d=value%d', i, i) end
fields = table.concat(fields, '&')
c = assert(curl.easy{
url = "http://httpbin.org/post",
url = POST_URL,
postfields = fields,
writefunction = function()end,
})

View File

@ -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'
local dump_mime_url = 'http://127.0.0.1:7090/post'
local function is_freed(c)
return not not string.find(tostring(c), '%(freed%)')

View File

@ -6,7 +6,8 @@ local curl = require "lcurl"
local WAIT_COUNT = 15
local SIZE = 10 * 1024
local RESOURCE_URL = "http://httpbin.org/bytes/" .. SIZE
-- local RESOURCE_URL = "http://httpbin.org/bytes/" .. SIZE
local RESOURCE_URL = "http://127.0.0.1:7090/bytes/" .. SIZE
local State = {
PAUSE = 0, -- write function should return CURL_WRITEFUNC_PAUSE