equal
deleted
inserted
replaced
8 # This was originally copied from the public domain code at |
8 # This was originally copied from the public domain code at |
9 # http://www.python.org/dev/peps/pep-0333/#the-server-gateway-side |
9 # http://www.python.org/dev/peps/pep-0333/#the-server-gateway-side |
10 |
10 |
11 from __future__ import absolute_import |
11 from __future__ import absolute_import |
12 |
12 |
|
13 import os |
|
14 |
13 from .. import ( |
15 from .. import ( |
14 encoding, |
16 pycompat, |
15 ) |
17 ) |
16 |
18 |
17 from ..utils import ( |
19 from ..utils import ( |
18 procutil, |
20 procutil, |
19 ) |
21 ) |
24 |
26 |
25 def launch(application): |
27 def launch(application): |
26 procutil.setbinary(procutil.stdin) |
28 procutil.setbinary(procutil.stdin) |
27 procutil.setbinary(procutil.stdout) |
29 procutil.setbinary(procutil.stdout) |
28 |
30 |
29 environ = dict(encoding.environ.iteritems()) |
31 environ = dict(os.environ.iteritems()) # re-exports |
30 environ.setdefault(r'PATH_INFO', '') |
32 environ.setdefault(r'PATH_INFO', '') |
31 if environ.get(r'SERVER_SOFTWARE', r'').startswith(r'Microsoft-IIS'): |
33 if environ.get(r'SERVER_SOFTWARE', r'').startswith(r'Microsoft-IIS'): |
32 # IIS includes script_name in PATH_INFO |
34 # IIS includes script_name in PATH_INFO |
33 scriptname = environ[r'SCRIPT_NAME'] |
35 scriptname = environ[r'SCRIPT_NAME'] |
34 if environ[r'PATH_INFO'].startswith(scriptname): |
36 if environ[r'PATH_INFO'].startswith(scriptname): |
59 raise AssertionError("write() before start_response()") |
61 raise AssertionError("write() before start_response()") |
60 |
62 |
61 elif not headers_sent: |
63 elif not headers_sent: |
62 # Before the first output, send the stored headers |
64 # Before the first output, send the stored headers |
63 status, response_headers = headers_sent[:] = headers_set |
65 status, response_headers = headers_sent[:] = headers_set |
64 out.write('Status: %s\r\n' % status) |
66 out.write('Status: %s\r\n' % pycompat.bytesurl(status)) |
65 for header in response_headers: |
67 for hk, hv in response_headers: |
66 out.write('%s: %s\r\n' % header) |
68 out.write('%s: %s\r\n' % (pycompat.bytesurl(hk), |
|
69 pycompat.bytesurl(hv))) |
67 out.write('\r\n') |
70 out.write('\r\n') |
68 |
71 |
69 out.write(data) |
72 out.write(data) |
70 out.flush() |
73 out.flush() |
71 |
74 |