Skip to content
Snippets Groups Projects
Commit c08c734e authored by Antoine Lambert's avatar Antoine Lambert
Browse files

config: Add maximum content size for source code highlighting

parent ab83b47f
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@ from swh.web.common.exc import NotFoundExc
from swh.web.common.utils import (
reverse, format_utc_iso_date, parse_timestamp
)
from swh.web.config import get_config
def get_directory_entries(sha1_git):
......@@ -88,7 +89,7 @@ def get_mimetype_and_encoding_for_content(content):
# maximum authorized content size in bytes for HTML display
# with code highlighting
content_display_max_size = 1000000
content_display_max_size = get_config()['content_display_max_size']
def request_content(query_string, max_size=content_display_max_size):
......
......@@ -29,6 +29,8 @@ DEFAULT_CONFIG = {
'host': ('string', '127.0.0.1'),
'port': ('int', 5004),
'secret_key': ('string', 'development key'),
# do not display code highlighting for content > 1MB
'content_display_max_size': ('int', 1024 * 1024),
'throttling': ('dict', {
'cache_uri': None, # production: memcached as cache (127.0.0.1:11211)
# development: in-memory cache so None
......
<div class="well well-sm swh-content" style="margin-bottom: 0px">
{% if content_size > max_content_size %}
Content is too large to be displayed.
Content is too large to be displayed (size is greater than {{ max_content_size|filesizeformat }}).
{% elif "inode/x-empty" == mimetype %}
<i>File is empty</i>
{% elif "text/" in mimetype %}
......
......@@ -262,5 +262,5 @@ class SwhBrowseContentTest(SWHWebTestBase, TestCase):
self.assertEquals(resp.status_code, 200)
self.assertTemplateUsed('content.html')
self.assertContains(resp, 'Content is too large to be displayed.')
self.assertContains(resp, 'Content is too large to be displayed')
self.assertContains(resp, url_raw)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment