OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 #!/usr/bin/env python2.7 |
| 2 # Copyright 2015, Google Inc. |
| 3 # All rights reserved. |
2 # | 4 # |
3 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
5 # met: | 7 # met: |
6 # | 8 # |
7 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 11 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 12 # copyright notice, this list of conditions and the following disclaimer |
11 # in the documentation and/or other materials provided with the | 13 # in the documentation and/or other materials provided with the |
12 # distribution. | 14 # distribution. |
13 # * Neither the name of Google Inc. nor the names of its | 15 # * Neither the name of Google Inc. nor the names of its |
14 # contributors may be used to endorse or promote products derived from | 16 # contributors may be used to endorse or promote products derived from |
15 # this software without specific prior written permission. | 17 # this software without specific prior written permission. |
16 # | 18 # |
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 30 |
29 import optparse | 31 """Server for httpcli_test""" |
30 | 32 |
31 from webkitpy.layout_tests.controllers import layout_test_finder | 33 import argparse |
| 34 import BaseHTTPServer |
| 35 import os |
| 36 import ssl |
| 37 import sys |
32 | 38 |
| 39 _PEM = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../../..', 's
rc/core/tsi/test_creds/server1.pem')) |
| 40 _KEY = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '../../..', 's
rc/core/tsi/test_creds/server1.key')) |
| 41 print _PEM |
| 42 open(_PEM).close() |
33 | 43 |
34 def main(host, argv): | 44 argp = argparse.ArgumentParser(description='Server for httpcli_test') |
35 port = host.port_factory.get() | 45 argp.add_argument('-p', '--port', default=10080, type=int) |
| 46 argp.add_argument('-s', '--ssl', default=False, action='store_true') |
| 47 args = argp.parse_args() |
36 | 48 |
37 parser = optparse.OptionParser() | 49 print 'server running on port %d' % args.port |
38 parser.add_option('--test-list', action='append') | |
39 parser.add_option('--type', action='append', | |
40 help='limit to tests of type X (valid values %s)' % port.A
LL_TEST_TYPES) | |
41 | 50 |
42 options, args = parser.parse_args(argv) | 51 class Handler(BaseHTTPServer.BaseHTTPRequestHandler): |
43 finder = layout_test_finder.LayoutTestFinder(port, options) | 52 » def good(self): |
44 _, tests, _ = finder.find_tests(args, test_list=options.test_list) | 53 » » self.send_response(200) |
| 54 » » self.send_header('Content-Type', 'text/html') |
| 55 » » self.end_headers() |
| 56 » » self.wfile.write('<html><head><title>Hello world!</title></head>
') |
| 57 » » self.wfile.write('<body><p>This is a test</p></body></html>') |
45 | 58 |
46 for test_name in tests: | 59 » def do_GET(self): |
47 test_type = port.test_type(test_name) | 60 » » if self.path == '/get': |
48 if options.type: | 61 » » » self.good() |
49 if test_type in options.type: | 62 |
50 host.print_(test_name) | 63 » def do_POST(self): |
51 else: | 64 » » content = self.rfile.read(int(self.headers.getheader('content-le
ngth'))) |
52 host.print_(test_name, test_type) | 65 » » if self.path == '/post' and content == 'hello': |
| 66 » » » self.good() |
| 67 |
| 68 httpd = BaseHTTPServer.HTTPServer(('localhost', args.port), Handler) |
| 69 if args.ssl: |
| 70 » httpd.socket = ssl.wrap_socket(httpd.socket, certfile=_PEM, keyfile=_KEY
, server_side=True) |
| 71 httpd.serve_forever() |
OLD | NEW |