bayserver-core 2.3.2 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/lib/baykit/bayserver/agent/accept_handler.rb +0 -26
  3. data/lib/baykit/bayserver/agent/channel_listener.rb +6 -6
  4. data/lib/baykit/bayserver/agent/command_receiver.rb +97 -38
  5. data/lib/baykit/bayserver/agent/grand_agent.rb +444 -134
  6. data/lib/baykit/bayserver/agent/letter.rb +30 -0
  7. data/lib/baykit/bayserver/agent/lifecycle_listener.rb +9 -7
  8. data/lib/baykit/bayserver/agent/monitor/grand_agent_monitor.rb +298 -0
  9. data/lib/baykit/bayserver/agent/multiplexer/job_multiplexer.rb +257 -0
  10. data/lib/baykit/bayserver/agent/multiplexer/job_multiplexer_base.rb +52 -0
  11. data/lib/baykit/bayserver/agent/multiplexer/multiplexer_base.rb +150 -0
  12. data/lib/baykit/bayserver/agent/multiplexer/plain_transporter.rb +129 -0
  13. data/lib/baykit/bayserver/agent/multiplexer/rudder_state.rb +81 -0
  14. data/lib/baykit/bayserver/agent/multiplexer/secure_transporter.rb +50 -0
  15. data/lib/baykit/bayserver/agent/multiplexer/spider_multiplexer.rb +561 -0
  16. data/lib/baykit/bayserver/agent/multiplexer/spin_multiplexer.rb +311 -0
  17. data/lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb +194 -0
  18. data/lib/baykit/bayserver/agent/multiplexer/transporter.rb +61 -0
  19. data/lib/baykit/bayserver/agent/multiplexer/write_unit.rb +30 -0
  20. data/lib/baykit/bayserver/agent/non_blocking_handler.rb +0 -319
  21. data/lib/baykit/bayserver/agent/signal/signal_agent.rb +2 -1
  22. data/lib/baykit/bayserver/agent/timer_handler.rb +1 -1
  23. data/lib/baykit/bayserver/agent/transporter/data_listener.rb +7 -7
  24. data/lib/baykit/bayserver/agent/transporter/package.rb +0 -3
  25. data/lib/baykit/bayserver/agent/transporter/transporter.rb +5 -139
  26. data/lib/baykit/bayserver/bay_log.rb +1 -0
  27. data/lib/baykit/bayserver/bayserver.rb +32 -28
  28. data/lib/baykit/bayserver/{util → common}/groups.rb +1 -1
  29. data/lib/baykit/bayserver/common/inbound_handler.rb +12 -0
  30. data/lib/baykit/bayserver/{docker/base → common}/inbound_ship.rb +94 -19
  31. data/lib/baykit/bayserver/{docker/base → common}/inbound_ship_store.rb +7 -9
  32. data/lib/baykit/bayserver/common/multiplexer.rb +98 -0
  33. data/lib/baykit/bayserver/common/postpone.rb +15 -0
  34. data/lib/baykit/bayserver/common/read_only_ship.rb +42 -0
  35. data/lib/baykit/bayserver/common/recipient.rb +24 -0
  36. data/lib/baykit/bayserver/common/vehicle.rb +24 -0
  37. data/lib/baykit/bayserver/common/vehicle_runner.rb +127 -0
  38. data/lib/baykit/bayserver/{docker/warp → common}/warp_data.rb +18 -10
  39. data/lib/baykit/bayserver/common/warp_handler.rb +27 -0
  40. data/lib/baykit/bayserver/{docker/warp → common}/warp_ship.rb +107 -27
  41. data/lib/baykit/bayserver/{docker/warp → common}/warp_ship_store.rb +3 -8
  42. data/lib/baykit/bayserver/docker/base/inbound_data_listener.rb +2 -2
  43. data/lib/baykit/bayserver/docker/base/port_base.rb +59 -27
  44. data/lib/baykit/bayserver/docker/{warp/warp_docker.rb → base/warp_base.rb} +43 -50
  45. data/lib/baykit/bayserver/docker/built_in/built_in_harbor_docker.rb +118 -31
  46. data/lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb +60 -63
  47. data/lib/baykit/bayserver/docker/built_in/built_in_permission_docker.rb +11 -10
  48. data/lib/baykit/bayserver/docker/built_in/built_in_secure_docker.rb +13 -4
  49. data/lib/baykit/bayserver/docker/city.rb +27 -13
  50. data/lib/baykit/bayserver/docker/club.rb +8 -8
  51. data/lib/baykit/bayserver/docker/docker.rb +9 -1
  52. data/lib/baykit/bayserver/docker/harbor.rb +184 -22
  53. data/lib/baykit/bayserver/docker/permission.rb +7 -6
  54. data/lib/baykit/bayserver/docker/port.rb +39 -11
  55. data/lib/baykit/bayserver/docker/secure.rb +11 -9
  56. data/lib/baykit/bayserver/docker/send_file/file_content_handler.rb +99 -4
  57. data/lib/baykit/bayserver/docker/send_file/send_file_docker.rb +6 -2
  58. data/lib/baykit/bayserver/docker/send_file/send_file_ship.rb +92 -0
  59. data/lib/baykit/bayserver/docker/town.rb +31 -15
  60. data/lib/baykit/bayserver/docker/trouble.rb +17 -5
  61. data/lib/baykit/bayserver/docker/warp.rb +34 -0
  62. data/lib/baykit/bayserver/mem_usage.rb +9 -9
  63. data/lib/baykit/bayserver/protocol/command_packer.rb +1 -8
  64. data/lib/baykit/bayserver/protocol/packet_packer.rb +7 -11
  65. data/lib/baykit/bayserver/protocol/packet_store.rb +4 -4
  66. data/lib/baykit/bayserver/protocol/protocol_handler.rb +26 -8
  67. data/lib/baykit/bayserver/protocol/protocol_handler_store.rb +5 -5
  68. data/lib/baykit/bayserver/rudders/io_rudder.rb +62 -0
  69. data/lib/baykit/bayserver/rudders/rudder.rb +29 -0
  70. data/lib/baykit/bayserver/{watercraft → ships}/ship.rb +65 -41
  71. data/lib/baykit/bayserver/taxi/taxi.rb +15 -10
  72. data/lib/baykit/bayserver/taxi/taxi_runner.rb +9 -94
  73. data/lib/baykit/bayserver/tours/read_file_taxi.rb +2 -2
  74. data/lib/baykit/bayserver/tours/req_content_handler.rb +16 -13
  75. data/lib/baykit/bayserver/tours/tour.rb +2 -2
  76. data/lib/baykit/bayserver/tours/tour_handler.rb +36 -0
  77. data/lib/baykit/bayserver/tours/tour_req.rb +14 -24
  78. data/lib/baykit/bayserver/tours/tour_res.rb +5 -89
  79. data/lib/baykit/bayserver/tours/tour_store.rb +5 -5
  80. data/lib/baykit/bayserver/train/train_runner.rb +17 -13
  81. data/lib/baykit/bayserver/util/data_consume_listener.rb +1 -1
  82. data/lib/baykit/bayserver/util/executor_service.rb +11 -7
  83. data/lib/baykit/bayserver/util/ip_matcher.rb +9 -39
  84. data/lib/baykit/bayserver/util/locale.rb +1 -1
  85. data/lib/baykit/bayserver/util/selector.rb +24 -5
  86. data/lib/baykit/bayserver/util/sys_util.rb +6 -6
  87. data/lib/baykit/bayserver/version.rb +1 -1
  88. metadata +37 -18
  89. data/lib/baykit/bayserver/agent/grand_agent_monitor.rb +0 -231
  90. data/lib/baykit/bayserver/agent/transporter/plain_transporter.rb +0 -55
  91. data/lib/baykit/bayserver/agent/transporter/secure_transporter.rb +0 -81
  92. data/lib/baykit/bayserver/docker/base/inbound_handler.rb +0 -42
  93. data/lib/baykit/bayserver/docker/warp/package.rb +0 -4
  94. data/lib/baykit/bayserver/docker/warp/warp_data_listener.rb +0 -112
  95. data/lib/baykit/bayserver/docker/warp/warp_handler.rb +0 -38
  96. /data/lib/baykit/bayserver/{util → common}/cities.rb +0 -0
@@ -1,7 +1,8 @@
1
1
  require 'openssl'
2
2
 
3
3
  require 'baykit/bayserver/bcf/package'
4
- require 'baykit/bayserver/agent/transporter/secure_transporter'
4
+ require 'baykit/bayserver/agent/grand_agent'
5
+ require 'baykit/bayserver/agent/multiplexer/secure_transporter'
5
6
 
6
7
  require 'baykit/bayserver/docker/secure'
7
8
  require 'baykit/bayserver/util/string_util'
@@ -14,7 +15,8 @@ module Baykit
14
15
  include Baykit::BayServer::Docker::Secure # implements
15
16
 
16
17
  include Baykit::BayServer::Bcf
17
- include Baykit::BayServer::Agent::Transporter
18
+ include Baykit::BayServer::Agent
19
+ include Baykit::BayServer::Agent::Multiplexer
18
20
  include Baykit::BayServer::Util
19
21
  include OpenSSL
20
22
 
@@ -109,8 +111,15 @@ module Baykit
109
111
  end
110
112
  end
111
113
 
112
- def create_transporter(buf_size)
113
- SecureTransporter.new(@sslctx, true, buf_size, @trace_ssl)
114
+ def new_transporter(agt_id, sip, buf_size)
115
+ agt = GrandAgent.get(agt_id)
116
+ return SecureTransporter.new(
117
+ agt.net_multiplexer,
118
+ sip,
119
+ true,
120
+ buf_size,
121
+ @trace_ssl,
122
+ @sslctx)
114
123
  end
115
124
 
116
125
  def reload_cert()
@@ -3,19 +3,33 @@ require 'baykit/bayserver/docker/docker'
3
3
  module Baykit
4
4
  module BayServer
5
5
  module Docker
6
- module City
7
- include Baykit::BayServer::Docker::Docker
8
-
9
- #
10
- # interface
11
- #
12
- # String name();
13
- # List<Club> clubs();
14
- # List<Town> towns();
15
- # void enter(Tour tour) throws HttpException;
16
- # Trouble getTrouble();
17
- # void log(Tour tour);
18
- #
6
+ module City # interface
7
+ include Baykit::BayServer::Docker::Docker # implements
8
+
9
+ def name
10
+ raise NotImplementedError.new
11
+ end
12
+
13
+ def clubs
14
+ raise NotImplementedError.new
15
+ end
16
+
17
+ def towns
18
+ raise NotImplementedError.new
19
+ end
20
+
21
+ def enter(tur)
22
+ raise NotImplementedError.new
23
+ end
24
+
25
+ def get_trouble
26
+ raise NotImplementedError.new
27
+ end
28
+
29
+ def log(tur)
30
+ raise NotImplementedError.new
31
+ end
32
+
19
33
  end
20
34
  end
21
35
  end
@@ -11,32 +11,32 @@ module Baykit
11
11
 
12
12
  # Get the file name part of club
13
13
  def file_name()
14
- raise NotImplementedError.new()
14
+ raise NotImplementedError.new
15
15
  end
16
16
 
17
17
  # Get the ext (file extension part) of club
18
18
  def extension()
19
- raise NotImplementedError.new()
19
+ raise NotImplementedError.new
20
20
  end
21
21
 
22
22
  # Check if file name matches this club
23
23
  def matches(fname)
24
- raise NotImplementedError.new()
24
+ raise NotImplementedError.new
25
25
  end
26
26
 
27
27
  # Get charset of club
28
- def charset()
29
- raise NotImplementedError.new()
28
+ def charset
29
+ raise NotImplementedError.new
30
30
  end
31
31
 
32
32
  # Check if this club decodes PATH_INFO
33
- def decode_path_info()
34
- raise NotImplementedError.new()
33
+ def decode_path_info
34
+ raise NotImplementedError.new
35
35
  end
36
36
 
37
37
  # Arrive
38
38
  def arrive(tur)
39
- raise NotImplementedError.new()
39
+ raise NotImplementedError.new
40
40
  end
41
41
 
42
42
  end
@@ -1,7 +1,15 @@
1
1
  module Baykit
2
2
  module BayServer
3
3
  module Docker
4
- module Docker
4
+ module Docker # interface
5
+
6
+ def init(ini, parent)
7
+ raise NotImplementedError.new
8
+ end
9
+
10
+ def type()
11
+ raise NotImplementedError.new
12
+ end
5
13
  end
6
14
  end
7
15
  end
@@ -6,28 +6,190 @@ module Baykit
6
6
  module Harbor
7
7
  include Docker
8
8
 
9
- FILE_SEND_METHOD_SELECT = 1
10
- FILE_SEND_METHOD_SPIN = 2
11
- FILE_SEND_METHOD_TAXI = 3
12
-
13
- #
14
- # interface
15
- #
16
- # String charset();
17
- # Locale locale();
18
- # int shipAgents();
19
- # int trainRunners();
20
- # int maxShips();
21
- # Trouble getTrouble();
22
- # int socketTimeoutSec();
23
- # int keepTimeoutSec();
24
- # boolean traceHeader();
25
- # int tourBufferSize();
26
- # String redirectFile();
27
- # int bayPort();
28
- # boolean gzipComp();
29
- # AsyncFileMethod asyncFileMethod();
30
- #
9
+ MULTIPLEXER_TYPE_SPIDER = 1
10
+ MULTIPLEXER_TYPE_SPIN = 2
11
+ MULTIPLEXER_TYPE_PIGEON = 3
12
+ MULTIPLEXER_TYPE_JOB = 4
13
+ MULTIPLEXER_TYPE_TAXI = 5
14
+ MULTIPLEXER_TYPE_TRAIN = 6
15
+
16
+ RECIPIENT_TYPE_SPIDER = 1
17
+ RECIPIENT_TYPE_PIPE = 2
18
+
19
+ # Default charset
20
+ def charset
21
+ raise NotImplementedError.new
22
+ end
23
+
24
+ # Default locale
25
+ def locale
26
+ raise NotImplementedError.new
27
+ end
28
+
29
+ # Number of grand agents
30
+ def grand_agents
31
+ raise NotImplementedError.new
32
+ end
33
+
34
+ # Number of train runners
35
+ def train_runners
36
+ raise NotImplementedError.new
37
+ end
38
+
39
+ # Number of taxi runners
40
+ def taxi_runners
41
+ raise NotImplementedError.new
42
+ end
43
+
44
+ # Max count of ships
45
+ def max_ships
46
+ raise NotImplementedError.new
47
+ end
48
+
49
+ # Trouble docker
50
+ def trouble
51
+ raise NotImplementedError.new
52
+ end
53
+
54
+ # Socket timeout in seconds
55
+ def socket_timeout_sec
56
+ raise NotImplementedError.new
57
+ end
58
+
59
+ # Keep-Alive timeout in seconds
60
+ def keep_timeout_sec
61
+ raise NotImplementedError.new
62
+ end
63
+
64
+ # Trace req/res header flag
65
+ def trace_header
66
+ raise NotImplementedError.new
67
+ end
68
+
69
+ # Internal buffer size of Tour
70
+ def tour_buffer_size
71
+ raise NotImplementedError.new
72
+ end
73
+
74
+ # File name to redirect stdout/stderr
75
+ def redirect_file
76
+ raise NotImplementedError.new
77
+ end
78
+
79
+ # Port number of signal agent
80
+ def control_port
81
+ raise NotImplementedError.new
82
+ end
83
+
84
+ # Gzip compression flag
85
+ def gzip_comp
86
+ raise NotImplementedError.new
87
+ end
88
+
89
+ # Multiplexer of Network I/O
90
+ def net_multiplexer
91
+ raise NotImplementedError.new
92
+ end
93
+
94
+ # Multiplexer of File I/O
95
+ def file_multiplexer
96
+ raise NotImplementedError.new
97
+ end
98
+
99
+ # Multiplexer of Log output
100
+ def log_multiplexer
101
+ raise NotImplementedError.new
102
+ end
103
+
104
+ # Multiplexer of CGI input
105
+ def cgi_multiplexer
106
+ raise NotImplementedError.new
107
+ end
108
+
109
+ # Recipient
110
+ def recipient
111
+ raise NotImplementedError
112
+ end
113
+
114
+ # PID file name
115
+ def pid_file
116
+ raise NotImplementedError
117
+ end
118
+
119
+ # Multi core flag
120
+ def multi_core
121
+ raise NotImplementedError
122
+ end
123
+
124
+
125
+ def self.get_multiplexer_type_name(type)
126
+ case type
127
+ when MULTIPLEXER_TYPE_SPIDER
128
+ return "spider"
129
+ when MULTIPLEXER_TYPE_SPIN
130
+ return "spin"
131
+ when MULTIPLEXER_TYPE_PIGEON
132
+ return "pigeon"
133
+ when MULTIPLEXER_TYPE_JOB
134
+ return "job"
135
+ when MULTIPLEXER_TYPE_TAXI
136
+ return "taxi"
137
+ when MULTIPLEXER_TYPE_TRAIN
138
+ return "train"
139
+ else
140
+ return nil
141
+ end
142
+ end
143
+
144
+ def self.get_multiplexer_type(type)
145
+ if type != nil
146
+ type = type.downcase
147
+ end
148
+
149
+ case type
150
+ when "spider"
151
+ return MULTIPLEXER_TYPE_SPIDER
152
+ when "spin"
153
+ return MULTIPLEXER_TYPE_SPIN
154
+ when "pigeon"
155
+ return MULTIPLEXER_TYPE_PIGEON
156
+ when "job"
157
+ return MULTIPLEXER_TYPE_JOB
158
+ when "taxi"
159
+ return MULTIPLEXER_TYPE_TAXI
160
+ when "train"
161
+ return MULTIPLEXER_TYPE_TRAIN
162
+ else
163
+ raise ArgumentError
164
+ end
165
+ end
166
+
167
+ def self.get_recipient_type_name(type)
168
+ case type
169
+ when RECIPIENT_TYPE_SPIDER
170
+ return "spider"
171
+ when RECIPIENT_TYPE_PIPE
172
+ return "pipe"
173
+ else
174
+ return nil
175
+ end
176
+ end
177
+
178
+ def self.get_recipient_type(type)
179
+ if type != nil
180
+ type = type.downcase
181
+ end
182
+
183
+ case type
184
+ when "spider"
185
+ return RECIPIENT_TYPE_SPIDER
186
+ when "pipe"
187
+ return RECIPIENT_TYPE_PIPE
188
+ else
189
+ raise ArgumentError
190
+ end
191
+ end
192
+
31
193
  end
32
194
  end
33
195
  end
@@ -6,12 +6,13 @@ module Baykit
6
6
  module Permission
7
7
  include Docker # implements
8
8
 
9
- #
10
- # interface
11
- #
12
- # void checkAdmitted(SocketChannel ch) throws HttpException;
13
- # void checkAdmitted(Tour tour) throws HttpException;
14
- #
9
+ def socket_admitterd(rd)
10
+ raise NotImplementedError.new
11
+ end
12
+
13
+ def tour_admitted(tour)
14
+ raise NotImplementedError.new
15
+ end
15
16
  end
16
17
  end
17
18
  end
@@ -6,32 +6,60 @@ module Baykit
6
6
  module Port
7
7
  include Docker # implements
8
8
 
9
+ def protocol
10
+ raise NotImplementedError.new
11
+ end
12
+
13
+ def host
14
+ raise NotImplementedError.new
15
+ end
16
+
17
+ def port
18
+ raise NotImplementedError.new
19
+ end
20
+
21
+ def socket_path
22
+ raise NotImplementedError.new
23
+ end
24
+
9
25
  def address()
10
- raise NotImplementedError()
26
+ raise NotImplementedError.new
11
27
  end
12
28
 
13
- def check_admitted(skt)
14
- raise NotImplementedError()
29
+ def anchored
30
+ raise NotImplementedError.new
15
31
  end
16
32
 
17
- def find_city(name)
18
- raise NotImplementedError()
33
+ def secure
34
+ raise NotImplementedError.new
35
+ end
36
+
37
+ def timeout_sec
38
+ raise NotImplementedError.new
39
+ end
40
+
41
+ def additional_headers
42
+ raise NotImplementedError.new
43
+ end
44
+
45
+ def cities
46
+ raise NotImplementedError.new
19
47
  end
20
48
 
21
- def new_transporter(agt, skt)
22
- raise NotImplementedError()
49
+ def find_city(name)
50
+ raise NotImplementedError.new
23
51
  end
24
52
 
25
- def check_admitted(skt)
26
- raise NotImplementedError()
53
+ def on_connected(agent_id, rd)
54
+ raise NotImplementedError.new
27
55
  end
28
56
 
29
57
  def return_protocol_handler(agt, proto_hnd)
30
- raise NotImplementedError()
58
+ raise NotImplementedError.new
31
59
  end
32
60
 
33
61
  def return_ship(sip)
34
- raise NotImplementedError()
62
+ raise NotImplementedError.new
35
63
  end
36
64
  end
37
65
  end
@@ -6,15 +6,17 @@ module Baykit
6
6
  module Secure
7
7
  include Docker # implements
8
8
 
9
- #
10
- # interface
11
- #
12
- # void setAppProtocols(String[] protocols);
13
- #
14
- # void reloadCert() throws Exception;
15
- #
16
- # public Transporter createTransporter();
17
- #
9
+ def set_app_protocols(protocols)
10
+ raise NotImplementedError.new
11
+ end
12
+
13
+ def reload_cert
14
+ raise NotImplementedError.new
15
+ end
16
+
17
+ def new_transporter(agt_id, sip)
18
+ raise NotImplementedError
19
+ end
18
20
  end
19
21
  end
20
22
  end
@@ -1,5 +1,9 @@
1
1
  require 'baykit/bayserver/tours/req_content_handler'
2
2
  require 'baykit/bayserver/tours/tour'
3
+ require 'baykit/bayserver/rudders/io_rudder'
4
+ require 'baykit/bayserver/agent/multiplexer/plain_transporter'
5
+ require 'baykit/bayserver/util/mimes'
6
+ require 'baykit/bayserver/docker/send_file/send_file_ship'
3
7
 
4
8
  module Baykit
5
9
  module BayServer
@@ -7,7 +11,11 @@ module Baykit
7
11
  module SendFile
8
12
  class FileContentHandler
9
13
  include Baykit::BayServer::Tours::ReqContentHandler # implements
14
+ include Baykit::BayServer::Agent
15
+ include Baykit::BayServer::Agent::Multiplexer
10
16
  include Baykit::BayServer::Tours
17
+ include Baykit::BayServer::Rudders
18
+ include Baykit::BayServer::Util
11
19
 
12
20
  attr :path
13
21
  attr :abortable
@@ -21,21 +29,108 @@ module Baykit
21
29
  # Implements ReqContentHandler
22
30
  ######################################################
23
31
 
24
- def on_read_content(tur, buf, start, len)
32
+ def on_read_req_content(tur, buf, start, len, &lis)
25
33
  BayLog.debug("%s onReadReqContent(Ignore) len=%d", tur, len)
34
+ tur.req.consumed(tur.tour_id, len, &lis)
26
35
  end
27
36
 
28
- def on_end_content(tur)
37
+ def on_end_req_content(tur)
29
38
  BayLog.debug("%s endReqContent", tur)
30
- tur.res.send_file(Tour::TOUR_ID_NOCHECK, path, tur.res.charset, true)
39
+ send_file_async(tur, path, tur.res.charset)
31
40
  @abortable = false
32
41
  end
33
42
 
34
- def on_abort(tur)
43
+ def on_abort_req(tur)
35
44
  BayLog.debug("%s onAbortReq aborted=%s", tur, abortable)
36
45
  return abortable
37
46
  end
38
47
 
48
+ ######################################################
49
+ # Sending file methods
50
+ ######################################################
51
+
52
+ def send_file_async(tur, file, charset)
53
+
54
+ if File.directory?(file)
55
+ raise HttpException.new HttpStatus::FORBIDDEN, file
56
+ elsif !File.exist?(file)
57
+ raise HttpException.new HttpStatus::NOT_FOUND, file
58
+ end
59
+
60
+ mime_type = nil
61
+
62
+ rname = File.basename(file)
63
+ pos = rname.rindex('.')
64
+ if pos
65
+ ext = rname[pos + 1 .. -1].downcase
66
+ mime_type = Mimes.type(ext)
67
+ end
68
+
69
+ if !mime_type
70
+ mime_type = "application/octet-stream"
71
+ end
72
+
73
+ if mime_type.start_with?("text/") && charset != nil
74
+ mime_type = mime_type + "; charset=" + charset
75
+ end
76
+
77
+ file_len = ::File.size(file)
78
+
79
+ tur.res.headers.set_content_type(mime_type)
80
+ tur.res.headers.set_content_length(file_len)
81
+
82
+ begin
83
+ tur.res.send_headers(Tour::TOUR_ID_NOCHECK)
84
+
85
+ bufsize = tur.ship.protocol_handler.max_res_packet_data_size
86
+ agt = GrandAgent.get(tur.ship.agent_id)
87
+
88
+ f = File.open(file, "rb")
89
+ rd = IORudder.new(f)
90
+
91
+ case(BayServer.harbor.file_multiplexer)
92
+
93
+ when Harbor::MULTIPLEXER_TYPE_SPIDER
94
+ mpx = agt.spider_multiplexer
95
+
96
+ when Harbor::MULTIPLEXER_TYPE_SPIN
97
+ mpx = agt.spin_multiplexer
98
+
99
+ when Harbor::MULTIPLEXER_TYPE_TAXI
100
+ mpx = agt.taxi_multiplexer
101
+
102
+ else
103
+ raise Sink.new
104
+ end
105
+
106
+ send_file_ship = SendFileShip.new
107
+ tp = PlainTransporter.new(
108
+ mpx,
109
+ send_file_ship,
110
+ true,
111
+ 8195,
112
+ false)
113
+
114
+ send_file_ship.init(rd, tp, tur)
115
+ sid = send_file_ship.ship_id
116
+
117
+ tur.res.set_consume_listener do |len, resume|
118
+ if resume
119
+ send_file_ship.resume_read(sid)
120
+ end
121
+ end
122
+
123
+ mpx.add_rudder_state(rd, RudderState.new(rd, tp))
124
+ mpx.req_read(rd)
125
+
126
+ rescue IOError => e
127
+ BayLog.error_e(e)
128
+ raise HttpException.new(HttpStatus::INTERNAL_SERVER_ERROR, file)
129
+ end
130
+
131
+ end
132
+
133
+
39
134
  end
40
135
  end
41
136
  end
@@ -46,11 +46,15 @@ module Baykit
46
46
  end
47
47
 
48
48
  begin
49
- rel_path = URLDecoder.decode(rel_path, tur.req.charset)
50
- rescue Encoding::UndefinedConversionError => e
49
+ rel_path = CGI.unescape(rel_path)
50
+ rescue Encoding::CompatibilityError => e
51
51
  BayLog.warn("%s Cannot decode request path: %s (encoding=%s)", tur, rel_path, tur.req.charset)
52
52
  end
53
53
 
54
+ if StringUtil.set?(tur.req.charset) && tur.req.charset != "UTF-8"
55
+ rel_path = rel_path.force_encoding(tur.req.charset).encode("UTF-8")
56
+ end
57
+
54
58
  real = "#{tur.town.location}/#{rel_path}"
55
59
 
56
60
  if File.directory?(real) && @list_files