diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-10-29 14:56:04 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-10-29 14:56:04 +0900 |
commit | e57ddcaa08fb046328c37c6473803b479636cfec (patch) | |
tree | 9c4c1bd81786235032319858754b6012aaab543a | |
parent | b76fb6e5ec81ea9142eb6479a9f05b0b45b75184 (diff) | |
download | plum-e57ddcaa08fb046328c37c6473803b479636cfec.tar.gz |
stream: refactor
-rw-r--r-- | lib/plum/stream.rb | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/lib/plum/stream.rb b/lib/plum/stream.rb index e67d80e..63dea66 100644 --- a/lib/plum/stream.rb +++ b/lib/plum/stream.rb @@ -112,40 +112,35 @@ module Plum end if frame.padded? - padding_length = frame.payload.uint8(0) + padding_length = frame.payload.uint8 if padding_length >= frame.length raise ConnectionError.new(:protocol_error, "padding is too long") end - body = frame.payload.byteslice(1, frame.length - padding_length - 1) + callback(:data, frame.payload.byteslice(1, frame.length - padding_length - 1)) else - body = frame.payload + callback(:data, frame.payload) end - callback(:data, body) receive_end_stream if frame.end_stream? end def receive_complete_headers(frames) first = frames.shift - payload = first.payload - first_length = first.length - padding_length = 0 if first.padded? padding_length = payload.uint8 - first_length -= 1 + padding_length - payload = payload.byteslice(1, first_length) + payload = payload.byteslice(1, payload.bytesize - padding_length - 1) else + padding_length = 0 payload = payload.dup end if first.priority? receive_priority_payload(payload.byteshift(5)) - first_length -= 5 end - if padding_length > first_length + if padding_length > payload.bytesize raise ConnectionError.new(:protocol_error, "padding is too long") end |