CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 12:31:33 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"965c25d6abd8dbd4011641a974b8c7d2"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com github.githubassets.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com wss://alive-staging.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com marketplace-screenshots.githubusercontent.com/ copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=t0UUNvRlTUFtjN%2B3l9de69tP7CqtJrkw8TZiyraTyzJ2nh%2BAtC6hoPWQ0R3QVY4tIqDSff%2FquAJjkam4FF%2BocGTWgG4gdzLCIWMmqzyRISUVrgKh%2BYueh91LAAM7ivU40wBv3%2BpID2Iqbz7e7WahFQ4UVBYBTrCiMgcZa4vAKfTiynykbo%2FpgmJU2kx9Ex6P90ZiguI79pPWXZIPM%2FlF6fVoGs98JlzaUrJc7ewnkaJQC2WECvQwEtfHs97sA1v4GfWDAoTShvQYk8X0BRwTBg%3D%3D--Kpf%2BBOAmWt1RenPS--4%2FfSnt2zbnIqMOmmOCwD0Q%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1586795034.1760185892; Path=/; Domain=github.com; Expires=Sun, 11 Oct 2026 12:31:32 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Sun, 11 Oct 2026 12:31:32 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: A9D0:9DC1D:69436A:8C169F:68EA4E24
base64-preview-prompt.txt · GitHub
Show Gist options
Save simonw/b2cfff8281d5681c30e54083a9882141 to your computer and use it in GitHub Desktop.
{{ message }}
Instantly share code, notes, and snippets.
simonw/base64-preview-prompt.txt Secret
Created
August 8, 2024 14:56
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save simonw/b2cfff8281d5681c30e54083a9882141 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import filetype | |
from datasette import hookimpl | |
from markupsafe import escape, Markup | |
sequence_re = re.compile(r"((?:\\x[0-9a-f]{2})+)") | |
octet_re = re.compile(r"(\\x[0-9a-f]{2})") | |
@hookimpl(trylast=True) | |
def render_cell(value): | |
if not isinstance(value, bytes): | |
return None | |
# Attempt to guess filetype | |
suggestion = None | |
match = filetype.guess(value[:1000]) | |
if match: | |
suggestion = "{} ({})".format(match.extension, match.mime) | |
encoded = repr(value) | |
# Ditch the b' and trailing ' | |
if encoded.startswith("b'") and encoded.endswith("'"): | |
encoded = encoded[2:-1] | |
# Split it into sequences of octets and characters | |
chunks = sequence_re.split(encoded) | |
html = [] | |
if suggestion: | |
html.append( | |
'<p style="margin-top: 0; font-family: monospace; font-size: 0.8em;">Suggestion: {}</p>'.format( | |
escape(suggestion) | |
) | |
) | |
for chunk in chunks: | |
if sequence_re.match(chunk): | |
octets = octet_re.findall(chunk) | |
octets = [o[2:] for o in octets] | |
html.append( | |
'<code style="color: #999; font-family: monospace">{}</code>'.format( | |
" ".join(octets).upper() | |
) | |
) | |
else: | |
html.append(escape(chunk.replace("\\\\", "\\"))) | |
return Markup(" ".join(html).strip()) | |
With that code as inspiration, modify the following Django Admin code to use that to display decoded base64 data: | |
@admin.register(RequestLog) | |
class RequestLogAdmin(admin.ModelAdmin): | |
list_display = ("endpoint", "method", "timestamp", "body_preview", "is_base64") | |
list_filter = ("endpoint", "method", "is_base64") | |
readonly_fields = ( | |
"endpoint", | |
"method", | |
"headers", | |
"body_display", | |
"is_base64", | |
"timestamp", | |
) | |
search_fields = ("endpoint__path",) | |
def has_add_permission(self, request): | |
return False | |
def has_change_permission(self, request, obj=None): | |
return False | |
def body_preview(self, obj): | |
body = obj.get_body() | |
if isinstance(body, bytes): | |
return f"Binary data ({len(body)} bytes)" | |
return body[:50] + ("..." if len(body) > 50 else "") | |
def body_display(self, obj): | |
body = obj.get_body() | |
if isinstance(body, bytes): | |
return format_html("<pre>Binary data ({} bytes)</pre>", len(body)) | |
return format_html("<pre>{}</pre>", body) | |
body_display.short_description = "Body" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can’t perform that action at this time.