bayserver-docker-http 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/baykit/bayserver/docker/http/h1/command/cmd_content.rb +46 -0
- data/lib/baykit/bayserver/docker/http/h1/command/cmd_end_content.rb +37 -0
- data/lib/baykit/bayserver/docker/http/h1/command/cmd_header.rb +306 -0
- data/lib/baykit/bayserver/docker/http/h1/command/package.rb +3 -0
- data/lib/baykit/bayserver/docker/http/h1/h1_command.rb +19 -0
- data/lib/baykit/bayserver/docker/http/h1/h1_command_handler.rb +31 -0
- data/lib/baykit/bayserver/docker/http/h1/h1_command_unpacker.rb +58 -0
- data/lib/baykit/bayserver/docker/http/h1/h1_inbound_handler.rb +371 -0
- data/lib/baykit/bayserver/docker/http/h1/h1_packet.rb +28 -0
- data/lib/baykit/bayserver/docker/http/h1/h1_packet_factory.rb +21 -0
- data/lib/baykit/bayserver/docker/http/h1/h1_packet_unpacker.rb +180 -0
- data/lib/baykit/bayserver/docker/http/h1/h1_protocol_handler.rb +66 -0
- data/lib/baykit/bayserver/docker/http/h1/h1_type.rb +18 -0
- data/lib/baykit/bayserver/docker/http/h1/h1_warp_handler.rb +228 -0
- data/lib/baykit/bayserver/docker/http/h1/package.rb +11 -0
- data/lib/baykit/bayserver/docker/http/h2/command/cmd_data.rb +65 -0
- data/lib/baykit/bayserver/docker/http/h2/command/cmd_go_away.rb +67 -0
- data/lib/baykit/bayserver/docker/http/h2/command/cmd_headers.rb +108 -0
- data/lib/baykit/bayserver/docker/http/h2/command/cmd_ping.rb +50 -0
- data/lib/baykit/bayserver/docker/http/h2/command/cmd_preface.rb +51 -0
- data/lib/baykit/bayserver/docker/http/h2/command/cmd_priority.rb +59 -0
- data/lib/baykit/bayserver/docker/http/h2/command/cmd_rst_stream.rb +50 -0
- data/lib/baykit/bayserver/docker/http/h2/command/cmd_settings.rb +98 -0
- data/lib/baykit/bayserver/docker/http/h2/command/cmd_window_update.rb +53 -0
- data/lib/baykit/bayserver/docker/http/h2/command/package.rb +9 -0
- data/lib/baykit/bayserver/docker/http/h2/h2_command.rb +42 -0
- data/lib/baykit/bayserver/docker/http/h2/h2_command_handler.rb +29 -0
- data/lib/baykit/bayserver/docker/http/h2/h2_command_unpacker.rb +73 -0
- data/lib/baykit/bayserver/docker/http/h2/h2_error_code.rb +53 -0
- data/lib/baykit/bayserver/docker/http/h2/h2_flags.rb +82 -0
- data/lib/baykit/bayserver/docker/http/h2/h2_inbound_handler.rb +417 -0
- data/lib/baykit/bayserver/docker/http/h2/h2_packet.rb +204 -0
- data/lib/baykit/bayserver/docker/http/h2/h2_packet_factory.rb +21 -0
- data/lib/baykit/bayserver/docker/http/h2/h2_packet_unpacker.rb +224 -0
- data/lib/baykit/bayserver/docker/http/h2/h2_protocol_handler.rb +58 -0
- data/lib/baykit/bayserver/docker/http/h2/h2_settings.rb +42 -0
- data/lib/baykit/bayserver/docker/http/h2/h2_type.rb +26 -0
- data/lib/baykit/bayserver/docker/http/h2/h2_warp_handler.rb +142 -0
- data/lib/baykit/bayserver/docker/http/h2/header_block.rb +191 -0
- data/lib/baykit/bayserver/docker/http/h2/header_block_analyzer.rb +88 -0
- data/lib/baykit/bayserver/docker/http/h2/header_block_builder.rb +68 -0
- data/lib/baykit/bayserver/docker/http/h2/header_table.rb +167 -0
- data/lib/baykit/bayserver/docker/http/h2/huffman/hnode.rb +28 -0
- data/lib/baykit/bayserver/docker/http/h2/huffman/htree.rb +339 -0
- data/lib/baykit/bayserver/docker/http/h2/package.rb +17 -0
- data/lib/baykit/bayserver/docker/http/htp_docker.rb +23 -0
- data/lib/baykit/bayserver/docker/http/htp_port_docker.rb +107 -0
- data/lib/baykit/bayserver/docker/http/htp_warp_docker.rb +125 -0
- data/lib/baykit/bayserver/docker/http/htp_warp_ship_helper.rb +19 -0
- data/lib/baykit/bayserver/docker/http/package.rb +6 -0
- metadata +106 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'baykit/bayserver/protocol/protocol_exception'
|
2
|
+
|
3
|
+
require 'baykit/bayserver/docker/http/h2/package'
|
4
|
+
|
5
|
+
#
|
6
|
+
# HTTP/2 Setting payload format
|
7
|
+
#
|
8
|
+
# +-------------------------------+
|
9
|
+
# | Identifier (16) |
|
10
|
+
# +-------------------------------+-------------------------------+
|
11
|
+
# | Value (32) |
|
12
|
+
# +---------------------------------------------------------------+
|
13
|
+
#
|
14
|
+
#
|
15
|
+
module Baykit
|
16
|
+
module BayServer
|
17
|
+
module Docker
|
18
|
+
module Http
|
19
|
+
module H2
|
20
|
+
module Command
|
21
|
+
|
22
|
+
class CmdSettings < Baykit::BayServer::Docker::Http::H2::H2Command
|
23
|
+
include Baykit::BayServer::Protocol
|
24
|
+
include Baykit::BayServer::Docker::Http::H2
|
25
|
+
|
26
|
+
class Item
|
27
|
+
attr :id
|
28
|
+
attr :value
|
29
|
+
|
30
|
+
def initialize(id, value)
|
31
|
+
@id = id
|
32
|
+
@value = value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
HEADER_TABLE_SIZE = 0x1
|
37
|
+
ENABLE_PUSH = 0x2
|
38
|
+
MAX_CONCURRENT_STREAMS = 0x3
|
39
|
+
INITIAL_WINDOW_SIZE = 0x4
|
40
|
+
MAX_FRAME_SIZE = 0x5
|
41
|
+
MAX_HEADER_LIST_SIZE = 0x6
|
42
|
+
|
43
|
+
INIT_HEADER_TABLE_SIZE = 4096
|
44
|
+
INIT_ENABLE_PUSH = 1
|
45
|
+
INIT_MAX_CONCURRENT_STREAMS = -1
|
46
|
+
INIT_INITIAL_WINDOW_SIZE = 65535
|
47
|
+
INIT_MAX_FRAME_SIZE = 16384
|
48
|
+
INIT_MAX_HEADER_LIST_SIZE = -1
|
49
|
+
|
50
|
+
attr :items
|
51
|
+
|
52
|
+
def initialize(stream_id, flags=nil)
|
53
|
+
super(H2Type::SETTINGS, stream_id, flags)
|
54
|
+
@items = []
|
55
|
+
end
|
56
|
+
|
57
|
+
def unpack(pkt)
|
58
|
+
super
|
59
|
+
if @flags.ack?
|
60
|
+
return
|
61
|
+
end
|
62
|
+
|
63
|
+
acc = pkt.new_data_accessor()
|
64
|
+
pos = 0
|
65
|
+
while pos < pkt.data_len()
|
66
|
+
id = acc.get_short()
|
67
|
+
value = acc.get_int()
|
68
|
+
@items.append(Item.new(id, value))
|
69
|
+
pos += 6
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def pack(pkt)
|
74
|
+
if @flags.ack?
|
75
|
+
# do not pack payload
|
76
|
+
else
|
77
|
+
acc = pkt.new_data_accessor()
|
78
|
+
@items.each do |item|
|
79
|
+
acc.put_short(item.id)
|
80
|
+
acc.put_int(item.value)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
super
|
84
|
+
end
|
85
|
+
|
86
|
+
def handle(cmd_handler)
|
87
|
+
return cmd_handler.handle_settings(self)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'baykit/bayserver/docker/http/h2/package'
|
2
|
+
|
3
|
+
#
|
4
|
+
# HTTP/2 Window Update payload format
|
5
|
+
#
|
6
|
+
# +-+-------------------------------------------------------------+
|
7
|
+
# |R| Window Size Increment (31) |
|
8
|
+
# +-+-------------------------------------------------------------+
|
9
|
+
#
|
10
|
+
|
11
|
+
module Baykit
|
12
|
+
module BayServer
|
13
|
+
module Docker
|
14
|
+
module Http
|
15
|
+
module H2
|
16
|
+
module Command
|
17
|
+
|
18
|
+
class CmdWindowUpdate < Baykit::BayServer::Docker::Http::H2::H2Command
|
19
|
+
include Baykit::BayServer::Docker::Http::H2
|
20
|
+
|
21
|
+
attr_accessor :window_size_increment
|
22
|
+
|
23
|
+
def initialize(stream_id, flags=nil)
|
24
|
+
super(H2Type::WINDOW_UPDATE, stream_id, flags)
|
25
|
+
@items = []
|
26
|
+
end
|
27
|
+
|
28
|
+
def unpack(pkt)
|
29
|
+
super
|
30
|
+
acc = pkt.new_data_accessor()
|
31
|
+
val = acc.get_int()
|
32
|
+
@window_size_increment = H2Packet.extract_int31(val)
|
33
|
+
end
|
34
|
+
|
35
|
+
def pack(pkt)
|
36
|
+
acc = pkt.new_data_accessor()
|
37
|
+
acc.put_int(H2Packet.consolidate_flag_and_int32(0, @window_size_increment))
|
38
|
+
BayLog.trace("h2: Pack windowUpdate size=#{@window_size_increment}")
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
def handle(cmd_handler)
|
43
|
+
return cmd_handler.handle_window_update(self)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'baykit/bayserver/docker/http/h2/command/cmd_data'
|
2
|
+
require 'baykit/bayserver/docker/http/h2/command/cmd_go_away'
|
3
|
+
require 'baykit/bayserver/docker/http/h2/command/cmd_headers'
|
4
|
+
require 'baykit/bayserver/docker/http/h2/command/cmd_ping'
|
5
|
+
require 'baykit/bayserver/docker/http/h2/command/cmd_preface'
|
6
|
+
require 'baykit/bayserver/docker/http/h2/command/cmd_priority'
|
7
|
+
require 'baykit/bayserver/docker/http/h2/command/cmd_rst_stream'
|
8
|
+
require 'baykit/bayserver/docker/http/h2/command/cmd_settings'
|
9
|
+
require 'baykit/bayserver/docker/http/h2/command/cmd_window_update'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'baykit/bayserver/docker/http/h2/h2_flags'
|
2
|
+
|
3
|
+
module Baykit
|
4
|
+
module BayServer
|
5
|
+
module Docker
|
6
|
+
module Http
|
7
|
+
module H2
|
8
|
+
class H2Command < Baykit::BayServer::Protocol::Command
|
9
|
+
include Baykit::BayServer::Docker::Http
|
10
|
+
include Baykit::BayServer::Docker::Http::H2
|
11
|
+
|
12
|
+
attr :flags
|
13
|
+
attr_accessor :stream_id
|
14
|
+
|
15
|
+
def initialize(type, stream_id, flags=nil)
|
16
|
+
super type
|
17
|
+
@stream_id = stream_id
|
18
|
+
if flags == nil
|
19
|
+
@flags = H2Flags.new
|
20
|
+
else
|
21
|
+
@flags = flags
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def unpack(pkt)
|
26
|
+
@stream_id = pkt.stream_id
|
27
|
+
@flags = pkt.flags
|
28
|
+
end
|
29
|
+
|
30
|
+
def pack(pkt)
|
31
|
+
pkt.stream_id = @stream_id
|
32
|
+
pkt.flags = @flags
|
33
|
+
pkt.pack_header
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Baykit
|
2
|
+
module BayServer
|
3
|
+
module Docker
|
4
|
+
module Http
|
5
|
+
module H2
|
6
|
+
module H2CommandHandler
|
7
|
+
include Baykit::BayServer::Protocol::CommandHandler # implements
|
8
|
+
|
9
|
+
#
|
10
|
+
# abstract methods
|
11
|
+
#
|
12
|
+
# handle_preface(cmd)
|
13
|
+
# handle_data(cmd)
|
14
|
+
# handle_headers(cmd)
|
15
|
+
# handle_priority(cmd)
|
16
|
+
# handle_settings(cmd)
|
17
|
+
# handle_window_update(cmd)
|
18
|
+
# handle_go_away(cmd)
|
19
|
+
# handle_ping(cmd)
|
20
|
+
# handle_rst_stream(cmd)
|
21
|
+
#
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'baykit/bayserver/protocol/package'
|
2
|
+
require 'baykit/bayserver/agent/next_socket_action'
|
3
|
+
require 'baykit/bayserver/docker/http/h2/h2_type'
|
4
|
+
require 'baykit/bayserver/docker/http/h2/command/package'
|
5
|
+
|
6
|
+
module Baykit
|
7
|
+
module BayServer
|
8
|
+
module Docker
|
9
|
+
module Http
|
10
|
+
module H2
|
11
|
+
class H2CommandUnPacker < Baykit::BayServer::Protocol::CommandUnPacker
|
12
|
+
|
13
|
+
include Baykit::BayServer::Agent
|
14
|
+
include Baykit::BayServer::Docker::Http::H2::Command
|
15
|
+
|
16
|
+
attr :cmd_handler
|
17
|
+
|
18
|
+
def initialize(cmd_handler)
|
19
|
+
@cmd_handler = cmd_handler
|
20
|
+
end
|
21
|
+
|
22
|
+
def reset
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def packet_received(pkt)
|
27
|
+
BayLog.debug("h2: read packet type=%d strmid=%d len=%d flgs=%s", pkt.type, pkt.stream_id, pkt.data_len(), pkt.flags)
|
28
|
+
|
29
|
+
case pkt.type
|
30
|
+
when H2Type::PREFACE
|
31
|
+
cmd = CmdPreface.new(pkt.stream_id, pkt.flags)
|
32
|
+
|
33
|
+
when H2Type::HEADERS
|
34
|
+
cmd = CmdHeaders.new(pkt.stream_id, pkt.flags)
|
35
|
+
|
36
|
+
when H2Type::PRIORITY
|
37
|
+
cmd = CmdPriority.new(pkt.stream_id, pkt.flags)
|
38
|
+
|
39
|
+
when H2Type::SETTINGS
|
40
|
+
cmd = CmdSettings.new(pkt.stream_id, pkt.flags)
|
41
|
+
|
42
|
+
when H2Type::WINDOW_UPDATE
|
43
|
+
cmd = CmdWindowUpdate.new(pkt.stream_id, pkt.flags)
|
44
|
+
|
45
|
+
when H2Type::DATA
|
46
|
+
cmd = CmdData.new(pkt.stream_id, pkt.flags)
|
47
|
+
|
48
|
+
when H2Type::GOAWAY
|
49
|
+
cmd = CmdGoAway.new(pkt.stream_id, pkt.flags)
|
50
|
+
|
51
|
+
when H2Type::PING
|
52
|
+
cmd = CmdPing.new(pkt.stream_id, pkt.flags)
|
53
|
+
|
54
|
+
when H2Type::RST_STREAM
|
55
|
+
cmd = CmdRstStream.new(pkt.stream_id, pkt.flags)
|
56
|
+
|
57
|
+
else
|
58
|
+
reset()
|
59
|
+
raise RuntimeError.new("Invalid Packet: #{pkt}")
|
60
|
+
end
|
61
|
+
|
62
|
+
cmd.unpack pkt
|
63
|
+
return cmd.handle(@cmd_handler)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'baykit/bayserver/util/message'
|
2
|
+
require 'baykit/bayserver/util/locale'
|
3
|
+
|
4
|
+
module Baykit
|
5
|
+
module BayServer
|
6
|
+
module Docker
|
7
|
+
module Http
|
8
|
+
module H2
|
9
|
+
class H2ErrorCode < Baykit::BayServer::Util::Message
|
10
|
+
include Baykit::BayServer::Util
|
11
|
+
|
12
|
+
NO_ERROR = 0x0
|
13
|
+
PROTOCOL_ERROR = 0x1
|
14
|
+
INTERNAL_ERROR = 0x2
|
15
|
+
FLOW_CONTROL_ERROR = 0x3
|
16
|
+
SETTINGS_TIMEOUT = 0x4
|
17
|
+
STREAM_CLOSED = 0x5
|
18
|
+
FRAME_SIZE_ERROR = 0x6
|
19
|
+
REFUSED_STREAM = 0x7
|
20
|
+
CANCEL = 0x8
|
21
|
+
COMPRESSION_ERROR = 0x9
|
22
|
+
CONNECT_ERROR = 0xa
|
23
|
+
ENHANCE_YOUR_CALM = 0xb
|
24
|
+
INADEQUATE_SECURITY = 0xc
|
25
|
+
HTTP_1_1_REQUIRED = 0xd
|
26
|
+
|
27
|
+
class << self
|
28
|
+
attr :desc
|
29
|
+
attr :msg
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.initialized
|
33
|
+
@desc = {}
|
34
|
+
@msg = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.init
|
38
|
+
if(@msg != nil)
|
39
|
+
return
|
40
|
+
end
|
41
|
+
|
42
|
+
prefix = BayServer.bserv_lib + "/conf/h2_messages"
|
43
|
+
@msg = H2ErrorCode.new()
|
44
|
+
@msg.init(prefix, Locale.new('ja', 'JP'))
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Baykit
|
2
|
+
module BayServer
|
3
|
+
module Docker
|
4
|
+
module Http
|
5
|
+
module H2
|
6
|
+
class H2Flags
|
7
|
+
FLAGS_NONE = 0x0
|
8
|
+
FLAGS_ACK = 0x1
|
9
|
+
FLAGS_END_STREAM = 0x1
|
10
|
+
FLAGS_END_HEADERS = 0x4
|
11
|
+
FLAGS_PADDED = 0x8
|
12
|
+
FLAGS_PRIORITY = 0x20
|
13
|
+
|
14
|
+
attr :flags
|
15
|
+
|
16
|
+
def initialize(flags=FLAGS_NONE)
|
17
|
+
@flags = flags
|
18
|
+
end
|
19
|
+
|
20
|
+
def flag?(flag)
|
21
|
+
(flags & flag) != 0
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_flag(flag, val)
|
25
|
+
if val
|
26
|
+
@flags |= flag
|
27
|
+
else
|
28
|
+
@flags &= ~flag
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def ack?()
|
33
|
+
flag?(FLAGS_ACK)
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_ack(val)
|
37
|
+
set_flag(FLAGS_ACK, val)
|
38
|
+
end
|
39
|
+
|
40
|
+
def end_stream?
|
41
|
+
flag?(FLAGS_END_STREAM)
|
42
|
+
end
|
43
|
+
|
44
|
+
def set_end_stream(val)
|
45
|
+
set_flag(FLAGS_END_STREAM, val)
|
46
|
+
end
|
47
|
+
|
48
|
+
def end_headers?
|
49
|
+
flag?(FLAGS_END_HEADERS)
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_end_headers(val)
|
53
|
+
set_flag(FLAGS_END_HEADERS, val)
|
54
|
+
end
|
55
|
+
|
56
|
+
def padded?
|
57
|
+
flag?(FLAGS_PADDED)
|
58
|
+
end
|
59
|
+
|
60
|
+
def set_padded(val)
|
61
|
+
set_flag(FLAGS_PADDED, val)
|
62
|
+
end
|
63
|
+
|
64
|
+
def priority?
|
65
|
+
flag?(FLAGS_PRIORITY)
|
66
|
+
end
|
67
|
+
|
68
|
+
def set_priority(val)
|
69
|
+
set_flag(FLAGS_PRIORITY, val)
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_s()
|
73
|
+
@flags.to_s()
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|