Skip to content

Instantly share code, notes, and snippets.

@sanmai
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanmai/9585016 to your computer and use it in GitHub Desktop.
Save sanmai/9585016 to your computer and use it in GitHub Desktop.
NGiNX_HTTP_Push_Module internal redirect test case
#!/bin/bash
cd nginx-1.4.6
./configure --add-module=../nginx_http_push_module/ --with-http_perl_module
make "$@"
package internal_redirect;
use nginx;
sub handler {
my $r = shift;
$r->internal_redirect("/activity?id=1");
return OK;
}
1;
__END__
worker_processes 1;
#error_log /dev/stderr notice;
error_log /tmp/nginx-error.log notice;
pid /tmp/nginx.pid;
events {
worker_connections 8;
}
http {
access_log /dev/stdout;
perl_require internal_redirect.pm;
server {
listen 8000;
location /publish {
push_publisher;
set $push_channel_id $arg_id;
#for simplicity's sake
push_store_messages off;
}
location /activity {
push_subscriber;
push_subscriber_timeout 6s;
set $push_channel_id $arg_id;
}
location /redirect {
perl internal_redirect::handler;
}
}
}
#!/bin/bash
./nginx-1.4.6/objs/nginx -V
./nginx-1.4.6/objs/nginx -c `pwd`/nginx-internal-redirect.conf
curl -s http://localhost:8000/activity?id=1 &
sleep 1
curl -s -o /dev/null --data "Straight request: OK" http://localhost:8000/publish?id=1
sleep 1
echo
curl -s http://localhost:8000/redirect &
sleep 1
curl -s -o /dev/null --data "Redirected request: OK" http://localhost:8000/publish?id=1
sleep 1
echo
echo
echo "Expected result for a stalled request:"
curl -s -D - http://localhost:8000/activity?id=1 | grep "HTTP/1.1 304"
echo
echo "Actual result for a stalled request:"
time curl http://localhost:8000/redirect
echo
kill `cat /tmp/nginx.pid`
#cat /tmp/nginx-error.log
rm /tmp/nginx-error.log
$ ./run.sh
nginx version: nginx/1.4.6
built by gcc 4.8.2 (Debian 4.8.2-16)
configure arguments: --add-module=../nginx_http_push_module/ --with-http_perl_module
127.0.0.1 - - [17/Mar/2014:00:31:30 +0900] "GET /activity?id=1 HTTP/1.1" 200 20 "-" "curl/7.35.0"
127.0.0.1 - - [17/Mar/2014:00:31:30 +0900] "POST /publish?id=1 HTTP/1.1" 201 80 "-" "curl/7.35.0"
Straight request: OK
127.0.0.1 - - [17/Mar/2014:00:31:32 +0900] "GET /redirect HTTP/1.1" 200 22 "-" "curl/7.35.0"
127.0.0.1 - - [17/Mar/2014:00:31:32 +0900] "POST /publish?id=1 HTTP/1.1" 201 80 "-" "curl/7.35.0"
Redirected request: OK
Expected result for a stalled request:
127.0.0.1 - - [17/Mar/2014:00:31:39 +0900] "GET /activity?id=1 HTTP/1.1" 304 0 "-" "curl/7.35.0"
HTTP/1.1 304 Not Modified
Actual result for a stalled request:
127.0.0.1 - - [17/Mar/2014:00:31:44 +0900] "GET /redirect HTTP/1.1" 000 0 "-" "curl/7.35.0"
curl: (52) Empty reply from server
real 0m5.025s
user 0m0.016s
sys 0m0.004s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment