-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Headers respond with the correct version #80
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
require 'stitches/api_key' | ||
require 'stitches/valid_mime_type' | ||
require 'stitches/response_header' | ||
|
||
module Stitches | ||
class Railtie < Rails::Railtie | ||
config.app_middleware.use Stitches::ApiKey | ||
config.app_middleware.use Stitches::ValidMimeType | ||
config.app_middleware.use Stitches::ResponseHeader | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require_relative 'allowlist_middleware' | ||
|
||
module Stitches | ||
class ResponseHeader < Stitches::AllowlistMiddleware | ||
protected | ||
def do_call(env) | ||
status, headers, body = @app.call(env) | ||
headers["Content-Type"] = env["CONTENT_TYPE"] | ||
[status, headers, body] | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Stitches | ||
VERSION = '3.7.3' | ||
VERSION = '3.8.3' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our pull request template contained some outdated instructions for updating the On a side note, the version here should be |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'spec_helper.rb' | ||
|
||
describe Stitches::ResponseHeader do | ||
let(:app) { double("rack app") } | ||
let(:headers) { {"Content-Type" => ""} } | ||
|
||
before do | ||
allow(app).to receive(:call).with(env).and_return([nil, headers, nil]) | ||
end | ||
|
||
subject(:middleware) { described_class.new(app, namespace: "/api") } | ||
|
||
describe "#call" do | ||
context "valid header" do | ||
let(:env) { | ||
{ | ||
"PATH_INFO" => "/api/ping", | ||
"HTTP_ACCEPT" => "application/json; version=99", | ||
"CONTENT_TYPE" => "application/json; version=99" | ||
} | ||
} | ||
|
||
before do | ||
@response = middleware.call(env) | ||
end | ||
it "calls through to the rest of the chain" do | ||
expect(app).to have_received(:call).with(env) | ||
end | ||
|
||
it "has the Content-Type version information" do | ||
expect(@response[1]["Content-Type"]).to eq("application/json; version=99") | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was one of our main concerns with this solution. This overwrites the response header for
Content-Type
with a value that we believe is non-standard. For example, what was returned as:Content-Type: application/json; charset=utf-8
would become
Content-Type: application/json; version=x
, overwritingcharset=utf-8
. According to RFC 7231 Section 3.1.1.5, this appears to be a non-standard value for this header.