Skip to content

Instantly share code, notes, and snippets.

@marcy-terui
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcy-terui/05b9ea5a6ac2b023fce3 to your computer and use it in GitHub Desktop.
Save marcy-terui/05b9ea5a6ac2b023fce3 to your computer and use it in GitHub Desktop.
ISUCON4予選問題をngx_mrubyだけで解いてみた(ノウハウ編) ref: http://qiita.com/Marcy/items/1a7ab35970c31d169bf8
r = Nginx::Request.new
Nginx.echo r.args #=> "id=hoge&name=fuga"
r = Nginx::Request.new
Nginx.echo r.var.request_body #=> "login=hoge&password=fuga"
r = Nginx::Request.new
Nginx.echo r.var.http_cookie #=> "login=hoge&password=fuga"
year = Time.now.year - 1
r = Nginx::Request.new
r.headers_out['Set-Cookie'] = "notice=+; expires=Mon, 25-Nov-#{year} 11:11:11 GMT; path=/"
p Time.now.strftime("%Y-%m-%d %H:%M:%S") #=> "2014-12-05 00:11:22"
year = Time.now.year
month = Time.now.month
day = Time.now.day
hour = Time.now.hour
min = Time.now.min
sec = Time.now.sec
month = month < 10 ? "0#{month.to_s}" : month.to_s
day = day < 10 ? "0#{day.to_s}" : day.to_s
hour = hour < 10 ? "0#{hour.to_s}" : hour.to_s
min = min < 10 ? "0#{min.to_s}" : min.to_s
sec = sec < 10 ? "0#{sec.to_s}" : sec.to_s
Nginx.echo "#{year}-#{month}-#{day} #{hour}:#{min}:#{sec}" #=> "2014-12-05 00:11:22"
r = Nginx::Request.new
r.headers_out["Location"] = "http://#{r.var.http_host}/mypage"
Nginx.return Nginx::HTTP_MOVED_TEMPORARILY
v = Nginx::Var.new
v.arg_name #=> "matsumotory"
v.arg_id #=> 0
set_form_input $login;
set_form_input $password;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment