mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-04-29 03:12:13 +00:00
proxy_pass 디렉티브 테스트
This commit is contained in:
parent
8c24411c3f
commit
c8ab8ad107
@ -34,4 +34,4 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"expensive": 10
|
"expensive": 10
|
||||||
}
|
}
|
||||||
|
@ -3,30 +3,112 @@ lua_package_path '/etc/jsonpath/?.lua;;';
|
|||||||
access_log /var/log/nginx_access.log;
|
access_log /var/log/nginx_access.log;
|
||||||
error_log /var/log/nginx_error.log info;
|
error_log /var/log/nginx_error.log info;
|
||||||
|
|
||||||
|
init_by_lua_block {
|
||||||
|
jp = require("jsonpath")
|
||||||
|
jp.init("/etc/jsonpath/libjsonpath_lib.so")
|
||||||
|
|
||||||
|
BOOK = "$..book"
|
||||||
|
jp.compile(BOOK)
|
||||||
|
|
||||||
|
COMMENT_COUNT = "$..commit[?(@.author.name == 'Thibault Charbonnier')]"
|
||||||
|
jp.compile(COMMENT_COUNT)
|
||||||
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name localhost;
|
server_name localhost;
|
||||||
|
|
||||||
location /0 {
|
gzip on;
|
||||||
default_type text/html;
|
gzip_types text/plain application/json;
|
||||||
|
#gzip_comp_level 6;
|
||||||
|
#gzip_vary on;
|
||||||
|
|
||||||
content_by_lua '
|
location ~ \.json {
|
||||||
local jsonpath = require("jsonpath")
|
add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
|
||||||
jsonpath.init("/etc/jsonpath/libjsonpath_lib.so")
|
expires off;
|
||||||
local data = ngx.location.capture("/example.json")
|
|
||||||
local template = jsonpath.compile("$..book[?(@.price<30 && @.category==\'fiction\')]")
|
default_type 'text/plain';
|
||||||
local result = template(data.body)
|
root /etc/jsonpath/example;
|
||||||
ngx.say(result)
|
|
||||||
';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
location /1 {
|
location /1 {
|
||||||
default_type text/html;
|
default_type text/plain;
|
||||||
|
content_by_lua_file /etc/jsonpath/testa.lua;
|
||||||
|
}
|
||||||
|
|
||||||
content_by_lua_file /etc/jsonpath/testa.lua;
|
location /2 {
|
||||||
|
# https://developer.mozilla.org/ko/docs/Web/HTTP/Headers/Accept-Encoding
|
||||||
|
proxy_set_header Accept-Encoding "*";
|
||||||
|
|
||||||
|
default_type 'text/plain';
|
||||||
|
|
||||||
|
proxy_pass 'http://localhost/example.json';
|
||||||
|
|
||||||
|
header_filter_by_lua_block {
|
||||||
|
ngx.header.content_length = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
location /example {
|
body_filter_by_lua_block {
|
||||||
root /etc/jsonpath/example;
|
local chunk, eof = ngx.arg[1], ngx.arg[2]
|
||||||
|
local buf = ngx.ctx.buf
|
||||||
|
|
||||||
|
if eof then
|
||||||
|
if buf then
|
||||||
|
local json = buf .. chunk
|
||||||
|
local template = jp.compile(BOOK)
|
||||||
|
local result = template(json)
|
||||||
|
ngx.arg[1] = result
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if buf then
|
||||||
|
ngx.ctx.buf = buf .. chunk
|
||||||
|
else
|
||||||
|
ngx.ctx.buf = chunk
|
||||||
|
end
|
||||||
|
|
||||||
|
ngx.arg[1] = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
location /3 {
|
||||||
|
# https://developer.mozilla.org/ko/docs/Web/HTTP/Headers/Accept-Encoding
|
||||||
|
proxy_set_header Accept-Encoding "*";
|
||||||
|
|
||||||
|
default_type 'text/plain';
|
||||||
|
|
||||||
|
proxy_pass 'https://api.github.com/repos/openresty/lua-nginx-module/commits';
|
||||||
|
|
||||||
|
header_filter_by_lua_block {
|
||||||
|
ngx.header.content_length = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
body_filter_by_lua_block {
|
||||||
|
local chunk, eof = ngx.arg[1], ngx.arg[2]
|
||||||
|
local buf = ngx.ctx.buf
|
||||||
|
|
||||||
|
if eof then
|
||||||
|
if buf then
|
||||||
|
local json = buf .. chunk
|
||||||
|
local template = jp.compile(COMMENT_COUNT)
|
||||||
|
local result = template(json)
|
||||||
|
ngx.arg[1] = result
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if buf then
|
||||||
|
ngx.ctx.buf = buf .. chunk
|
||||||
|
else
|
||||||
|
ngx.ctx.buf = chunk
|
||||||
|
end
|
||||||
|
|
||||||
|
ngx.arg[1] = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +1,10 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# cd lua/docker_example && ./run.sh
|
# cd lua && cargo build --release && cd docker_example && ./run.sh
|
||||||
|
|
||||||
set -v
|
set -v
|
||||||
|
|
||||||
docker kill jsonpath
|
[ "$(docker ps -a | grep jsonpath)" ] && docker kill jsonpath
|
||||||
|
|
||||||
docker run -d --rm --name jsonpath \
|
docker run -d --rm --name jsonpath \
|
||||||
-v "${PWD}/../../benchmark/example.json":/etc/jsonpath/example/example.json:ro \
|
-v "${PWD}/../../benchmark/example.json":/etc/jsonpath/example/example.json:ro \
|
||||||
@ -16,35 +16,5 @@ docker run -d --rm --name jsonpath \
|
|||||||
-p 8080:80 \
|
-p 8080:80 \
|
||||||
openresty/openresty:bionic
|
openresty/openresty:bionic
|
||||||
|
|
||||||
paths=(
|
sleep 1
|
||||||
"$.store.book[*].author"
|
curl http://localhost:8080/3
|
||||||
"$..author"
|
|
||||||
"$.store.*"
|
|
||||||
"$.store..price"
|
|
||||||
"$..book[2]"
|
|
||||||
"$..book[-2]"
|
|
||||||
"$..book[0,1]"
|
|
||||||
"$..book[:2]"
|
|
||||||
"$..book[1:2]"
|
|
||||||
"$..book[-2:]"
|
|
||||||
"$..book[2:]"
|
|
||||||
"$..book[?(@.isbn)]"
|
|
||||||
"$.store.book[?(@.price == 10)]"
|
|
||||||
"$..*"
|
|
||||||
"$..book[ ?( (@.price < 13 || $.store.bicycle.price < @.price) && @.price <=10 ) ]"
|
|
||||||
"$.store.book[?( (@.price < 10 || @.price > 10) && @.price > 10 )]"
|
|
||||||
)
|
|
||||||
|
|
||||||
encoded_paths=()
|
|
||||||
|
|
||||||
for i in "${!paths[@]}"
|
|
||||||
do
|
|
||||||
encoded_paths+=("$(node --eval "console.log(encodeURIComponent('${paths[$i]}'))")")
|
|
||||||
curl http://localhost:8080/1?path="${encoded_paths[$i]}"
|
|
||||||
done
|
|
||||||
|
|
||||||
for i in "${!encoded_paths[@]}"
|
|
||||||
do
|
|
||||||
ab -n 1000 -c 10 http://localhost:8080/1?path="${encoded_paths[$i]}" > ab_results/"${paths[$i]}".txt
|
|
||||||
done
|
|
||||||
|
|
||||||
|
@ -23,7 +23,9 @@ if existsVaiable('ngx') then
|
|||||||
_ngx = ngx
|
_ngx = ngx
|
||||||
else
|
else
|
||||||
_ngx = {}
|
_ngx = {}
|
||||||
_ngx.log = function() end
|
_ngx.log = function(level, msg)
|
||||||
|
print('['..level..'] ' .. msg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function module.compile(path)
|
function module.compile(path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user