OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """This is a python sync server used for testing Chrome Sync. | 6 """This is a python sync server used for testing Chrome Sync. |
7 | 7 |
8 By default, it listens on an ephemeral port and xmpp_port and sends the port | 8 By default, it listens on an ephemeral port and xmpp_port and sends the port |
9 numbers back to the originating process over a pipe. The originating process can | 9 numbers back to the originating process over a pipe. The originating process can |
10 specify an explicit port and xmpp_port if necessary. | 10 specify an explicit port and xmpp_port if necessary. |
11 """ | 11 """ |
12 | 12 |
13 import asyncore | 13 import asyncore |
14 import BaseHTTPServer | 14 import BaseHTTPServer |
15 import errno | 15 import errno |
16 import gzip | |
16 import os | 17 import os |
17 import select | 18 import select |
19 import StringIO | |
18 import socket | 20 import socket |
19 import sys | 21 import sys |
20 import urlparse | 22 import urlparse |
21 | 23 |
22 import chromiumsync | 24 import chromiumsync |
23 import echo_message | 25 import echo_message |
24 import testserver_base | 26 import testserver_base |
25 import xmppserver | 27 import xmppserver |
26 | 28 |
27 | 29 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 This covers all sync protocol commands: authentication, getupdates, and | 191 This covers all sync protocol commands: authentication, getupdates, and |
190 commit. | 192 commit. |
191 """ | 193 """ |
192 | 194 |
193 test_name = "/chromiumsync/command" | 195 test_name = "/chromiumsync/command" |
194 if not self._ShouldHandleRequest(test_name): | 196 if not self._ShouldHandleRequest(test_name): |
195 return False | 197 return False |
196 | 198 |
197 length = int(self.headers.getheader('content-length')) | 199 length = int(self.headers.getheader('content-length')) |
198 raw_request = self.rfile.read(length) | 200 raw_request = self.rfile.read(length) |
201 if self.headers.getheader('Content-Encoding'): | |
202 enocde = self.headers.getheader('Content-Encoding') | |
Nicolas Zea
2015/07/30 19:59:44
enocde -> encode
Gang Wu
2015/07/31 00:39:45
Done.
| |
203 if enocde == "gzip": | |
204 raw_request = gzip.GzipFile( | |
205 fileobj=StringIO.StringIO(raw_request)).read() | |
206 | |
199 http_response = 200 | 207 http_response = 200 |
200 raw_reply = None | 208 raw_reply = None |
201 if not self.server.GetAuthenticated(): | 209 if not self.server.GetAuthenticated(): |
202 http_response = 401 | 210 http_response = 401 |
203 challenge = 'GoogleLogin realm="http://%s", service="chromiumsync"' % ( | 211 challenge = 'GoogleLogin realm="http://%s", service="chromiumsync"' % ( |
204 self.server.server_address[0]) | 212 self.server.server_address[0]) |
205 else: | 213 else: |
206 http_response, raw_reply = self.server.HandleCommand( | 214 http_response, raw_reply = self.server.HandleCommand( |
207 self.path, raw_request) | 215 self.path, raw_request) |
208 | 216 |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 testserver_base.TestServerRunner.add_options(self) | 562 testserver_base.TestServerRunner.add_options(self) |
555 self.option_parser.add_option('--xmpp-port', default='0', type='int', | 563 self.option_parser.add_option('--xmpp-port', default='0', type='int', |
556 help='Port used by the XMPP server. If ' | 564 help='Port used by the XMPP server. If ' |
557 'unspecified, the XMPP server will listen on ' | 565 'unspecified, the XMPP server will listen on ' |
558 'an ephemeral port.') | 566 'an ephemeral port.') |
559 # Override the default logfile name used in testserver.py. | 567 # Override the default logfile name used in testserver.py. |
560 self.option_parser.set_defaults(log_file='sync_testserver.log') | 568 self.option_parser.set_defaults(log_file='sync_testserver.log') |
561 | 569 |
562 if __name__ == '__main__': | 570 if __name__ == '__main__': |
563 sys.exit(SyncServerRunner().main()) | 571 sys.exit(SyncServerRunner().main()) |
OLD | NEW |