Index: third_party/grpc/src/python/grpcio/tests/interop/server.py |
diff --git a/third_party/WebKit/LayoutTests/http/tests/websocket/close_wsh.py b/third_party/grpc/src/python/grpcio/tests/interop/server.py |
similarity index 53% |
copy from third_party/WebKit/LayoutTests/http/tests/websocket/close_wsh.py |
copy to third_party/grpc/src/python/grpcio/tests/interop/server.py |
index 1b02d66267e294ce83977dac64f075981705647c..6dd55f008c3a680f95d4bf3ac33f7918e88da21e 100644 |
--- a/third_party/WebKit/LayoutTests/http/tests/websocket/close_wsh.py |
+++ b/third_party/grpc/src/python/grpcio/tests/interop/server.py |
@@ -1,4 +1,4 @@ |
-# Copyright 2011, Google Inc. |
+# Copyright 2015, Google Inc. |
# All rights reserved. |
# |
# Redistribution and use in source and binary forms, with or without |
@@ -27,27 +27,49 @@ |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+"""The Python implementation of the GRPC interoperability test server.""" |
+import argparse |
import logging |
-_GOODBYE_MESSAGE = u'Goodbye' |
+import time |
+from grpc.beta import implementations |
-def web_socket_do_extra_handshake(request): |
- pass # Always accept. |
+from tests.interop import methods |
+from tests.interop import resources |
+from tests.interop import test_pb2 |
+_ONE_DAY_IN_SECONDS = 60 * 60 * 24 |
-def web_socket_transfer_data(request): |
+ |
+def serve(): |
+ parser = argparse.ArgumentParser() |
+ parser.add_argument( |
+ '--port', help='the port on which to serve', type=int) |
+ parser.add_argument( |
+ '--use_tls', help='require a secure connection', |
+ default=False, type=resources.parse_bool) |
+ args = parser.parse_args() |
+ |
+ server = test_pb2.beta_create_TestService_server(methods.TestService()) |
+ if args.use_tls: |
+ private_key = resources.private_key() |
+ certificate_chain = resources.certificate_chain() |
+ credentials = implementations.ssl_server_credentials( |
+ [(private_key, certificate_chain)]) |
+ server.add_secure_port('[::]:{}'.format(args.port), credentials) |
+ else: |
+ server.add_insecure_port('[::]:{}'.format(args.port)) |
+ |
+ server.start() |
+ logging.info('Server serving.') |
+ try: |
while True: |
- line = request.ws_stream.receive_message() |
- if line is None: |
- return |
- if isinstance(line, unicode): |
- request.ws_stream.send_message(line, binary=False) |
- if line == _GOODBYE_MESSAGE: |
- return |
- else: |
- request.ws_stream.send_message(line, binary=True) |
- |
- |
-def web_socket_passive_closing_handshake(request): |
- return request.ws_close_code, request.ws_close_reason |
+ time.sleep(_ONE_DAY_IN_SECONDS) |
+ except BaseException as e: |
+ logging.info('Caught exception "%s"; stopping server...', e) |
+ server.stop(0) |
+ logging.info('Server stopped; exiting.') |
+ |
+if __name__ == '__main__': |
+ serve() |