bayserver-docker-fcgi 2.3.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 289a23cc5810c090a239df6233dd8bd63f973bb39d8a65eb8b265b0233973904
4
- data.tar.gz: b7f740d4e725432a763b5b9f0fdf8e6bd7aac3e5852ef52b6560e9ed72bd4de0
3
+ metadata.gz: ac6e10f22238925d53d4b263e48e07563a08b4d353b452f5364c1d6dd817c67c
4
+ data.tar.gz: 24b6c04656d85b3eeb0884179c7598a9b32a877e50850157650b5a0ac86a22c1
5
5
  SHA512:
6
- metadata.gz: 3f0ed513d2ea1dbe0a6ba4493ca70fe533537969cffaf8f2821bc7fb022bec02b955aec0d9644abf99cca9b0a30f8af68a925701cc8f591f95708955996f5f63
7
- data.tar.gz: c7fedd620450d4965aab1e1044b7b853c50c0afb894b3282ad75ba17f8c41431f7fb724f7c6c0de4229936c7c11f279cd76291ac13cdc03f3a49b83e3fe8c15f
6
+ metadata.gz: d4bb7bbcbc6041bf6528228520d36b698fd1964e9317fe1691db84a852aaff8f05832c3a58816b53948c7ee25f086c542d11ab0885e31143ba4745f007875bd8
7
+ data.tar.gz: fb9d03f73913be62b8ea301ca66dea5f16819e602b7dfc5c674cd822cb2dbf09022a8c8e4a7b2214084a779d79a48654feef8c94e7fabfff8387ab00f4037018
@@ -0,0 +1,14 @@
1
+
2
+ module Baykit
3
+ module BayServer
4
+ module Docker
5
+ module Fcgi
6
+ module FcgHandler # interface
7
+ def on_protocol_error(e)
8
+ raise NotImplementedError.new
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,47 +1,65 @@
1
1
  require 'baykit/bayserver/protocol/protocol_exception'
2
- require 'baykit/bayserver/docker/base/inbound_handler'
2
+ require 'baykit/bayserver/common/inbound_handler'
3
3
  require 'baykit/bayserver/tours/req_content_handler'
4
4
  require 'baykit/bayserver/util/cgi_util'
5
5
 
6
6
  require 'baykit/bayserver/docker/fcgi/fcg_protocol_handler'
7
+ require 'baykit/bayserver/docker/fcgi/fcg_handler'
7
8
 
8
9
  module Baykit
9
10
  module BayServer
10
11
  module Docker
11
12
  module Fcgi
12
- class FcgInboundHandler < Baykit::BayServer::Docker::Fcgi::FcgProtocolHandler
13
+ class FcgInboundHandler
13
14
 
14
15
  class InboundProtocolHandlerFactory
15
16
  include Baykit::BayServer::Protocol::ProtocolHandlerFactory # implements
16
17
 
18
+ include Baykit::BayServer::Protocol
19
+
17
20
  def create_protocol_handler(pkt_store)
18
- return FcgInboundHandler.new(pkt_store)
21
+ ib_handler = FcgInboundHandler.new
22
+ cmd_unpacker = FcgCommandUnPacker.new(ib_handler)
23
+ pkt_unpacker = FcgPacketUnPacker.new(pkt_store, cmd_unpacker)
24
+ pkt_packer = PacketPacker.new()
25
+ cmd_packer = CommandPacker.new(pkt_packer, pkt_store)
26
+
27
+ proto_handler = FcgProtocolHandler.new(ib_handler, pkt_unpacker, pkt_packer, cmd_unpacker, cmd_packer, true)
28
+ ib_handler.init(proto_handler)
29
+ return proto_handler
19
30
  end
20
31
  end
21
32
 
22
- include Baykit::BayServer::Docker::Base::InboundHandler # implements
33
+ include Baykit::BayServer::Common::InboundHandler # implements
34
+ include FcgHandler # implements
35
+
23
36
  include Baykit::BayServer::Agent
24
37
  include Baykit::BayServer::Tours
25
38
  include Baykit::BayServer::Protocol
26
39
  include Baykit::BayServer::Util
40
+ include Baykit::BayServer::Docker::Fcgi::Command
27
41
 
28
42
  STATE_BEGIN_REQUEST = 1
29
43
  STATE_READ_PARAMS = 2
30
44
  STATE_READ_STDIN = 3
31
45
 
32
46
  attr :state
47
+ attr :protocol_handler
33
48
  attr :cont_len
34
49
 
35
50
  attr :env
36
51
  attr :req_id
37
52
  attr :req_keep_alive
38
53
 
39
- def initialize(pkt_store)
40
- super(pkt_store, true)
54
+ def initialize
41
55
  @env = {}
42
- reset_state()
56
+ reset()
43
57
  end
44
58
 
59
+ def init(proto_handler)
60
+ @protocol_handler = proto_handler
61
+ end
62
+
45
63
  def to_s()
46
64
  return ClassUtil.get_local_name(self.class)
47
65
  end
@@ -50,23 +68,22 @@ module Baykit
50
68
  # implements Reusable
51
69
  ######################################################
52
70
  def reset
53
- super
54
71
  @env.clear()
55
72
  reset_state()
56
73
  end
57
74
 
58
75
  ######################################################
59
- # implements InboundHandler
76
+ # implements TourHandler
60
77
  ######################################################
61
78
 
62
79
  def send_res_headers(tur)
63
- BayLog.debug("%s PH:sendHeaders: tur=%s", @ship, tur)
80
+ BayLog.debug("%s PH:sendHeaders: tur=%s", ship, tur)
64
81
 
65
82
  scode = tur.res.headers.status
66
83
  status = "#{scode} #{HttpStatus.description(scode)}"
67
84
  tur.res.headers.set(Headers::STATUS, status)
68
85
 
69
- if BayServer.harbor.trace_header?
86
+ if BayServer.harbor.trace_header
70
87
  BayLog.info("%s resStatus:%d", tur, tur.res.headers.status)
71
88
  tur.res.headers.names().each do |name|
72
89
  tur.res.headers.values(name) do |value|
@@ -79,32 +96,32 @@ module Baykit
79
96
  HttpUtil.send_mime_headers(tur.res.headers, buf)
80
97
  HttpUtil.send_new_line(buf)
81
98
  cmd = CmdStdOut.new(tur.req.key, buf.buf, 0, buf.length)
82
- @command_packer.post(@ship, cmd)
99
+ @protocol_handler.post(cmd)
83
100
  end
84
101
 
85
102
  def send_res_content(tur, bytes, ofs, len, &callback)
86
103
  cmd = CmdStdOut.new(tur.req.key, bytes, ofs, len);
87
- @command_packer.post(@ship, cmd, &callback)
104
+ @protocol_handler.post(cmd, &callback)
88
105
  end
89
106
 
90
107
  def send_end_tour(tur, keep_alive, &callback)
91
- BayLog.debug("%s PH:endTour: tur=%s keep=%s", @ship, tur, keep_alive)
108
+ BayLog.debug("%s PH:endTour: tur=%s keep=%s", ship, tur, keep_alive)
92
109
 
93
110
  # Send empty stdout command
94
111
  cmd = CmdStdOut.new(tur.req.key)
95
- @command_packer.post(@ship, cmd)
112
+ @protocol_handler.post(cmd)
96
113
 
97
114
  # Send end request command
98
115
  cmd = CmdEndRequest.new(tur.req.key)
99
116
 
100
117
  ensure_func = lambda do
101
118
  if !keep_alive
102
- @command_packer.end(@ship)
119
+ ship.post_close
103
120
  end
104
121
  end
105
122
 
106
123
  begin
107
- @command_packer.post(@ship, cmd) do
124
+ @protocol_handler.post(cmd) do
108
125
  BayLog.debug("%s call back in sendEndTour: tur=%s keep=%s", self, tur, keep_alive)
109
126
  ensure_func.call()
110
127
  callback.call()
@@ -116,8 +133,8 @@ module Baykit
116
133
  end
117
134
  end
118
135
 
119
- def send_req_protocol_error(err)
120
- tur = @ship.get_error_tour()
136
+ def on_protocol_error(err)
137
+ tur = ship.get_error_tour()
121
138
  tur.res.send_error(Tour::TOUR_ID_NOCHECK, HttpStatus::BAD_REQUEST, err.message, err)
122
139
  true
123
140
  end
@@ -155,7 +172,7 @@ module Baykit
155
172
  end
156
173
 
157
174
  def handle_params(cmd)
158
- BayLog.debug("%s handle_params req_id=%d", @ship, cmd.req_id)
175
+ BayLog.debug("%s handle_params req_id=%d", ship, cmd.req_id)
159
176
 
160
177
  if state != STATE_READ_PARAMS
161
178
  raise ProtocolException.new("Invalid FCGI command: %d state=%d", cmd.type, @state)
@@ -163,8 +180,8 @@ module Baykit
163
180
 
164
181
  check_req_id(cmd.req_id)
165
182
 
166
- BayLog.debug("%s handle_param get_tour req_id=%d", @ship, cmd.req_id)
167
- tur = @ship.get_tour(cmd.req_id)
183
+ BayLog.debug("%s handle_param get_tour req_id=%d", ship, cmd.req_id)
184
+ tur = ship.get_tour(cmd.req_id)
168
185
 
169
186
  if cmd.params.empty?
170
187
  # Header completed
@@ -182,28 +199,23 @@ module Baykit
182
199
  req_cont_len = tur.req.headers.content_length()
183
200
 
184
201
  BayLog.debug("%s read header method=%s protocol=%s uri=%s contlen=%d",
185
- @ship, tur.req.method, tur.req.protocol, tur.req.uri, @cont_len)
202
+ ship, tur.req.method, tur.req.protocol, tur.req.uri, @cont_len)
186
203
 
187
- if BayServer.harbor.trace_header?
204
+ if BayServer.harbor.trace_header
188
205
  cmd.params.each do |nv|
189
206
  BayLog.info("%s reqHeader: %s=%s", tur, nv[0], nv[1])
190
207
  end
191
208
  end
192
209
 
193
210
  if req_cont_len > 0
194
- tur.req.set_consume_listener(req_cont_len) do |len, resume|
195
- sid = @ship.ship_id
196
- if resume
197
- @ship.resume(sid)
198
- end
199
- end
211
+ tur.req.set_limit(req_cont_len)
200
212
  end
201
213
 
202
214
  change_state(STATE_READ_STDIN)
203
215
  begin
204
216
  start_tour(tur)
205
217
  rescue HttpException => e
206
- BayLog.debug("%s Http error occurred: %s", @ship, e)
218
+ BayLog.debug("%s Http error occurred: %s", ship, e)
207
219
 
208
220
  if req_cont_len <= 0
209
221
  # no post data
@@ -220,14 +232,14 @@ module Baykit
220
232
  end
221
233
 
222
234
  else
223
- if BayServer.harbor.trace_header?
235
+ if BayServer.harbor.trace_header
224
236
  BayLog.info("%s Read FcgiParam", tur)
225
237
  end
226
238
 
227
239
  cmd.params.each do |nv|
228
240
  name = nv[0]
229
241
  value = nv[1]
230
- if BayServer.harbor.trace_header?
242
+ if BayServer.harbor.trace_header
231
243
  BayLog.info("%s param: %s=%s", tur, name, value);
232
244
  end
233
245
  @env[name] = value
@@ -257,41 +269,48 @@ module Baykit
257
269
  end
258
270
 
259
271
  def handle_stdin(cmd)
260
- BayLog.debug("%s handle_stdin req_id=%d len=%d", @ship, cmd.req_id, cmd.length)
272
+ BayLog.debug("%s handle_stdin req_id=%d len=%d", ship, cmd.req_id, cmd.length)
261
273
 
262
274
  if @state != STATE_READ_STDIN
263
275
  raise ProtocolException.new("Invalid FCGI command: %d state=%d", cmd.type, @state)
264
276
  end
265
277
 
266
- check_req_id(cmd.req_id)
267
-
268
- tur = @ship.get_tour(cmd.req_id)
269
- if cmd.length == 0
270
- # request content completed
271
- if tur.error != nil
272
- # Error has occurred on header completed
273
- tur.res.set_consume_listener do |len, resume|
278
+ begin
279
+ check_req_id(cmd.req_id)
280
+
281
+ tur = ship.get_tour(cmd.req_id)
282
+ if cmd.length == 0
283
+ # request content completed
284
+ if tur.error != nil
285
+ # Error has occurred on header completed
286
+ BayLog.debug("%s Delay send error", tur)
287
+ raise tur.error
288
+ else
289
+ begin
290
+ end_req_content(Tour::TOUR_ID_NOCHECK, tur)
291
+ return NextSocketAction::CONTINUE
292
+ end
274
293
  end
275
- tur.res.send_http_exception(Tour::TOUR_ID_NOCHECK, tur.error)
276
- reset_state()
277
- return NextSocketAction::WRITE
278
294
  else
279
- begin
280
- end_req_content(Tour::TOUR_ID_NOCHECK, tur)
295
+ sid = ship.ship_id
296
+ success = tur.req.post_req_content(Tour::TOUR_ID_NOCHECK, cmd.data, cmd.start, cmd.length) do |len, resume|
297
+ if resume
298
+ ship.resume_read(sid)
299
+ end
300
+ end
301
+
302
+ if !success
303
+ return NextSocketAction::SUSPEND
304
+ else
281
305
  return NextSocketAction::CONTINUE
282
- rescue HttpException => e
283
- tur.res.send_http_exception(Tour::TOUR_ID_NOCHECK, e)
284
- return NextSocketAction::WRITE
285
306
  end
286
307
  end
287
- else
288
- success = tur.req.post_content(Tour::TOUR_ID_NOCHECK, cmd.data, cmd.start, cmd.length)
289
308
 
290
- if !success
291
- return NextSocketAction::SUSPEND
292
- else
293
- return NextSocketAction::CONTINUE
294
- end
309
+ rescue HttpException => e
310
+ tur.res.send_http_exception(Tour::TOUR_ID_NOCHECK, tur.error)
311
+ tur.res.send_http_exception(Tour::TOUR_ID_NOCHECK, e)
312
+ reset_state()
313
+ return NextSocketAction::WRITE
295
314
  end
296
315
  end
297
316
 
@@ -300,6 +319,11 @@ module Baykit
300
319
  end
301
320
 
302
321
  private
322
+
323
+ def ship
324
+ return @protocol_handler.ship
325
+ end
326
+
303
327
  def check_req_id(received_id)
304
328
  if received_id == FcgPacket::FCGI_NULL_REQUEST_ID
305
329
  raise ProtocolException.new("Invalid request id: %d", received_id)
@@ -310,7 +334,7 @@ module Baykit
310
334
  end
311
335
 
312
336
  if @req_id != received_id
313
- BayLog.error("%s invalid request id: received=%d reqId=%d", @ship, received_id, req_id)
337
+ BayLog.error("%s invalid request id: received=%d reqId=%d", sip, received_id, req_id)
314
338
  raise ProtocolException.new("Invalid request id: %d", received_id)
315
339
  end
316
340
  end
@@ -326,7 +350,7 @@ module Baykit
326
350
  end
327
351
 
328
352
  def end_req_content(check_id, tur)
329
- tur.req.end_content(check_id)
353
+ tur.req.end_req_content(check_id)
330
354
  reset_state()
331
355
  end
332
356
 
@@ -336,7 +360,7 @@ module Baykit
336
360
 
337
361
  tur.req.remote_port = @env[CgiUtil::REMOTE_PORT].to_i
338
362
  tur.req.remote_address = @env[CgiUtil::REMOTE_ADDR]
339
- tur.req.remote_host_func = lambda { @req_command.remote_host }
363
+ tur.req.remote_host_func = lambda { tur.req.remote_address }
340
364
 
341
365
  tur.req.server_name = @env[CgiUtil::SERVER_NAME]
342
366
  tur.req.server_address = @env[CgiUtil::SERVER_ADDR]
@@ -20,17 +20,10 @@ module Baykit
20
20
  include Baykit::BayServer::Protocol
21
21
  include Baykit::BayServer::Docker::Fcgi::Command
22
22
 
23
- def initialize(pkt_store, svr_mode)
24
- @command_unpacker = FcgCommandUnPacker.new(self)
25
- @packet_unpacker = FcgPacketUnPacker.new(pkt_store, @command_unpacker)
26
- @packet_packer = PacketPacker.new()
27
- @command_packer = CommandPacker.new(@packet_packer, pkt_store)
28
- @server_mode = svr_mode
23
+ def initialize(fcg_handler, pkt_unpacker, pkt_packer, cmd_unpacker, cmd_packer, svr_mode)
24
+ super(pkt_unpacker, pkt_packer, cmd_unpacker, cmd_packer, fcg_handler, svr_mode)
29
25
  end
30
26
 
31
- def inspect()
32
- return "PH[#{@ship}]"
33
- end
34
27
 
35
28
  ######################################################
36
29
  # Implements ProtocolHandler
@@ -1,18 +1,20 @@
1
1
  require 'baykit/bayserver/bcf/package'
2
- require 'baykit/bayserver/docker/warp/warp_docker'
3
- require 'baykit/bayserver/agent/transporter/plain_transporter'
2
+ require 'baykit/bayserver/docker/base/warp_base'
3
+ require 'baykit/bayserver/agent/multiplexer/plain_transporter'
4
4
  require 'baykit/bayserver/docker/fcgi/package'
5
+ require 'baykit/bayserver/util/io_util'
5
6
 
6
7
  module Baykit
7
8
  module BayServer
8
9
  module Docker
9
10
  module Fcgi
10
- class FcgWarpDocker < Baykit::BayServer::Docker::Warp::WarpDocker
11
+ class FcgWarpDocker < Baykit::BayServer::Docker::Base::WarpBase
11
12
  include Baykit::BayServer::Docker::Fcgi::FcgDocker # implements
12
13
 
13
14
  include Baykit::BayServer::Bcf
14
15
  include Baykit::BayServer::Protocol
15
- include Baykit::BayServer::Agent::Transporter
16
+ include Baykit::BayServer::Util
17
+ include Baykit::BayServer::Agent::Multiplexer
16
18
 
17
19
  attr :script_base
18
20
  attr :doc_root
@@ -34,7 +36,7 @@ module Baykit
34
36
 
35
37
  def init_key_val(kv)
36
38
  case kv.key.downcase
37
- when "scritbase"
39
+ when "scriptbase"
38
40
  @script_base = kv.value
39
41
  when "docroot"
40
42
  @doc_root = kv.value
@@ -58,8 +60,15 @@ module Baykit
58
60
  return PROTO_NAME
59
61
  end
60
62
 
61
- def new_transporter(agt, skt)
62
- PlainTransporter.new(false, IOUtil.get_sock_recv_buf_size(skt))
63
+ def new_transporter(agt, rd, sip)
64
+ tp = PlainTransporter.new(
65
+ agt.net_multiplexer,
66
+ sip,
67
+ false,
68
+ IOUtil.get_sock_recv_buf_size(rd.io),
69
+ false
70
+ )
71
+ return tp
63
72
  end
64
73
 
65
74
  ######################################################
@@ -1,3 +1,5 @@
1
+ require 'baykit/bayserver/sink'
2
+
1
3
  require 'baykit/bayserver/protocol/protocol_exception'
2
4
  require 'baykit/bayserver/tours/package'
3
5
  require 'baykit/bayserver/agent/next_socket_action'
@@ -6,7 +8,7 @@ require 'baykit/bayserver/util/string_util'
6
8
  require 'baykit/bayserver/util/simple_buffer'
7
9
  require 'baykit/bayserver/util/cgi_util'
8
10
 
9
- require 'baykit/bayserver/docker/warp/warp_data'
11
+ require 'baykit/bayserver/common/warp_data'
10
12
  require 'baykit/bayserver/docker/fcgi/fcg_protocol_handler'
11
13
  require 'baykit/bayserver/docker/fcgi/command/package'
12
14
  require 'baykit/bayserver/docker/fcgi/fcg_params'
@@ -15,14 +17,24 @@ module Baykit
15
17
  module BayServer
16
18
  module Docker
17
19
  module Fcgi
18
- class FcgWarpHandler < Baykit::BayServer::Docker::Fcgi::FcgProtocolHandler
19
- include Baykit::BayServer::Docker::Warp::WarpHandler # implements
20
+ class FcgWarpHandler
21
+ include Baykit::BayServer::Common::WarpHandler # implements
22
+ include FcgHandler
20
23
 
21
24
  class WarpProtocolHandlerFactory
22
25
  include Baykit::BayServer::Protocol::ProtocolHandlerFactory # implements
26
+ include Baykit::BayServer::Protocol
23
27
 
24
28
  def create_protocol_handler(pkt_store)
25
- return FcgWarpHandler.new(pkt_store)
29
+ warp_handler = FcgWarpHandler.new
30
+ cmd_unpacker = FcgCommandUnPacker.new(warp_handler)
31
+ pkt_unpacker = FcgPacketUnPacker.new(pkt_store, cmd_unpacker)
32
+ pkt_packer = PacketPacker.new()
33
+ cmd_packer = CommandPacker.new(pkt_packer, pkt_store)
34
+
35
+ proto_handler = FcgProtocolHandler.new(warp_handler, pkt_unpacker, pkt_packer, cmd_unpacker, cmd_packer, false)
36
+ warp_handler.init(proto_handler)
37
+ return proto_handler
26
38
  end
27
39
  end
28
40
 
@@ -30,13 +42,14 @@ module Baykit
30
42
  include Baykit::BayServer::Protocol
31
43
  include Baykit::BayServer::Tours
32
44
  include Baykit::BayServer::Util
33
- include Baykit::BayServer::Docker::Warp
45
+ include Baykit::BayServer::Common
34
46
  include Baykit::BayServer::Docker::Fcgi::Command
35
47
 
36
48
 
37
49
  STATE_READ_HEADER = 1
38
50
  STATE_READ_CONTENT = 2
39
51
 
52
+ attr :protocol_handler
40
53
  attr :cur_warp_id
41
54
  attr :state
42
55
  attr :line_buf
@@ -45,15 +58,17 @@ module Baykit
45
58
  attr :last
46
59
  attr :data
47
60
 
48
- def initialize(pkt_store)
49
- super(pkt_store, false)
61
+ def initialize
50
62
  @cur_warp_id = 0
51
63
  @line_buf = SimpleBuffer.new
52
64
  reset()
53
65
  end
54
66
 
67
+ def init(proto_handler)
68
+ @protocol_handler = proto_handler
69
+ end
70
+
55
71
  def reset
56
- super
57
72
  reset_state
58
73
  @line_buf.reset
59
74
  @pos = 0
@@ -71,28 +86,33 @@ module Baykit
71
86
  end
72
87
 
73
88
  def new_warp_data(warp_id)
74
- return WarpData.new(@ship, warp_id)
89
+ return WarpData.new(ship, warp_id)
75
90
  end
76
91
 
77
- def post_warp_headers(tur)
92
+ ######################################################
93
+ # Implements TourHandler
94
+ ######################################################
95
+
96
+ def send_res_headers(tur)
78
97
  send_begin_req(tur)
79
98
  send_params(tur)
80
99
  end
81
100
 
82
- def post_warp_contents(tur, buf, start, len, &callback)
101
+ def send_res_content(tur, buf, start, len, &callback)
83
102
  send_stdin(tur, buf, start, len, &callback)
84
103
  end
85
104
 
86
- def post_warp_end(tur)
87
- callback = lambda do
88
- @ship.agent.non_blocking_handler.ask_to_read(@ship.socket)
89
- end
105
+ def send_end_tour(tur, keep_alive, &callback)
90
106
  send_stdin(tur, nil, 0, 0, &callback)
91
107
  end
92
108
 
93
109
  def verify_protocol(proto)
94
110
  end
95
111
 
112
+ def on_protocol_error(e)
113
+ raise Sink.new
114
+ end
115
+
96
116
 
97
117
  ######################################################
98
118
  # Implements FcgCommandHandler
@@ -103,7 +123,7 @@ module Baykit
103
123
  end
104
124
 
105
125
  def handle_end_request(cmd)
106
- tur = @ship.get_tour(cmd.req_id)
126
+ tur = ship.get_tour(cmd.req_id)
107
127
  end_req_content(tur)
108
128
  NextSocketAction::CONTINUE
109
129
  end
@@ -123,10 +143,10 @@ module Baykit
123
143
  end
124
144
 
125
145
  def handle_stdout(cmd)
126
- BayLog.debug("%s handle_stdout req_id=%d len=%d", @ship, cmd.req_id, cmd.length)
146
+ BayLog.debug("%s handle_stdout req_id=%d len=%d", ship, cmd.req_id, cmd.length)
127
147
  #BayLog.debug "#{self} handle_stdout data=#{cmd.data}"
128
148
 
129
- tur = @ship.get_tour(cmd.req_id)
149
+ tur = ship.get_tour(cmd.req_id)
130
150
  if tur == nil
131
151
  raise Sink.new("Tour not found")
132
152
  end
@@ -146,9 +166,9 @@ module Baykit
146
166
  end
147
167
 
148
168
  if @pos < @last
149
- BayLog.debug("%s fcgi: pos=%d last=%d len=%d", @ship, @pos, @last, @last - @pos)
169
+ BayLog.debug("%s fcgi: pos=%d last=%d len=%d", ship, @pos, @last, @last - @pos)
150
170
  if @state == STATE_READ_CONTENT
151
- available = tur.res.send_content(Tour::TOUR_ID_NOCHECK, @data, @pos, @last - @pos)
171
+ available = tur.res.send_res_content(Tour::TOUR_ID_NOCHECK, @data, @pos, @last - @pos)
152
172
  if !available
153
173
  return NextSocketAction::SUSPEND
154
174
  end
@@ -158,6 +178,10 @@ module Baykit
158
178
  NextSocketAction::CONTINUE
159
179
  end
160
180
 
181
+ ######################################################
182
+ # Implements FcgCommandHandler
183
+ ######################################################
184
+
161
185
  ######################################################
162
186
  # Custom methods
163
187
  ######################################################
@@ -179,11 +203,11 @@ module Baykit
179
203
  tur.res.headers.remove(Headers::STATUS)
180
204
  end
181
205
 
182
- BayLog.debug("%s fcgi: read header status=%d contlen=%d", @ship, tur.res.headers.status, wdat.res_headers.content_length())
183
- sid = @ship.ship_id
206
+ BayLog.debug("%s fcgi: read header status=%d contlen=%d", ship, tur.res.headers.status, wdat.res_headers.content_length())
207
+ sid = ship.ship_id
184
208
  tur.res.set_consume_listener do |len, resume|
185
209
  if resume
186
- @ship.resume(sid)
210
+ ship.resume_read(sid)
187
211
  end
188
212
  end
189
213
 
@@ -229,8 +253,8 @@ module Baykit
229
253
  end
230
254
 
231
255
  headers.add(name, value)
232
- if BayServer.harbor.trace_header?
233
- BayLog.info("%s fcgi_warp: resHeader: %s=%s", @ship, name, value)
256
+ if BayServer.harbor.trace_header
257
+ BayLog.info("%s fcgi_warp: resHeader: %s=%s", ship, name, value)
234
258
  end
235
259
  end
236
260
  @line_buf.reset()
@@ -242,8 +266,8 @@ module Baykit
242
266
  end
243
267
 
244
268
  def end_req_content(tur)
245
- @ship.end_warp_tour(tur)
246
- tur.res.end_content(Tour::TOUR_ID_NOCHECK)
269
+ ship.end_warp_tour(tur)
270
+ tur.res.end_res_content(Tour::TOUR_ID_NOCHECK)
247
271
  reset_state()
248
272
  end
249
273
 
@@ -258,18 +282,18 @@ module Baykit
258
282
 
259
283
  def send_stdin(tur, data, ofs, len, &callback)
260
284
  cmd = CmdStdIn.new(WarpData.get(tur).warp_id, data, ofs, len)
261
- @ship.post(cmd, callback)
285
+ ship.post(cmd, &callback)
262
286
  end
263
287
 
264
288
  def send_begin_req(tur)
265
289
  cmd = CmdBeginRequest.new(WarpData.get(tur).warp_id)
266
290
  cmd.role = CmdBeginRequest::FCGI_RESPONDER
267
291
  cmd.keep_conn = true
268
- @ship.post(cmd)
292
+ ship.post(cmd)
269
293
  end
270
294
 
271
295
  def send_params(tur)
272
- script_base = @ship.docker.script_base
296
+ script_base = ship.docker.script_base
273
297
  if script_base == nil
274
298
  script_base = tur.town.location
275
299
  end
@@ -278,7 +302,7 @@ module Baykit
278
302
  raise StandardError.new("#{tur.town} Could not create SCRIPT_FILENAME. Location of town not specified.")
279
303
  end
280
304
 
281
- doc_root = @ship.docker.doc_root
305
+ doc_root = ship.docker.doc_root
282
306
  if doc_root == nil
283
307
  doc_root = tur.town.location
284
308
  end
@@ -298,7 +322,7 @@ module Baykit
298
322
  end
299
323
  end
300
324
 
301
- script_fname = "proxy:fcgi://#{@ship.docker.host}:#{@ship.docker.port}#{script_fname}"
325
+ script_fname = "proxy:fcgi://#{ship.docker.host}:#{ship.docker.port}#{script_fname}"
302
326
  cmd.add_param(CgiUtil::SCRIPT_FILENAME, script_fname)
303
327
 
304
328
  # Add FCGI params
@@ -308,18 +332,21 @@ module Baykit
308
332
  #cmd.add_param(FcgParams::X_FORWARDED_PROTO, tur.is_secure ? "https" : "http")
309
333
  #cmd.add_param(FcgParams::X_FORWARDED_PORT, tur.req.req_port.to_s)
310
334
 
311
- if BayServer.harbor.trace_header?
335
+ if BayServer.harbor.trace_header
312
336
  cmd.params.each do |kv|
313
- BayLog.info("%s fcgi_warp: env: %s=%s", @ship, kv[0], kv[1])
337
+ BayLog.info("%s fcgi_warp: env: %s=%s", ship, kv[0], kv[1])
314
338
  end
315
339
  end
316
340
 
317
- @ship.post(cmd)
341
+ ship.post(cmd)
318
342
 
319
343
  cmd_params_end = CmdParams.new(WarpData.get(tur).warp_id)
320
- @ship.post(cmd_params_end)
344
+ ship.post(cmd_params_end)
321
345
  end
322
346
 
347
+ def ship
348
+ return @protocol_handler.ship
349
+ end
323
350
  end
324
351
  end
325
352
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bayserver-docker-fcgi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michisuke-P
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-23 00:00:00.000000000 Z
11
+ date: 2024-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bayserver-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.3.2
19
+ version: 3.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.3.2
26
+ version: 3.0.0
27
27
  description: BayServer is one of the high-speed web servers. It operates as a single-threaded,
28
28
  asynchronous server, which makes it exceptionally fast. It also supports multi-core
29
29
  processors, harnessing the full potential of the CPU's capabilities.
@@ -46,6 +46,7 @@ files:
46
46
  - lib/baykit/bayserver/docker/fcgi/fcg_command_handler.rb
47
47
  - lib/baykit/bayserver/docker/fcgi/fcg_command_unpacker.rb
48
48
  - lib/baykit/bayserver/docker/fcgi/fcg_docker.rb
49
+ - lib/baykit/bayserver/docker/fcgi/fcg_handler.rb
49
50
  - lib/baykit/bayserver/docker/fcgi/fcg_inbound_handler.rb
50
51
  - lib/baykit/bayserver/docker/fcgi/fcg_packet.rb
51
52
  - lib/baykit/bayserver/docker/fcgi/fcg_packet_factory.rb