| Index: appengine/isolate/handlers_frontend.py
|
| diff --git a/appengine/isolate/handlers_frontend.py b/appengine/isolate/handlers_frontend.py
|
| index 745a07c58345bcf8b077d4e596111a37cef234d9..c20dec5698cb5b056234f207a441ef92b5e2d421 100644
|
| --- a/appengine/isolate/handlers_frontend.py
|
| +++ b/appengine/isolate/handlers_frontend.py
|
| @@ -6,11 +6,13 @@
|
|
|
| import datetime
|
| import json
|
| +import logging
|
| import re
|
|
|
| import webapp2
|
|
|
| from google.appengine.api import memcache
|
| +from google.appengine.api import modules
|
| from google.appengine.api import users
|
|
|
| import acl
|
| @@ -229,33 +231,50 @@ class ContentHandler(auth.AuthenticatingHandler):
|
| # We delete Content-Type before storing to it to avoid having two (yes,
|
| # two) Content-Type headers.
|
| del self.response.headers['Content-Type']
|
| +
|
| # Apparently, setting the content type to text/plain encourages the
|
| # browser (Chrome, at least) to sniff the mime type and display
|
| # things like images. Images are autowrapped in <img> and text is
|
| # wrapped in <pre>.
|
| self.response.headers['Content-Type'] = 'text/plain; charset=utf-8'
|
| - self.response.headers['Content-Disposition'] = str('filename=%s' % digest)
|
| - if content.startswith('{'):
|
| - # Try to format as JSON.
|
| - try:
|
| - content = json.dumps(
|
| - json.loads(content), sort_keys=True, indent=2,
|
| - separators=(',', ': '))
|
| - # If we don't wrap this in html, browsers will put content in a pre
|
| - # tag which is also styled with monospace/pre-wrap. We can't use
|
| - # anchor tags in <pre>, so we force it to be a <div>, which happily
|
| - # accepts links.
|
| - content = (
|
| - '<div style="font-family:monospace;white-space:pre-wrap;">%s</div>'
|
| - % content)
|
| - # Linkify things that look like hashes
|
| - content = re.sub(r'([0-9a-f]{40})',
|
| - r'<a target="_blank" href="/browse?namespace=%s' % namespace +
|
| - r'&digest=\1">\1</a>',
|
| - content)
|
| - self.response.headers['Content-Type'] = 'text/html; charset=utf-8'
|
| - except ValueError:
|
| - pass
|
| +
|
| + # App Engine puts a limit of 33554432 bytes on a request, which includes
|
| + # headers. Headers are ~150 bytes. If the content + headers might
|
| + # exceed that limit, we give the user an option to workround getting
|
| + # their file.
|
| + if len(content) > 33554000:
|
| + host = modules.get_hostname(module='default', version='default')
|
| + # host is something like default.default.myisolateserver.appspot.com
|
| + host = host.replace('default.default.','')
|
| + sizeInMib = len(content) / (1024.0 * 1024.0)
|
| + content = ('Sorry, your file is %1.1f MiB big, which exceeds the 32 MiB'
|
| + ' App Engine limit.\nTo work around this, run the following command:\n'
|
| + ' python isolateserver.py download -I %s --namespace %s -f %s %s'
|
| + % (sizeInMib, host, namespace, digest, digest))
|
| + else:
|
| + self.response.headers['Content-Disposition'] = str('filename=%s'
|
| + % digest)
|
| + if content.startswith('{'):
|
| + # Try to format as JSON.
|
| + try:
|
| + content = json.dumps(
|
| + json.loads(content), sort_keys=True, indent=2,
|
| + separators=(',', ': '))
|
| + # If we don't wrap this in html, browsers will put content in a pre
|
| + # tag which is also styled with monospace/pre-wrap. We can't use
|
| + # anchor tags in <pre>, so we force it to be a <div>, which happily
|
| + # accepts links.
|
| + content = (
|
| + '<div style="font-family:monospace;white-space:pre-wrap;">%s'
|
| + '</div>' % content)
|
| + # Linkify things that look like hashes
|
| + content = re.sub(r'([0-9a-f]{40})',
|
| + r'<a target="_blank" href="/browse?namespace=%s' % namespace +
|
| + r'&digest=\1">\1</a>',
|
| + content)
|
| + self.response.headers['Content-Type'] = 'text/html; charset=utf-8'
|
| + except ValueError:
|
| + pass
|
|
|
| self.response.write(content)
|
|
|
|
|