Created
July 19, 2017 19:11
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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