Fix HEAD response header for brid.gy
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -31,6 +31,7 @@ gem "matrix"
|
||||
|
||||
gem "rack-session"
|
||||
gem "rack-rewrite"
|
||||
gem "rack-contrib"
|
||||
|
||||
gem "ruby-readability", require: "readability"
|
||||
gem "down"
|
||||
|
@@ -331,6 +331,8 @@ GEM
|
||||
que (2.3.0)
|
||||
racc (1.7.3)
|
||||
rack (2.2.8)
|
||||
rack-contrib (2.4.0)
|
||||
rack (< 4)
|
||||
rack-rewrite (1.5.1)
|
||||
rack-session (1.0.1)
|
||||
rack (< 3)
|
||||
@@ -524,6 +526,7 @@ DEPENDENCIES
|
||||
pg
|
||||
puma
|
||||
que
|
||||
rack-contrib
|
||||
rack-rewrite
|
||||
rack-session
|
||||
rack-test
|
||||
|
@@ -22,6 +22,10 @@ module Adamantium
|
||||
handle_exception ROM::TupleCountMismatchError => :not_found
|
||||
handle_exception StandardError => :handle_error
|
||||
|
||||
config.default_headers = {
|
||||
"Content-Type" => "text/html"
|
||||
}
|
||||
|
||||
def cache(key:, content:)
|
||||
cacher.call(key: key, content: content, expiry: TimeMath.min.advance(Time.now, +10))
|
||||
end
|
||||
|
@@ -15,7 +15,14 @@ use Rack::Session::Cookie,
|
||||
require "rack/rewrite"
|
||||
use Rack::Rewrite do
|
||||
# remove trailing slashes
|
||||
# r302 %r{(/.*)/(\?.*)?$}, "$1$2"
|
||||
r302 %r{(/.*)/(\?.*)?$}, "$1$2"
|
||||
end
|
||||
|
||||
require "adamantium/middleware/header_fix"
|
||||
use Adamantium::Middleware::HeaderFix do |headers, env|
|
||||
if env["REQUEST_METHOD"] == "HEAD"
|
||||
headers['Content-Type'] = "text/html"
|
||||
end
|
||||
end
|
||||
|
||||
run Hanami.app
|
||||
|
@@ -8,7 +8,7 @@ module Adamantium
|
||||
|
||||
slice :micropub, at: "/micropub"
|
||||
|
||||
get "/", to: "site.home"
|
||||
root to: "site.home"
|
||||
get "/post/top_tracks/:slug", to: "posts.top_tracks"
|
||||
get "/post/:slug", to: "posts.show"
|
||||
get "/posts", to: "posts.index"
|
||||
|
24
lib/adamantium/middleware/header_fix.rb
Normal file
24
lib/adamantium/middleware/header_fix.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
require "rack"
|
||||
require "rack/contrib"
|
||||
|
||||
module Adamantium
|
||||
module Middleware
|
||||
class HeaderFix
|
||||
HEADERS_KLASS = Rack.release < "3" ? Rack::Utils::HeaderHash : Rack::Headers
|
||||
private_constant :HEADERS_KLASS
|
||||
|
||||
def initialize(app, &block)
|
||||
@app = app
|
||||
@block = block
|
||||
end
|
||||
|
||||
def call(env)
|
||||
response = @app.call(env)
|
||||
headers = HEADERS_KLASS.new.merge(response[1])
|
||||
@block.call(headers, env)
|
||||
response[1] = headers
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user