-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseHTTPServer_GET.py
More file actions
38 lines (35 loc) · 1.33 KB
/
BaseHTTPServer_GET.py
File metadata and controls
38 lines (35 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /usr/bin/env python
#coding=utf-8
from BaseHTTPServer import BaseHTTPRequestHandler
import urlparse
class GetHandler(BaseHTTPRequestHandler):
def do_GET(self):
parsed_path = urlparse.urlparse(self.path)
message_parts = [
'CLIENT VALUES:',
'client_address = %s (%s)' % (self.client_address,self.address_string),
'command=%s' % self.command,
'path=%s' % self.path,
'real path=%s' % parsed_path.path,
'query=%s'%parsed_path.query,
'request_version=%s' % self.request_version,
'',
'SERVER VALUES:',
'server_version=%s' % self.sys_version,
'protocol_version=%s' % self.protocol_version,
'',
'HEADERS RECERVED',
]
for name,value in sorted(self.headers.items()):
message_parts.append('%s=%s' % (name,value.rstrip()))
message_parts.append('')
message = '\r\n'.join(message_parts)
self.send_response(200)
self.end_headers()
self.wfile.write(message)
return
if __name__=='__main__':
from BaseHTTPServer import HTTPServer
server = HTTPServer(('localhost',8080),GetHandler)
print 'Starting server, use <Ctrl-C> to stop'
server.serve_forever()