| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2008 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 simple HTTP server used for testing Chrome. | 6 """This is a simple HTTP server used for testing Chrome. |
| 7 | 7 |
| 8 It supports several test URLs, as specified by the handlers in TestPageHandler. | 8 It supports several test URLs, as specified by the handlers in TestPageHandler. |
| 9 It defaults to living on localhost:8888. | 9 It defaults to living on localhost:8888. |
| 10 It can use https if you specify the flag --https=CERT where CERT is the path | 10 It can use https if you specify the flag --https=CERT where CERT is the path |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 self.ContentTypeHandler, | 113 self.ContentTypeHandler, |
| 114 self.ServerRedirectHandler, | 114 self.ServerRedirectHandler, |
| 115 self.ClientRedirectHandler, | 115 self.ClientRedirectHandler, |
| 116 self.DefaultResponseHandler] | 116 self.DefaultResponseHandler] |
| 117 self._post_handlers = [ | 117 self._post_handlers = [ |
| 118 self.WriteFile, | 118 self.WriteFile, |
| 119 self.EchoTitleHandler, | 119 self.EchoTitleHandler, |
| 120 self.EchoAllHandler, | 120 self.EchoAllHandler, |
| 121 self.EchoHandler] + self._get_handlers | 121 self.EchoHandler] + self._get_handlers |
| 122 | 122 |
| 123 self._mime_types = { 'gif': 'image/gif', 'jpeg' : 'image/jpeg', 'jpg' : 'im
age/jpeg' } | 123 self._mime_types = { |
| 124 'gif': 'image/gif', |
| 125 'jpeg' : 'image/jpeg', |
| 126 'jpg' : 'image/jpeg' |
| 127 } |
| 124 self._default_mime_type = 'text/html' | 128 self._default_mime_type = 'text/html' |
| 125 | 129 |
| 126 BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, request, client_address
, socket_server) | 130 BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, request, |
| 131 client_address, |
| 132 socket_server) |
| 127 | 133 |
| 128 def _ShouldHandleRequest(self, handler_name): | 134 def _ShouldHandleRequest(self, handler_name): |
| 129 """Determines if the path can be handled by the handler. | 135 """Determines if the path can be handled by the handler. |
| 130 | 136 |
| 131 We consider a handler valid if the path begins with the | 137 We consider a handler valid if the path begins with the |
| 132 handler name. It can optionally be followed by "?*", "/*". | 138 handler name. It can optionally be followed by "?*", "/*". |
| 133 """ | 139 """ |
| 134 | 140 |
| 135 pattern = re.compile('%s($|\?|/).*' % handler_name) | 141 pattern = re.compile('%s($|\?|/).*' % handler_name) |
| 136 return pattern.match(self.path) | 142 return pattern.match(self.path) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 167 system time, and no caching requested.""" | 173 system time, and no caching requested.""" |
| 168 | 174 |
| 169 if not self._ShouldHandleRequest("/nocachetime/maxage"): | 175 if not self._ShouldHandleRequest("/nocachetime/maxage"): |
| 170 return False | 176 return False |
| 171 | 177 |
| 172 self.send_response(200) | 178 self.send_response(200) |
| 173 self.send_header('Cache-Control', 'max-age=0') | 179 self.send_header('Cache-Control', 'max-age=0') |
| 174 self.send_header('Content-type', 'text/html') | 180 self.send_header('Content-type', 'text/html') |
| 175 self.end_headers() | 181 self.end_headers() |
| 176 | 182 |
| 177 self.wfile.write('<html><head><title>%s</title></head></html>' % time.time()
) | 183 self.wfile.write('<html><head><title>%s</title></head></html>' % |
| 184 time.time()) |
| 178 | 185 |
| 179 return True | 186 return True |
| 180 | 187 |
| 181 def NoCacheTimeHandler(self): | 188 def NoCacheTimeHandler(self): |
| 182 """This request handler yields a page with the title set to the current | 189 """This request handler yields a page with the title set to the current |
| 183 system time, and no caching requested.""" | 190 system time, and no caching requested.""" |
| 184 | 191 |
| 185 if not self._ShouldHandleRequest("/nocachetime"): | 192 if not self._ShouldHandleRequest("/nocachetime"): |
| 186 return False | 193 return False |
| 187 | 194 |
| 188 self.send_response(200) | 195 self.send_response(200) |
| 189 self.send_header('Cache-Control', 'no-cache') | 196 self.send_header('Cache-Control', 'no-cache') |
| 190 self.send_header('Content-type', 'text/html') | 197 self.send_header('Content-type', 'text/html') |
| 191 self.end_headers() | 198 self.end_headers() |
| 192 | 199 |
| 193 self.wfile.write('<html><head><title>%s</title></head></html>' % time.time()
) | 200 self.wfile.write('<html><head><title>%s</title></head></html>' % |
| 201 time.time()) |
| 194 | 202 |
| 195 return True | 203 return True |
| 196 | 204 |
| 197 def CacheTimeHandler(self): | 205 def CacheTimeHandler(self): |
| 198 """This request handler yields a page with the title set to the current | 206 """This request handler yields a page with the title set to the current |
| 199 system time, and allows caching for one minute.""" | 207 system time, and allows caching for one minute.""" |
| 200 | 208 |
| 201 if not self._ShouldHandleRequest("/cachetime"): | 209 if not self._ShouldHandleRequest("/cachetime"): |
| 202 return False | 210 return False |
| 203 | 211 |
| 204 self.send_response(200) | 212 self.send_response(200) |
| 205 self.send_header('Cache-Control', 'max-age=60') | 213 self.send_header('Cache-Control', 'max-age=60') |
| 206 self.send_header('Content-type', 'text/html') | 214 self.send_header('Content-type', 'text/html') |
| 207 self.end_headers() | 215 self.end_headers() |
| 208 | 216 |
| 209 self.wfile.write('<html><head><title>%s</title></head></html>' % time.time()
) | 217 self.wfile.write('<html><head><title>%s</title></head></html>' % |
| 218 time.time()) |
| 210 | 219 |
| 211 return True | 220 return True |
| 212 | 221 |
| 213 def CacheExpiresHandler(self): | 222 def CacheExpiresHandler(self): |
| 214 """This request handler yields a page with the title set to the current | 223 """This request handler yields a page with the title set to the current |
| 215 system time, and set the page to expire on 1 Jan 2099.""" | 224 system time, and set the page to expire on 1 Jan 2099.""" |
| 216 | 225 |
| 217 if not self._ShouldHandleRequest("/cache/expires"): | 226 if not self._ShouldHandleRequest("/cache/expires"): |
| 218 return False | 227 return False |
| 219 | 228 |
| 220 self.send_response(200) | 229 self.send_response(200) |
| 221 self.send_header('Expires', 'Thu, 1 Jan 2099 00:00:00 GMT') | 230 self.send_header('Expires', 'Thu, 1 Jan 2099 00:00:00 GMT') |
| 222 self.send_header('Content-type', 'text/html') | 231 self.send_header('Content-type', 'text/html') |
| 223 self.end_headers() | 232 self.end_headers() |
| 224 | 233 |
| 225 self.wfile.write('<html><head><title>%s</title></head></html>' % time.time()
) | 234 self.wfile.write('<html><head><title>%s</title></head></html>' % |
| 235 time.time()) |
| 226 | 236 |
| 227 return True | 237 return True |
| 228 | 238 |
| 229 def CacheProxyRevalidateHandler(self): | 239 def CacheProxyRevalidateHandler(self): |
| 230 """This request handler yields a page with the title set to the current | 240 """This request handler yields a page with the title set to the current |
| 231 system time, and allows caching for 60 seconds""" | 241 system time, and allows caching for 60 seconds""" |
| 232 | 242 |
| 233 if not self._ShouldHandleRequest("/cache/proxy-revalidate"): | 243 if not self._ShouldHandleRequest("/cache/proxy-revalidate"): |
| 234 return False | 244 return False |
| 235 | 245 |
| 236 self.send_response(200) | 246 self.send_response(200) |
| 237 self.send_header('Content-type', 'text/html') | 247 self.send_header('Content-type', 'text/html') |
| 238 self.send_header('Cache-Control', 'max-age=60, proxy-revalidate') | 248 self.send_header('Cache-Control', 'max-age=60, proxy-revalidate') |
| 239 self.end_headers() | 249 self.end_headers() |
| 240 | 250 |
| 241 self.wfile.write('<html><head><title>%s</title></head></html>' % time.time()
) | 251 self.wfile.write('<html><head><title>%s</title></head></html>' % |
| 252 time.time()) |
| 242 | 253 |
| 243 return True | 254 return True |
| 244 | 255 |
| 245 def CachePrivateHandler(self): | 256 def CachePrivateHandler(self): |
| 246 """This request handler yields a page with the title set to the current | 257 """This request handler yields a page with the title set to the current |
| 247 system time, and allows caching for 5 seconds.""" | 258 system time, and allows caching for 5 seconds.""" |
| 248 | 259 |
| 249 if not self._ShouldHandleRequest("/cache/private"): | 260 if not self._ShouldHandleRequest("/cache/private"): |
| 250 return False | 261 return False |
| 251 | 262 |
| 252 self.send_response(200) | 263 self.send_response(200) |
| 253 self.send_header('Content-type', 'text/html') | 264 self.send_header('Content-type', 'text/html') |
| 254 self.send_header('Cache-Control', 'max-age=5, private') | 265 self.send_header('Cache-Control', 'max-age=5, private') |
| 255 self.end_headers() | 266 self.end_headers() |
| 256 | 267 |
| 257 self.wfile.write('<html><head><title>%s</title></head></html>' % time.time()
) | 268 self.wfile.write('<html><head><title>%s</title></head></html>' % |
| 269 time.time()) |
| 258 | 270 |
| 259 return True | 271 return True |
| 260 | 272 |
| 261 def CachePublicHandler(self): | 273 def CachePublicHandler(self): |
| 262 """This request handler yields a page with the title set to the current | 274 """This request handler yields a page with the title set to the current |
| 263 system time, and allows caching for 5 seconds.""" | 275 system time, and allows caching for 5 seconds.""" |
| 264 | 276 |
| 265 if not self._ShouldHandleRequest("/cache/public"): | 277 if not self._ShouldHandleRequest("/cache/public"): |
| 266 return False | 278 return False |
| 267 | 279 |
| 268 self.send_response(200) | 280 self.send_response(200) |
| 269 self.send_header('Content-type', 'text/html') | 281 self.send_header('Content-type', 'text/html') |
| 270 self.send_header('Cache-Control', 'max-age=5, public') | 282 self.send_header('Cache-Control', 'max-age=5, public') |
| 271 self.end_headers() | 283 self.end_headers() |
| 272 | 284 |
| 273 self.wfile.write('<html><head><title>%s</title></head></html>' % time.time()
) | 285 self.wfile.write('<html><head><title>%s</title></head></html>' % |
| 286 time.time()) |
| 274 | 287 |
| 275 return True | 288 return True |
| 276 | 289 |
| 277 def CacheSMaxAgeHandler(self): | 290 def CacheSMaxAgeHandler(self): |
| 278 """This request handler yields a page with the title set to the current | 291 """This request handler yields a page with the title set to the current |
| 279 system time, and does not allow for caching.""" | 292 system time, and does not allow for caching.""" |
| 280 | 293 |
| 281 if not self._ShouldHandleRequest("/cache/s-maxage"): | 294 if not self._ShouldHandleRequest("/cache/s-maxage"): |
| 282 return False | 295 return False |
| 283 | 296 |
| 284 self.send_response(200) | 297 self.send_response(200) |
| 285 self.send_header('Content-type', 'text/html') | 298 self.send_header('Content-type', 'text/html') |
| 286 self.send_header('Cache-Control', 'public, s-maxage = 60, max-age = 0') | 299 self.send_header('Cache-Control', 'public, s-maxage = 60, max-age = 0') |
| 287 self.end_headers() | 300 self.end_headers() |
| 288 | 301 |
| 289 self.wfile.write('<html><head><title>%s</title></head></html>' % time.time()
) | 302 self.wfile.write('<html><head><title>%s</title></head></html>' % |
| 303 time.time()) |
| 290 | 304 |
| 291 return True | 305 return True |
| 292 | 306 |
| 293 def CacheMustRevalidateHandler(self): | 307 def CacheMustRevalidateHandler(self): |
| 294 """This request handler yields a page with the title set to the current | 308 """This request handler yields a page with the title set to the current |
| 295 system time, and does not allow caching.""" | 309 system time, and does not allow caching.""" |
| 296 | 310 |
| 297 if not self._ShouldHandleRequest("/cache/must-revalidate"): | 311 if not self._ShouldHandleRequest("/cache/must-revalidate"): |
| 298 return False | 312 return False |
| 299 | 313 |
| 300 self.send_response(200) | 314 self.send_response(200) |
| 301 self.send_header('Content-type', 'text/html') | 315 self.send_header('Content-type', 'text/html') |
| 302 self.send_header('Cache-Control', 'must-revalidate') | 316 self.send_header('Cache-Control', 'must-revalidate') |
| 303 self.end_headers() | 317 self.end_headers() |
| 304 | 318 |
| 305 self.wfile.write('<html><head><title>%s</title></head></html>' % time.time()
) | 319 self.wfile.write('<html><head><title>%s</title></head></html>' % |
| 320 time.time()) |
| 306 | 321 |
| 307 return True | 322 return True |
| 308 | 323 |
| 309 def CacheMustRevalidateMaxAgeHandler(self): | 324 def CacheMustRevalidateMaxAgeHandler(self): |
| 310 """This request handler yields a page with the title set to the current | 325 """This request handler yields a page with the title set to the current |
| 311 system time, and does not allow caching event though max-age of 60 | 326 system time, and does not allow caching event though max-age of 60 |
| 312 seconds is specified.""" | 327 seconds is specified.""" |
| 313 | 328 |
| 314 if not self._ShouldHandleRequest("/cache/must-revalidate/max-age"): | 329 if not self._ShouldHandleRequest("/cache/must-revalidate/max-age"): |
| 315 return False | 330 return False |
| 316 | 331 |
| 317 self.send_response(200) | 332 self.send_response(200) |
| 318 self.send_header('Content-type', 'text/html') | 333 self.send_header('Content-type', 'text/html') |
| 319 self.send_header('Cache-Control', 'max-age=60, must-revalidate') | 334 self.send_header('Cache-Control', 'max-age=60, must-revalidate') |
| 320 self.end_headers() | 335 self.end_headers() |
| 321 | 336 |
| 322 self.wfile.write('<html><head><title>%s</title></head></html>' % time.time()
) | 337 self.wfile.write('<html><head><title>%s</title></head></html>' % |
| 338 time.time()) |
| 323 | 339 |
| 324 return True | 340 return True |
| 325 | 341 |
| 326 def CacheNoStoreHandler(self): | 342 def CacheNoStoreHandler(self): |
| 327 """This request handler yields a page with the title set to the current | 343 """This request handler yields a page with the title set to the current |
| 328 system time, and does not allow the page to be stored.""" | 344 system time, and does not allow the page to be stored.""" |
| 329 | 345 |
| 330 if not self._ShouldHandleRequest("/cache/no-store"): | 346 if not self._ShouldHandleRequest("/cache/no-store"): |
| 331 return False | 347 return False |
| 332 | 348 |
| 333 self.send_response(200) | 349 self.send_response(200) |
| 334 self.send_header('Content-type', 'text/html') | 350 self.send_header('Content-type', 'text/html') |
| 335 self.send_header('Cache-Control', 'no-store') | 351 self.send_header('Cache-Control', 'no-store') |
| 336 self.end_headers() | 352 self.end_headers() |
| 337 | 353 |
| 338 self.wfile.write('<html><head><title>%s</title></head></html>' % time.time()
) | 354 self.wfile.write('<html><head><title>%s</title></head></html>' % |
| 355 time.time()) |
| 339 | 356 |
| 340 return True | 357 return True |
| 341 | 358 |
| 342 def CacheNoStoreMaxAgeHandler(self): | 359 def CacheNoStoreMaxAgeHandler(self): |
| 343 """This request handler yields a page with the title set to the current | 360 """This request handler yields a page with the title set to the current |
| 344 system time, and does not allow the page to be stored even though max-age | 361 system time, and does not allow the page to be stored even though max-age |
| 345 of 60 seconds is specified.""" | 362 of 60 seconds is specified.""" |
| 346 | 363 |
| 347 if not self._ShouldHandleRequest("/cache/no-store/max-age"): | 364 if not self._ShouldHandleRequest("/cache/no-store/max-age"): |
| 348 return False | 365 return False |
| 349 | 366 |
| 350 self.send_response(200) | 367 self.send_response(200) |
| 351 self.send_header('Content-type', 'text/html') | 368 self.send_header('Content-type', 'text/html') |
| 352 self.send_header('Cache-Control', 'max-age=60, no-store') | 369 self.send_header('Cache-Control', 'max-age=60, no-store') |
| 353 self.end_headers() | 370 self.end_headers() |
| 354 | 371 |
| 355 self.wfile.write('<html><head><title>%s</title></head></html>' % time.time()
) | 372 self.wfile.write('<html><head><title>%s</title></head></html>' % |
| 373 time.time()) |
| 356 | 374 |
| 357 return True | 375 return True |
| 358 | 376 |
| 359 | 377 |
| 360 def CacheNoTransformHandler(self): | 378 def CacheNoTransformHandler(self): |
| 361 """This request handler yields a page with the title set to the current | 379 """This request handler yields a page with the title set to the current |
| 362 system time, and does not allow the content to transformed during | 380 system time, and does not allow the content to transformed during |
| 363 user-agent caching""" | 381 user-agent caching""" |
| 364 | 382 |
| 365 if not self._ShouldHandleRequest("/cache/no-transform"): | 383 if not self._ShouldHandleRequest("/cache/no-transform"): |
| 366 return False | 384 return False |
| 367 | 385 |
| 368 self.send_response(200) | 386 self.send_response(200) |
| 369 self.send_header('Content-type', 'text/html') | 387 self.send_header('Content-type', 'text/html') |
| 370 self.send_header('Cache-Control', 'no-transform') | 388 self.send_header('Cache-Control', 'no-transform') |
| 371 self.end_headers() | 389 self.end_headers() |
| 372 | 390 |
| 373 self.wfile.write('<html><head><title>%s</title></head></html>' % time.time()
) | 391 self.wfile.write('<html><head><title>%s</title></head></html>' % |
| 392 time.time()) |
| 374 | 393 |
| 375 return True | 394 return True |
| 376 | 395 |
| 377 def EchoHeader(self): | 396 def EchoHeader(self): |
| 378 """This handler echoes back the value of a specific request header.""" | 397 """This handler echoes back the value of a specific request header.""" |
| 379 | 398 |
| 380 if not self._ShouldHandleRequest("/echoheader"): | 399 if not self._ShouldHandleRequest("/echoheader"): |
| 381 return False | 400 return False |
| 382 | 401 |
| 383 query_char = self.path.find('?') | 402 query_char = self.path.find('?') |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 """This handler tests 'Digest' authentication. It just sends a page with | 742 """This handler tests 'Digest' authentication. It just sends a page with |
| 724 title 'user/pass' if you succeed.""" | 743 title 'user/pass' if you succeed.""" |
| 725 | 744 |
| 726 if not self._ShouldHandleRequest("/auth-digest"): | 745 if not self._ShouldHandleRequest("/auth-digest"): |
| 727 return False | 746 return False |
| 728 | 747 |
| 729 # Periodically generate a new nonce. Technically we should incorporate | 748 # Periodically generate a new nonce. Technically we should incorporate |
| 730 # the request URL into this, but we don't care for testing. | 749 # the request URL into this, but we don't care for testing. |
| 731 nonce_life = 10 | 750 nonce_life = 10 |
| 732 stale = False | 751 stale = False |
| 733 if not self.server.nonce or (time.time() - self.server.nonce_time > nonce_li
fe): | 752 if (not self.server.nonce or |
| 753 (time.time() - self.server.nonce_time > nonce_life)): |
| 734 if self.server.nonce: | 754 if self.server.nonce: |
| 735 stale = True | 755 stale = True |
| 736 self.server.nonce_time = time.time() | 756 self.server.nonce_time = time.time() |
| 737 self.server.nonce = \ | 757 self.server.nonce = \ |
| 738 _new_md5(time.ctime(self.server.nonce_time) + 'privatekey').hexdigest(
) | 758 _new_md5(time.ctime(self.server.nonce_time) + |
| 759 'privatekey').hexdigest() |
| 739 | 760 |
| 740 nonce = self.server.nonce | 761 nonce = self.server.nonce |
| 741 opaque = _new_md5('opaque').hexdigest() | 762 opaque = _new_md5('opaque').hexdigest() |
| 742 password = 'secret' | 763 password = 'secret' |
| 743 realm = 'testrealm' | 764 realm = 'testrealm' |
| 744 | 765 |
| 745 auth = self.headers.getheader('authorization') | 766 auth = self.headers.getheader('authorization') |
| 746 pairs = {} | 767 pairs = {} |
| 747 try: | 768 try: |
| 748 if not auth: | 769 if not auth: |
| 749 raise Exception('no auth') | 770 raise Exception('no auth') |
| 750 if not auth.startswith('Digest'): | 771 if not auth.startswith('Digest'): |
| 751 raise Exception('not digest') | 772 raise Exception('not digest') |
| 752 # Pull out all the name="value" pairs as a dictionary. | 773 # Pull out all the name="value" pairs as a dictionary. |
| 753 pairs = dict(re.findall(r'(\b[^ ,=]+)="?([^",]+)"?', auth)) | 774 pairs = dict(re.findall(r'(\b[^ ,=]+)="?([^",]+)"?', auth)) |
| 754 | 775 |
| 755 # Make sure it's all valid. | 776 # Make sure it's all valid. |
| 756 if pairs['nonce'] != nonce: | 777 if pairs['nonce'] != nonce: |
| 757 raise Exception('wrong nonce') | 778 raise Exception('wrong nonce') |
| 758 if pairs['opaque'] != opaque: | 779 if pairs['opaque'] != opaque: |
| 759 raise Exception('wrong opaque') | 780 raise Exception('wrong opaque') |
| 760 | 781 |
| 761 # Check the 'response' value and make sure it matches our magic hash. | 782 # Check the 'response' value and make sure it matches our magic hash. |
| 762 # See http://www.ietf.org/rfc/rfc2617.txt | 783 # See http://www.ietf.org/rfc/rfc2617.txt |
| 763 hash_a1 = _new_md5(':'.join([pairs['username'], realm, password])).hexdige
st() | 784 hash_a1 = _new_md5( |
| 785 ':'.join([pairs['username'], realm, password])).hexdigest() |
| 764 hash_a2 = _new_md5(':'.join([self.command, pairs['uri']])).hexdigest() | 786 hash_a2 = _new_md5(':'.join([self.command, pairs['uri']])).hexdigest() |
| 765 if 'qop' in pairs and 'nc' in pairs and 'cnonce' in pairs: | 787 if 'qop' in pairs and 'nc' in pairs and 'cnonce' in pairs: |
| 766 response = _new_md5(':'.join([hash_a1, nonce, pairs['nc'], | 788 response = _new_md5(':'.join([hash_a1, nonce, pairs['nc'], |
| 767 pairs['cnonce'], pairs['qop'], hash_a2])).hexdigest() | 789 pairs['cnonce'], pairs['qop'], hash_a2])).hexdigest() |
| 768 else: | 790 else: |
| 769 response = _new_md5(':'.join([hash_a1, nonce, hash_a2])).hexdigest() | 791 response = _new_md5(':'.join([hash_a1, nonce, hash_a2])).hexdigest() |
| 770 | 792 |
| 771 if pairs['response'] != response: | 793 if pairs['response'] != response: |
| 772 raise Exception('wrong password') | 794 raise Exception('wrong password') |
| 773 except Exception, e: | 795 except Exception, e: |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 if not content_type: | 860 if not content_type: |
| 839 content_type = 'text/html' | 861 content_type = 'text/html' |
| 840 self.send_response(200) | 862 self.send_response(200) |
| 841 self.send_header('Content-Type', content_type) | 863 self.send_header('Content-Type', content_type) |
| 842 self.end_headers() | 864 self.end_headers() |
| 843 self.wfile.write("<html>\n<body>\n<p>HTML text</p>\n</body>\n</html>\n"); | 865 self.wfile.write("<html>\n<body>\n<p>HTML text</p>\n</body>\n</html>\n"); |
| 844 return True | 866 return True |
| 845 | 867 |
| 846 def ServerRedirectHandler(self): | 868 def ServerRedirectHandler(self): |
| 847 """Sends a server redirect to the given URL. The syntax is | 869 """Sends a server redirect to the given URL. The syntax is |
| 848 '/server-redirect?http://foo.bar/asdf' to redirect to 'http://foo.bar/asdf'"
"" | 870 '/server-redirect?http://foo.bar/asdf' to redirect to |
| 871 'http://foo.bar/asdf'""" |
| 849 | 872 |
| 850 test_name = "/server-redirect" | 873 test_name = "/server-redirect" |
| 851 if not self._ShouldHandleRequest(test_name): | 874 if not self._ShouldHandleRequest(test_name): |
| 852 return False | 875 return False |
| 853 | 876 |
| 854 query_char = self.path.find('?') | 877 query_char = self.path.find('?') |
| 855 if query_char < 0 or len(self.path) <= query_char + 1: | 878 if query_char < 0 or len(self.path) <= query_char + 1: |
| 856 self.sendRedirectHelp(test_name) | 879 self.sendRedirectHelp(test_name) |
| 857 return True | 880 return True |
| 858 dest = self.path[query_char + 1:] | 881 dest = self.path[query_char + 1:] |
| 859 | 882 |
| 860 self.send_response(301) # moved permanently | 883 self.send_response(301) # moved permanently |
| 861 self.send_header('Location', dest) | 884 self.send_header('Location', dest) |
| 862 self.send_header('Content-type', 'text/html') | 885 self.send_header('Content-type', 'text/html') |
| 863 self.end_headers() | 886 self.end_headers() |
| 864 self.wfile.write('<html><head>') | 887 self.wfile.write('<html><head>') |
| 865 self.wfile.write('</head><body>Redirecting to %s</body></html>' % dest) | 888 self.wfile.write('</head><body>Redirecting to %s</body></html>' % dest) |
| 866 | 889 |
| 867 return True | 890 return True |
| 868 | 891 |
| 869 def ClientRedirectHandler(self): | 892 def ClientRedirectHandler(self): |
| 870 """Sends a client redirect to the given URL. The syntax is | 893 """Sends a client redirect to the given URL. The syntax is |
| 871 '/client-redirect?http://foo.bar/asdf' to redirect to 'http://foo.bar/asdf'"
"" | 894 '/client-redirect?http://foo.bar/asdf' to redirect to |
| 895 'http://foo.bar/asdf'""" |
| 872 | 896 |
| 873 test_name = "/client-redirect" | 897 test_name = "/client-redirect" |
| 874 if not self._ShouldHandleRequest(test_name): | 898 if not self._ShouldHandleRequest(test_name): |
| 875 return False | 899 return False |
| 876 | 900 |
| 877 query_char = self.path.find('?'); | 901 query_char = self.path.find('?'); |
| 878 if query_char < 0 or len(self.path) <= query_char + 1: | 902 if query_char < 0 or len(self.path) <= query_char + 1: |
| 879 self.sendRedirectHelp(test_name) | 903 self.sendRedirectHelp(test_name) |
| 880 return True | 904 return True |
| 881 dest = self.path[query_char + 1:] | 905 dest = self.path[query_char + 1:] |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 authorizer.add_user('chrome', 'chrome', my_data_dir, perm='elradfmw') | 1062 authorizer.add_user('chrome', 'chrome', my_data_dir, perm='elradfmw') |
| 1039 | 1063 |
| 1040 authorizer.add_anonymous(my_data_dir) | 1064 authorizer.add_anonymous(my_data_dir) |
| 1041 | 1065 |
| 1042 # Instantiate FTP handler class | 1066 # Instantiate FTP handler class |
| 1043 ftp_handler = pyftpdlib.ftpserver.FTPHandler | 1067 ftp_handler = pyftpdlib.ftpserver.FTPHandler |
| 1044 ftp_handler.authorizer = authorizer | 1068 ftp_handler.authorizer = authorizer |
| 1045 pyftpdlib.ftpserver.logline = line_logger | 1069 pyftpdlib.ftpserver.logline = line_logger |
| 1046 | 1070 |
| 1047 # Define a customized banner (string returned when client connects) | 1071 # Define a customized banner (string returned when client connects) |
| 1048 ftp_handler.banner = "pyftpdlib %s based ftpd ready." % pyftpdlib.ftpserver.
__ver__ | 1072 ftp_handler.banner = ("pyftpdlib %s based ftpd ready." % |
| 1073 pyftpdlib.ftpserver.__ver__) |
| 1049 | 1074 |
| 1050 # Instantiate FTP server class and listen to 127.0.0.1:port | 1075 # Instantiate FTP server class and listen to 127.0.0.1:port |
| 1051 address = ('127.0.0.1', port) | 1076 address = ('127.0.0.1', port) |
| 1052 server = pyftpdlib.ftpserver.FTPServer(address, ftp_handler) | 1077 server = pyftpdlib.ftpserver.FTPServer(address, ftp_handler) |
| 1053 print 'FTP server started on port %d...' % port | 1078 print 'FTP server started on port %d...' % port |
| 1054 | 1079 |
| 1055 try: | 1080 try: |
| 1056 server.serve_forever() | 1081 server.serve_forever() |
| 1057 except KeyboardInterrupt: | 1082 except KeyboardInterrupt: |
| 1058 print 'shutting down server' | 1083 print 'shutting down server' |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1069 option_parser.add_option('', '--data-dir', dest='data_dir', | 1094 option_parser.add_option('', '--data-dir', dest='data_dir', |
| 1070 help='Directory from which to read the files') | 1095 help='Directory from which to read the files') |
| 1071 option_parser.add_option('', '--https', dest='cert', | 1096 option_parser.add_option('', '--https', dest='cert', |
| 1072 help='Specify that https should be used, specify ' | 1097 help='Specify that https should be used, specify ' |
| 1073 'the path to the cert containing the private key ' | 1098 'the path to the cert containing the private key ' |
| 1074 'the server should use') | 1099 'the server should use') |
| 1075 options, args = option_parser.parse_args() | 1100 options, args = option_parser.parse_args() |
| 1076 | 1101 |
| 1077 sys.exit(main(options, args)) | 1102 sys.exit(main(options, args)) |
| 1078 | 1103 |
| OLD | NEW |