equal
deleted
inserted
replaced
74 |
74 |
75 from google.appengine.api import apiproxy_stub_map |
75 from google.appengine.api import apiproxy_stub_map |
76 from google.appengine.api import appinfo |
76 from google.appengine.api import appinfo |
77 from google.appengine.api import datastore_admin |
77 from google.appengine.api import datastore_admin |
78 from google.appengine.api import datastore_file_stub |
78 from google.appengine.api import datastore_file_stub |
|
79 from google.appengine.api import mail_stub |
79 from google.appengine.api import urlfetch_stub |
80 from google.appengine.api import urlfetch_stub |
80 from google.appengine.api import mail_stub |
|
81 from google.appengine.api import user_service_stub |
81 from google.appengine.api import user_service_stub |
82 from google.appengine.api import yaml_errors |
82 from google.appengine.api import yaml_errors |
|
83 from google.appengine.api.capabilities import capability_stub |
83 from google.appengine.api.memcache import memcache_stub |
84 from google.appengine.api.memcache import memcache_stub |
84 |
85 |
85 from google.appengine.tools import dev_appserver_index |
86 from google.appengine.tools import dev_appserver_index |
86 from google.appengine.tools import dev_appserver_login |
87 from google.appengine.tools import dev_appserver_login |
87 |
88 |
465 % (level_name, time_diff, level_letter)) |
466 % (level_name, time_diff, level_letter)) |
466 outfile.write('%s\n' % message) |
467 outfile.write('%s\n' % message) |
467 outfile.write('</span>\n') |
468 outfile.write('</span>\n') |
468 |
469 |
469 |
470 |
470 _IGNORE_HEADERS = frozenset(['content-type', 'content-length']) |
471 _IGNORE_REQUEST_HEADERS = frozenset(['content-type', 'content-length', |
|
472 'accept-encoding', 'transfer-encoding']) |
471 |
473 |
472 def SetupEnvironment(cgi_path, |
474 def SetupEnvironment(cgi_path, |
473 relative_url, |
475 relative_url, |
474 headers, |
476 headers, |
475 split_url=SplitURL, |
477 split_url=SplitURL, |
502 env['USER_EMAIL'] = email |
504 env['USER_EMAIL'] = email |
503 if admin: |
505 if admin: |
504 env['USER_IS_ADMIN'] = '1' |
506 env['USER_IS_ADMIN'] = '1' |
505 |
507 |
506 for key in headers: |
508 for key in headers: |
507 if key in _IGNORE_HEADERS: |
509 if key in _IGNORE_REQUEST_HEADERS: |
508 continue |
510 continue |
509 adjusted_name = key.replace('-', '_').upper() |
511 adjusted_name = key.replace('-', '_').upper() |
510 env['HTTP_' + adjusted_name] = ', '.join(headers.getheaders(key)) |
512 env['HTTP_' + adjusted_name] = ', '.join(headers.getheaders(key)) |
511 |
513 |
512 return env |
514 return env |
2133 def __str__(self): |
2135 def __str__(self): |
2134 """Returns a string representation of this dispatcher.""" |
2136 """Returns a string representation of this dispatcher.""" |
2135 return 'File dispatcher' |
2137 return 'File dispatcher' |
2136 |
2138 |
2137 |
2139 |
|
2140 _IGNORE_RESPONSE_HEADERS = frozenset([ |
|
2141 'content-encoding', 'accept-encoding', 'transfer-encoding', |
|
2142 'server', 'date', |
|
2143 ]) |
|
2144 |
|
2145 |
2138 def RewriteResponse(response_file): |
2146 def RewriteResponse(response_file): |
2139 """Interprets server-side headers and adjusts the HTTP response accordingly. |
2147 """Interprets server-side headers and adjusts the HTTP response accordingly. |
2140 |
2148 |
2141 Handles the server-side 'status' header, which instructs the server to change |
2149 Handles the server-side 'status' header, which instructs the server to change |
2142 the HTTP response code accordingly. Handles the 'location' header, which |
2150 the HTTP response code accordingly. Handles the 'location' header, which |
2148 set the response to a 500 with an error message as content. |
2156 set the response to a 500 with an error message as content. |
2149 |
2157 |
2150 Args: |
2158 Args: |
2151 response_file: File-like object containing the full HTTP response including |
2159 response_file: File-like object containing the full HTTP response including |
2152 the response code, all headers, and the request body. |
2160 the response code, all headers, and the request body. |
|
2161 gmtime: Function which returns current time in a format matching standard |
|
2162 time.gmtime(). |
2153 |
2163 |
2154 Returns: |
2164 Returns: |
2155 Tuple (status_code, status_message, header, body) where: |
2165 Tuple (status_code, status_message, header, body) where: |
2156 status_code: Integer HTTP response status (e.g., 200, 302, 404, 500) |
2166 status_code: Integer HTTP response status (e.g., 200, 302, 404, 500) |
2157 status_message: String containing an informational message about the |
2167 status_message: String containing an informational message about the |
2159 header: String containing the HTTP headers of the response, without |
2169 header: String containing the HTTP headers of the response, without |
2160 a trailing new-line (CRLF). |
2170 a trailing new-line (CRLF). |
2161 body: String containing the body of the response. |
2171 body: String containing the body of the response. |
2162 """ |
2172 """ |
2163 headers = mimetools.Message(response_file) |
2173 headers = mimetools.Message(response_file) |
|
2174 |
|
2175 for h in _IGNORE_RESPONSE_HEADERS: |
|
2176 if h in headers: |
|
2177 del headers[h] |
2164 |
2178 |
2165 response_status = '%d Good to go' % httplib.OK |
2179 response_status = '%d Good to go' % httplib.OK |
2166 |
2180 |
2167 location_value = headers.getheader('location') |
2181 location_value = headers.getheader('location') |
2168 status_value = headers.getheader('status') |
2182 status_value = headers.getheader('status') |
2183 status_code = 500 |
2197 status_code = 500 |
2184 body = 'Error: Invalid "status" header value returned.' |
2198 body = 'Error: Invalid "status" header value returned.' |
2185 else: |
2199 else: |
2186 body = response_file.read() |
2200 body = response_file.read() |
2187 |
2201 |
2188 headers['content-length'] = str(len(body)) |
2202 headers['Content-Length'] = str(len(body)) |
2189 |
2203 |
2190 header_list = [] |
2204 header_list = [] |
2191 for header in headers.headers: |
2205 for header in headers.headers: |
2192 header = header.rstrip('\n') |
2206 header = header.rstrip('\n') |
2193 header = header.rstrip('\r') |
2207 header = header.rstrip('\r') |
2351 Args: |
2365 Args: |
2352 args, kwargs: Positional and keyword arguments passed to the constructor |
2366 args, kwargs: Positional and keyword arguments passed to the constructor |
2353 of the super class. |
2367 of the super class. |
2354 """ |
2368 """ |
2355 BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kwargs) |
2369 BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kwargs) |
|
2370 |
|
2371 def version_string(self): |
|
2372 """Returns server's version string used for Server HTTP header""" |
|
2373 return self.server_version |
2356 |
2374 |
2357 def do_GET(self): |
2375 def do_GET(self): |
2358 """Handle GET requests.""" |
2376 """Handle GET requests.""" |
2359 self._HandleRequest() |
2377 self._HandleRequest() |
2360 |
2378 |
2755 |
2773 |
2756 apiproxy_stub_map.apiproxy.RegisterStub( |
2774 apiproxy_stub_map.apiproxy.RegisterStub( |
2757 'memcache', |
2775 'memcache', |
2758 memcache_stub.MemcacheServiceStub()) |
2776 memcache_stub.MemcacheServiceStub()) |
2759 |
2777 |
|
2778 apiproxy_stub_map.apiproxy.RegisterStub( |
|
2779 'capability_service', |
|
2780 capability_stub.CapabilityServiceStub()) |
|
2781 |
2760 try: |
2782 try: |
2761 from google.appengine.api.images import images_stub |
2783 from google.appengine.api.images import images_stub |
2762 apiproxy_stub_map.apiproxy.RegisterStub( |
2784 apiproxy_stub_map.apiproxy.RegisterStub( |
2763 'images', |
2785 'images', |
2764 images_stub.ImagesServiceStub()) |
2786 images_stub.ImagesServiceStub()) |