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

Capture surrogate keys and pass them to a front-end application. #70

Merged
merged 5 commits into from
Jul 22, 2016

Conversation

ehibun
Copy link
Contributor

@ehibun ehibun commented Jul 22, 2016

This PR introduces a middleware to capture Fastly surrogate keys, as supplied to the server, and store them for passing onto a client. We use this so that we can output Matalan pages with these surrogate keys to assist in Fastly caching, as described in https://github.com/shiftcommerce/matalan-rails-site/issues/633.

@@ -76,6 +77,12 @@ def path(params = nil, record = nil)
super(params)
end

def capture_surrogate_keys
Thread.current[:shift_surrogate_keys] = nil
Copy link
Contributor

@garytaylor garytaylor Jul 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be

Thread.current[:shift_surrogate_keys] = []
yield
results = Thread.current[:shift_surrogate_keys].uniq.join(' ')
Thread.current[:shift_surrogate_keys = nil)
results

@@ -7,10 +7,8 @@ def call(environment)
surrogate_keys = env.response_headers['external-surrogate-key'].split(' ') if env.response_headers['external-surrogate-key']

if surrogate_keys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have an unless inside an if here which could be tidied up

@ehibun ehibun merged commit 49152d3 into master Jul 22, 2016
@praweb praweb deleted the feature/capture_surrogate_keys branch August 9, 2018 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants