Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: chrome/browser/prerender/tools/prerender_test_server/prerender_test_server.py

Issue 2201093003: NoStatePrefetch: Add a more dummy prerender_test_server.py (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed to tools/prerender_test_server/prerender_test_server.py Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/prerender/tools/prerender_test_server/prerender.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 # A local web server with a copy of functionality of
7 # http://prerender-test.appspot.com with a DISABLED check whether Prerendering
8 # is working.
9
10 import BaseHTTPServer
11 import argparse
12 import os
13 import sys
14
15
16 THIS_DIR = os.path.abspath(os.path.dirname(__file__))
17
18
19 def ReadFileRelative(file_name):
20 return open(os.path.join(THIS_DIR, file_name), 'r').read()
21
22
23 class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
24 def do_GET(self):
25 file_path = None
26 if self.path == '/':
27 self.path = '/index.html'
28 if self.path[0] == '/':
29 self.path = self.path[1:]
30 supported_file_to_mime = {
31 'index.html': 'text/html',
32 'default.css': 'text/css',
33 'prerender.js': 'application/javascript'
34 }
35 if self.path in supported_file_to_mime:
36 file_path = self.path
37
38 if file_path:
39 self._SendHeaders(supported_file_to_mime[file_path])
40 self.wfile.write(ReadFileRelative(file_path))
41 self.wfile.close()
42 return
43
44 self.send_error(404, 'Not found')
45
46 def _SendHeaders(self, mime_type):
47 self.send_response(200)
48 self.send_header('Content-type', mime_type)
49 self.send_header('Cache-Control', 'no-cache')
50 self.end_headers()
51
52 def main(argv):
53 parser = argparse.ArgumentParser(prog='prerender_test')
54 parser.add_argument('-p', '--port', type=int, default=8080,
55 help='port to run on (default = %(default)s)')
56 args = parser.parse_args(argv)
57
58 s = BaseHTTPServer.HTTPServer(('', args.port), Handler)
59 try:
60 print("Listening on http://localhost:%d/" % args.port)
61 s.serve_forever()
62 return 0
63 except KeyboardInterrupt:
64 s.server_close()
65 return 130
66
67
68 if __name__ == '__main__':
69 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « chrome/browser/prerender/tools/prerender_test_server/prerender.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698