Skip to content
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

Using lowercase for HTTP headers to make it compatible with HTTP/2 and Rack v3 #271

Merged
merged 1 commit into from
Dec 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ use Rack::Deflater
use Prometheus::Middleware::Collector
use Prometheus::Middleware::Exporter

run ->(_) { [200, {'Content-Type' => 'text/html'}, ['OK']] }
run ->(_) { [200, {'content-type' => 'text/html'}, ['OK']] }
```

Start the server and have a look at the metrics endpoint:
Expand Down
4 changes: 2 additions & 2 deletions lib/prometheus/middleware/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def extract_quality(attributes, default = 1.0)
def respond_with(format)
[
200,
{ 'Content-Type' => format::CONTENT_TYPE },
{ 'content-type' => format::CONTENT_TYPE },
[format.marshal(@registry)],
]
end
Expand All @@ -76,7 +76,7 @@ def not_acceptable(formats)

[
406,
{ 'Content-Type' => 'text/plain' },
{ 'content-type' => 'text/plain' },
["Supported media types: #{types.join(', ')}"],
]
end
Expand Down
4 changes: 2 additions & 2 deletions spec/prometheus/middleware/collector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
end

let(:original_app) do
->(_) { [200, { 'Content-Type' => 'text/html' }, ['OK']] }
->(_) { [200, { 'content-type' => 'text/html' }, ['OK']] }
end

let!(:app) do
Expand Down Expand Up @@ -128,7 +128,7 @@
lambda do |env|
raise dummy_error if env['PATH_INFO'] == '/broken'

[200, { 'Content-Type' => 'text/html' }, ['OK']]
[200, { 'content-type' => 'text/html' }, ['OK']]
end
end

Expand Down
10 changes: 5 additions & 5 deletions spec/prometheus/middleware/exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

let(:app) do
app = ->(_) { [200, { 'Content-Type' => 'text/html' }, ['OK']] }
app = ->(_) { [200, { 'content-type' => 'text/html' }, ['OK']] }
described_class.new(app, **options)
end

Expand All @@ -29,13 +29,13 @@
text = Prometheus::Client::Formats::Text

shared_examples 'ok' do |headers, fmt|
it "responds with 200 OK and Content-Type #{fmt::CONTENT_TYPE}" do
it "responds with 200 OK and content-type #{fmt::CONTENT_TYPE}" do
registry.counter(:foo, docstring: 'foo counter').increment(by: 9)

get '/metrics', nil, headers

expect(last_response.status).to eql(200)
expect(last_response.header['Content-Type']).to eql(fmt::CONTENT_TYPE)
expect(last_response.header['content-type']).to eql(fmt::CONTENT_TYPE)
expect(last_response.body).to eql(fmt.marshal(registry))
end
end
Expand All @@ -47,7 +47,7 @@
get '/metrics', nil, headers

expect(last_response.status).to eql(406)
expect(last_response.header['Content-Type']).to eql('text/plain')
expect(last_response.header['content-type']).to eql('text/plain')
expect(last_response.body).to eql(message)
end
end
Expand Down Expand Up @@ -108,7 +108,7 @@
get 'http://example.org:9999/metrics', nil, {}

expect(last_response.status).to eql(200)
expect(last_response.header['Content-Type']).to eql(text::CONTENT_TYPE)
expect(last_response.header['content-type']).to eql(text::CONTENT_TYPE)
expect(last_response.body).to eql(text.marshal(registry))
end
end
Expand Down