1 #################################
2 # swMap Test
3 # scott
4 # 2010.11.19
5 # wallizard.vicp.net sw2us.com
6 #################################
7 #simplest http server
8 # expose image
9 #
10
11 import BaseHTTPServer,SocketServer,SimpleHTTPServer
12 import time,sys,os,os.path
13
14
15 class MyThreadServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): pass
16
17 '''
18 HTTP/1.1 200 OK
19 Cache-Control: private, max-age=30
20 Content-Type: text/html; charset=utf-8
21 Content-Encoding: gzip
22 Expires: Mon, 25 May 2009 03:20:33 GMT
23 Last-Modified: Mon, 25 May 2009 03:20:03 GMT
24 Vary: Accept-Encoding
25 Server: Microsoft-IIS/7.0
26 X-AspNet-Version: 2.0.50727
27 X-Powered-By: ASP.NET
28 Date: Mon, 25 May 2009 03:20:02 GMT
29 Content-Length: 12173
30 '''
31 '''
32 Pragma:no-cache
33 Cache-Control:no-cache
34 '''
35
36 class MyHander(SimpleHTTPServer.SimpleHTTPRequestHandler):
37 def __init__(self,request, client_address, server):
38 SimpleHTTPServer.SimpleHTTPRequestHandler.__init__(self,request, client_address, server)
39
40 def do_GET(self):
41 print self.headers
42
43 f= open('d:/nono.gif','rb')
44 image = f.read()
45 f.close()
46
47 self.send_response(200)
48 self.send_header( 'Server','swMapServer')
49 now = self.date_time_string(time.time())
50 self.send_header('Date',now)
51 self.send_header('Content-Type','image/gif')
52 self.send_header('Content-Length',len(image))
53 self.end_headers()
54
55 self.wfile.write(image)
56
57 def run(server_class=MyThreadServer,handler_class=MyHander):
58 server_address = ('', 8000)
59 httpd = server_class(server_address, handler_class)
60 print 'serve on ',server_address
61 httpd.serve_forever()
62
63
64 run()