Last active
August 29, 2015 14:01
-
-
Save tkuchiki/8445565e2571aadd8b39 to your computer and use it in GitHub Desktop.
webサーバから proxy した http request ヘッダを出力する SimpleHTTPServer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./httpserver.py | |
$ ./httpserver.py PORT | |
$ ./httpserver.py IPADDR | |
$ ./httpserver.py IPADDR:PORT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
import SimpleHTTPServer, SocketServer, cgi, sys, socket | |
port = 8080 | |
host = "" | |
if len(sys.argv) > 1: | |
arg = sys.argv[1] | |
if ':' in arg: | |
host, port = arg.split(':') | |
port = int(port) | |
else: | |
try: | |
port = int(sys.argv[1]) | |
except: | |
host = sys.argv[1] | |
class HTTPDHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): | |
def do_GET(self): | |
self.send_response(200); self.send_header("Content-type", "text/html"); self.end_headers() | |
print "\n########## HEADER ##########\n", self.headers | |
def do_POST(self): | |
self.send_response(200); self.send_header("Content-type", "text/html"); self.end_headers() | |
print "\n########## HEADER ##########\n", self.headers | |
form = cgi.FieldStorage(fp = self.rfile, headers=self.headers, | |
environ = {'REQUEST_METHOD':'POST', 'CONTENT_TYPE':self.headers['Content-Type'],}) | |
print "########## FORM ##########" | |
for item in form.keys(): print "%s = %s" % (item, form[item].value) | |
print "" | |
SocketServer.TCPServer.allow_reuse_address = True | |
httpd = SocketServer.TCPServer((host, port), HTTPDHandler) | |
sn = httpd.socket.getsockname() | |
print "Serving HTTP on", sn[0], "port", sn[1], "..." | |
try: | |
httpd.serve_forever() | |
except KeyboardInterrupt: | |
pass | |
httpd.server_close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user nginx; | |
worker_processes 1; | |
error_log /var/log/nginx/error.log warn; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log /var/log/nginx/access.log main; | |
variables_hash_max_size 1024; | |
server { | |
listen 80; | |
server_name _; | |
location / { | |
proxy_set_header Host 'test-server'; | |
proxy_set_header Test 'foobar'; | |
proxy_pass http://127.0.0.1:8080; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment