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

#file_storeObject (readonly)

Returns the value of attribute file_store.



21
22
23
# File 'lib/baykit/bayserver/docker/send_file/send_file_docker.rb', line 21

def file_store
  @file_store
end

#list_filesObject (readonly)

Returns the value of attribute list_files.



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

def list_files
  @list_files
end

Instance Method Details

#arrive(tur) ⇒ Object



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
71
72
73
74
75
76
77
78
# File 'lib/baykit/bayserver/docker/send_file/send_file_docker.rb', line 41

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)
      if @list_files
        train = DirectoryTrain.new(tur, real)
        train.start_tour()
      else
        raise HttpException.new(HttpStatus::FORBIDDEN, "Directory scan is prohibited")
      end
    else
      if BayServer.harbor.enable_cache() && @file_store == nil
        @file_store = FileStore.new(BayServer.harbor.cache_lifespan_sec, BayServer.harbor.cache_size_mb * 1024 * 1024)
      end
      handler = FileContentHandler.new(tur, @file_store, real, tur.res.charset)
      tur.req.set_content_handler(handler)
    end
  end

end

#init(elm, parent) ⇒ Object

Implements DockerBase



27
28
29
# File 'lib/baykit/bayserver/docker/send_file/send_file_docker.rb', line 27

def init(elm, parent)
  super
end

#init_key_val(kv) ⇒ Object



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

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