Skip to content

Instantly share code, notes, and snippets.

@kyontan
Created July 19, 2017 19:11
Show Gist options
  • Save kyontan/c9f5714f3fbcd49ad13c59e9a605be27 to your computer and use it in GitHub Desktop.
Save kyontan/c9f5714f3fbcd49ad13c59e9a605be27 to your computer and use it in GitHub Desktop.
HTTP2 Server Push link header generator (Using h2o & mruby, for ictsc-score-server)
hosts:
"example.com":
listen:
port: 443
ssl:
key-file: /etc/h2o/key.pem
certificate-file: /etc/h2o/cert.pem
http2-casper: ON
reproxy: ON
paths:
"/":
mruby.handler: |
links = []
{
"css" => "style",
"js" => "script"
}.each do |ext, as|
Dir.entries("/public/static/#{ext}").each do |file|
links << "</static/#{ext}/#{file}>; rel=preload; as=#{as}" if file.end_with? ext
end
end
# $stderr.puts links
lambda do |env|
if not File.exist?("/public/" + env["PATH_INFO"])
return [307, {"x-reproxy-url" => "/"}, []]
end
return [399, { "link" => links.join("\n") }, []]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment