Skip to content

Commit a48d65c

Browse files
committed
Keep headers in non-html render
1 parent 4ce85d3 commit a48d65c

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lib/plug/debugger.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,20 @@ defmodule Plug.Debugger do
206206
session = maybe_fetch_session(conn)
207207
params = maybe_fetch_query_params(conn)
208208
{title, message} = info(kind, reason)
209+
html? = accepts_html?(get_req_header(conn, "accept"))
209210

210211
assigns = [
211212
conn: conn,
212213
title: title,
213214
formatted: Exception.format(kind, reason, stack),
214215
session: session,
215216
params: params,
216-
frames: frames(:md, stack, opts)
217+
full_version: not html?
217218
]
218219

219220
markdown = template_markdown(assigns)
220221

221-
if accepts_html?(get_req_header(conn, "accept")) do
222+
if html? do
222223
conn =
223224
conn
224225
|> put_resp_content_type("text/html")

lib/plug/templates/debugger.md.eex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Exception:
1515
* URI: <%= url(@conn) %>
1616
* Query string: <%= @conn.query_string %>
1717

18-
### Session
18+
<%= if @full_version do %>### Headers
19+
<%= for {key, value} <- Enum.sort(@conn.req_headers) do %>
20+
* <%= key %>: <%= value %><% end %>
21+
22+
<% end %>### Session
1923

2024
<%= inspect(@session) %>

test/plug/debugger_test.exs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ defmodule Plug.DebuggerTest do
316316
|> render([], fn -> raise "oops" end)
317317

318318
assert conn.resp_body =~ "Copy markdown"
319+
320+
# Does not include Headers in markdown though
321+
refute conn.resp_body =~ "Code:"
322+
refute conn.resp_body =~ "### Headers"
319323
end
320324

321325
defp stack(stack) do
@@ -395,7 +399,6 @@ defmodule Plug.DebuggerTest do
395399
end)
396400

397401
assert get_resp_header(conn, "content-type") == ["text/markdown; charset=utf-8"]
398-
399402
assert get_resp_header(conn, "content-security-policy") == ["abcdef"]
400403

401404
assert conn.resp_body =~ "# Plug.Parsers.UnsupportedMediaTypeError at GET /"

0 commit comments

Comments
 (0)