Skip to content

Commit

Permalink
Merge pull request #271 from bitmaybewise/lowercase-headers
Browse files Browse the repository at this point in the history
Using lowercase for HTTP headers to make it compatible with HTTP/2 and Rack v3
  • Loading branch information
Sinjo authored Dec 24, 2022
2 parents 5a04516 + 07344f9 commit d2987f1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
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

0 comments on commit d2987f1

Please sign in to comment.