Skip to content

Commit

Permalink
Add spec for when format could not be determined
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcsmith committed Sep 12, 2019
1 parent 7d03209 commit 59b9d75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion spec/lucky/mime_type_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ describe Lucky::MimeType do
format.should eq(:json)
end

it "returns the 'default_format' if the accept header accepts anything '*/*'" do
it "returns 'nil' if there is a non-browser 'Accept' header, but Lucky doesn't understand it" do
format = determine_format("accept": "wut/is-this")
format.should be_nil
end

it "returns the 'default_format' if the 'Accept' header accepts anything '*/*'" do
format = determine_format(default_format: :csv, "accept": "*/*")
format.should eq(:csv)
end
Expand Down
7 changes: 4 additions & 3 deletions src/lucky/mime_type.cr
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ class Lucky::MimeType
end
end

# Browser typically send */* in their accept header
# This method checks for that so we can figure out if a browser is
# making the request.
# This checks if the "Accept" header is from a browser. Browsers typically
# include "*/*" along with other characters in the request's "Accept" header.
# This method handles those intricacies and determins if the header is from
# a browser.
private def default_accept_header_that_browsers_send? : Bool
accept = accept_header

Expand Down

0 comments on commit 59b9d75

Please sign in to comment.