Last active
September 22, 2016 05:24
-
-
Save k4zuki02h4t4/8403ac3f219b9a70dbd2bf714657d9dd to your computer and use it in GitHub Desktop.
Access restriction & Server push by mruby for H2O HTTP/2 server.
This file contains 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
class H2oServerHeader | |
def call(env) | |
path = env["PATH_INFO"] | |
method = env['REQUEST_METHOD'] | |
exclude = [ | |
"/php.ini", | |
"/readme.html", | |
"/readme-ja.html", | |
"/wp-config.php", | |
"/wp-config-sample.php", | |
"/wp-admin/install.php", | |
"/wp-admin/includes/comment.php", | |
"/wp-admin/network/menu.php", | |
"/wp-admin/user/menu.php", | |
"/wp-includes/admin-bar.php", | |
"/wp-includes/version.php" | |
] | |
if ["GET","POST","HEAD"].include? method | |
if exclude.include? path | |
return [403,{"content-type" => "text/plain;charset=utf-8"},["Forbidden.\n"]] | |
else | |
return [399,{},[]] | |
end | |
else | |
return [405,{"content-type" => "text/plain;charset=utf-8"},["Method Not Allowed.\n"]] | |
end | |
end | |
end | |
H2oServerHeader.new |
This file contains 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
class H2oServerHeader | |
def call(env) | |
path = env["PATH_INFO"] | |
method = env['REQUEST_METHOD'] | |
exclude = [ | |
"/php.ini", | |
"/readme.html", | |
"/readme-ja.html", | |
"/wp-config.php", | |
"/wp-config-sample.php", | |
"/wp-admin/install.php", | |
"/wp-admin/includes/comment.php", | |
"/wp-admin/network/menu.php", | |
"/wp-admin/user/menu.php", | |
"/wp-includes/admin-bar.php", | |
"/wp-includes/version.php" | |
] | |
push_paths = [] | |
if ["GET","POST","HEAD"].include? method | |
if exclude.include? path | |
return [403,{"content-type" => "text/plain;charset=utf-8"},["Forbidden.\n"]] | |
else | |
if /^(?!.*(wp\-admin|wp\-login)).+$/.match(path) | |
push_paths << "/wp-content/themes/kuck1u/assets/css/style.css" | |
push_paths << "/wp-content/themes/kuck1u/assets/js/script.js" | |
end | |
return [399, push_paths.empty? ? {} : {"link" => push_paths.map{|p| "<#{p}>; rel=preload"}.join("\n")}, []] | |
end | |
else | |
return [405,{"content-type" => "text/plain;charset=utf-8"},["Method Not Allowed.\n"]] | |
end | |
end | |
end | |
H2oServerHeader.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment