Skip to content

Instantly share code, notes, and snippets.

@klingerf
Last active March 8, 2017 00:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klingerf/6365bec92a24e6f6a77e78ecb3a7220a to your computer and use it in GitHub Desktop.
Save klingerf/6365bec92a24e6f6a77e78ecb3a7220a to your computer and use it in GitHub Desktop.
sinatra extension to forward linkerd headers with activeresource requests
require 'sinatra/extension'
require 'active_resource'
module L5D
extend Sinatra::Extension
class << self
attr_accessor :headers
end
before do
L5D.headers = {}
request.env.each do |key, value|
if key =~ /^HTTP_(L5D_CTX.*)$/
header = $1.split('_').map(&:capitalize).join("-")
L5D.headers[header] = value
end
end
end
end
register L5D
module ActiveResource
class Base
cattr_accessor :static_headers
self.static_headers = self.headers
def self.headers
static_headers.merge(L5D.headers)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment