Skip to content

Commit

Permalink
Make sure that the function that checks if the content-type header
Browse files Browse the repository at this point in the history
is valid for parsing the response body
and supports when there are no content-type header information.
  • Loading branch information
GustavoCaso committed Oct 30, 2023
1 parent b84ca45 commit f869696
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/datadog/appsec/contrib/rack/gateway/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def response

def json_content_type?
content_type = headers['content-type']
VALID_JSON_TYPES.any? { |valid_type| content_type.include?(valid_type) }
VALID_JSON_TYPES.include?(content_type)
end
end
end
Expand Down
11 changes: 10 additions & 1 deletion spec/datadog/appsec/contrib/rack/gateway/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
RSpec.describe Datadog::AppSec::Contrib::Rack::Gateway::Response do
let(:body) { ['Ok'] }
let(:content_type) { 'text/html' }
let(:headers) { { 'Content-Type' => content_type } }

let(:response) do
described_class.new(
body,
200,
{ 'Content-Type' => content_type },
headers,
scope: instance_double(Datadog::AppSec::Scope)
)
end
Expand Down Expand Up @@ -93,6 +94,14 @@
end
end

context 'without content-type header' do
let(:headers) { {} }

it 'returns nil' do
expect(response.parsed_body).to be_nil
end
end

context 'with a body that is not an Array' do
let(:body) { proc { ' "ba' } }

Expand Down

0 comments on commit f869696

Please sign in to comment.