Skip to content

Commit

Permalink
Set Vary: Accept header when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija committed Mar 21, 2024
1 parent 37ae0b2 commit acfa975
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/gphoto2/web/routes.cr
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ get "/cameras/:id/blob/*filepath" do |env|
fs = camera / path.dirname
file = fs.open(path.basename)

env.response.headers["Vary"] = "Accept"

if request_accepts_json?(env.request)
send_json env, file
else
Expand Down Expand Up @@ -209,6 +211,8 @@ end
# Error pages

error 404 do |env|
env.response.headers["Vary"] = "Accept"

if request_accepts_json?(env.request)
send_json env, {error: "Not found"}
else
Expand All @@ -223,6 +227,8 @@ error 500 do |env, err|
env.response.status = :internal_server_error
end

env.response.headers["Vary"] = "Accept"

if request_accepts_json?(env.request)
send_json env, {error: err.to_s}
else
Expand Down

0 comments on commit acfa975

Please sign in to comment.