class Qwik::SimpleSender
Public Class Methods
download(req, res, local_path, test=false)
click to toggle source
# File vendor/qwik/lib/qwik/common-send.rb, line 49 def self.download(req, res, local_path, test=false) local_path = local_path.path if ! local_path.exist? raise WEBrick::HTTPStatus::NotFound end st = local_path.stat res['etag'] = sprintf('%x-%x-%x', st.ino, st.size, st.mtime.to_i) if not_modified?(req, res, st.mtime) res.body = '' raise WEBrick::HTTPStatus::NotModified end res.set_content_type(local_path.ext) res['Content-Length'] = st.size res['Last-Modified'] = st.mtime.httpdate basename = local_path.basename decoded = Filename.decode(basename.to_s) # UTF-8 filename = decoded.to_page_charset res['Content-Disposition'] = "attachment; filename=\"#{filename}\"" if test res.body = local_path.read else res.body = open(local_path.to_s, 'rb') end end
fsend(config, req, res, local_path, mtype, dfilename)
click to toggle source
# File vendor/qwik/lib/qwik/common-send.rb, line 79 def self.fsend(config, req, res, local_path, mtype, dfilename) local_path = local_path.path if ! local_path.exist? raise WEBrick::HTTPStatus::NotFound end res['Content-Type'] = mtype res['Content-Disposition'] = ' attachment; filename='+dfilename res.body = local_path.read end
send(config, req, res, local_path, mtype=nil)
click to toggle source
copied from webrick
# File vendor/qwik/lib/qwik/common-send.rb, line 20 def self.send(config, req, res, local_path, mtype=nil) local_path = local_path.path if ! local_path.exist? raise WEBrick::HTTPStatus::NotFound end st = local_path.stat res['etag'] = sprintf('%x-%x-%x', st.ino, st.size, st.mtime.to_i) if not_modified?(req, res, st.mtime) res.body = '' raise WEBrick::HTTPStatus::NotModified end if mtype.nil? mtype = res.get_mimetypes(local_path.ext) # Get content type. end res['Content-Type'] = mtype res['Content-Length'] = st.size res['Last-Modified'] = st.mtime.httpdate if config.ssl || config.test # BUG: ssl can not send data as stream. res.body = local_path.read else res.body = open(local_path.to_s, 'rb') end end
Private Class Methods
not_modified?(req, res, mtime)
click to toggle source
# File vendor/qwik/lib/qwik/common-send.rb, line 91 def self.not_modified?(req, res, mtime) if ir = req['if-range'] begin return true if mtime <= ::Time.httpdate(ir) rescue if WEBrick::HTTPUtils::split_header_valie(ir).member?(res['etag']) return true end end end if (ims = req['if-modified-since']) && mtime <= ::Time.parse(ims) return true end if (inm = req['if-none-match']) && WEBrick::HTTPUtils::split_header_value(inm).member?(res['etag']) return true end return false end