⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 16 - setting cookies and other http response headers.rb

📁 O Reilly Ruby Cookbook source code
💻 RB
字号:
#!/usr/bin/ruby# headers.cgirequire "cgi"cgi = CGI.new("html3")# Retrieve or create the "rubycookbook" cookiecookie = cgi.cookies['rubycookbook']cookie = CGI::Cookie.new('rubycookbook', 'hits=0',                          "last=#{Time.now}") if cookie.empty?# Read the values in the cookie for future usehits = cookie.value[0].split('=')[1]last = cookie.value[1].split('=')[1]# Set new values in the cookiecookie.value[0] = "hits=#{hits.succ}"cookie.value[1] = "last=#{Time.now}"#---# Create a hash of HTTP response headers.header = { 'status'      => 'OK',           'cookie'      => [cookie],           'Refresh'     => 2,           'Recipe Name' => 'Setting HTTP Response Headers',           'server'      => ENV['SERVER_SOFTWARE']  }cgi.out(header) do  cgi.html('PRETTY' => '  ') do    cgi.head { cgi.title { 'Setting HTTP Response Headers' } } +    cgi.body do      cgi.p('Your headers:') +      cgi.pre{ cgi.header(header) } +      cgi.pre do        "Number of times your browser hit this cgi: #{hits}\n"+        "Last connected: #{last}"      end    end endend#---

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -