Skip to content

Instantly share code, notes, and snippets.

@mtourne
Created November 19, 2012 17:46
Show Gist options
  • Save mtourne/4112241 to your computer and use it in GitHub Desktop.
Save mtourne/4112241 to your computer and use it in GitHub Desktop.
Use Alternate-Protocol header to advertise SPDY to clients not using it already.
-- the nginx variable $http_x_spdy_protocol contains the value for X-SPDY-Protocol
local SPDY_REQ_HEADER_VAR='http_x_spdy_protocol'
local ALTERNATE_HEADER='Alternate-Protocol'
local ALTERNATE_VALUE='443:npn-spdy/2'
local function is_spdy_on()
local spdy_version = tonumber(ngx.var[SPDY_REQ_HEADER_VAR]) or 0
ngx.log(ngx.DEBUG, 'SPDY Version: ', spdy_version)
return spdy_version ~= 0
end
-- Use Alternate-Protocol header to advertise SPDY
function advertise()
if not is_spdy_on() then
ngx.log(ngx.DEBUG, 'Advertising SPDY')
ngx.header[ALTERNATE_HEADER] = ALTERNATE_VALUE
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment