Class: Baykit::BayServer::Docker::SendFile::SendFileDocker

Inherits:
Base::ClubBase show all
Includes:
Agent, Bcf, Tours, Util
Defined in:
lib/baykit/bayserver/docker/send_file/send_file_docker.rb

Instance Attribute Summary collapse

Attributes inherited from Base::ClubBase

#charset, #decode_path_info, #extension, #file_name, #locale

Attributes inherited from Base::DockerBase

#type

Instance Method Summary collapse

Methods inherited from Base::ClubBase

#initialize, #inspect, #matches, #to_s

Methods included from Club

#charset, #decode_path_info, #extension, #file_name, #matches

Methods included from Docker

#type

Methods inherited from Base::DockerBase

#init_docker, #to_s

Constructor Details

This class inherits a constructor from Baykit::BayServer::Docker::Base::ClubBase

Instance Attribute Details

#list_filesObject (readonly)

Returns the value of attribute list_files.



19
20
21
# File 'lib/baykit/bayserver/docker/send_file/send_file_docker.rb', line 19

def list_files
  @list_files
end

Instance Method Details

#arrive(tur) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/baykit/bayserver/docker/send_file/send_file_docker.rb', line 39

def arrive(tur)
  rel_path = tur.req.rewritten_uri != nil ? tur.req.rewritten_uri : tur.req.uri
  if StringUtil.set?(tur.town.name)
    rel_path = rel_path[tur.town.name.length .. -1]
    pos = rel_path.index('?')
    if pos != nil
      rel_path = rel_path[0, pos]
    end

    begin
      rel_path = CGI.unescape(rel_path)
    rescue Encoding::CompatibilityError => e
      BayLog.warn("%s Cannot decode request path: %s (encoding=%s)", tur, rel_path, tur.req.charset)
    end

    if StringUtil.set?(tur.req.charset) && tur.req.charset != "UTF-8"
      rel_path = rel_path.force_encoding(tur.req.charset).encode("UTF-8")
    end

    real = "#{tur.town.location}/#{rel_path}"

    if File.directory?(real) && @list_files
      train = DirectoryTrain.new(tur, real)
      train.start_tour()
    else
      handler = FileContentHandler.new(real)
      tur.req.set_content_handler(handler)
    end

  end

end

#init(elm, parent) ⇒ Object

Implements DockerBase



25
26
27
# File 'lib/baykit/bayserver/docker/send_file/send_file_docker.rb', line 25

def init(elm, parent)
  super
end

#init_key_val(kv) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/baykit/bayserver/docker/send_file/send_file_docker.rb', line 29

def init_key_val(kv)
  case kv.key.downcase
  when "listfiles"
    @list_files = StringUtil.parse_bool(kv.value)
  else
    return super
  end
  return true
end