public
Last active

Use Alternate-Protocol header to advertise SPDY to clients not using it already.

  • Download Gist
spdy_alternate_protocol.lua
Lua
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
-- 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.