Skip to content

Commit

Permalink
Handle case if no user agent is set
Browse files Browse the repository at this point in the history
  • Loading branch information
treagod committed Aug 5, 2024
1 parent 33848d2 commit b50d490
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions spec/marten-turbo/ext/marten/http/request_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,15 @@ describe Marten::HTTP::Request do

request.turbo_native_app?.should be_true
end

it "correctly returns false if the request headers do not contain a user agent" do
request = Marten::HTTP::Request.new(
method: "GET",
resource: "/test/xyz",
headers: HTTP::Headers{"Accept" => "text/html"},
)

request.turbo_native_app?.should be_false
end
end
end
3 changes: 2 additions & 1 deletion src/marten_turbo/ext/marten/http/request.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Marten::HTTP::Request

def turbo_native_app?
user_agent = @request.headers["User-Agent"]?
user_agent.includes?("Turbo Native") if user_agent

user_agent ? user_agent.includes?("Turbo Native") : false
end
end

0 comments on commit b50d490

Please sign in to comment.