Skip to content

Commit

Permalink
use url-safe (RFC 4648) base64 decode
Browse files Browse the repository at this point in the history
  • Loading branch information
igrigorik committed Dec 27, 2015
1 parent a5a081c commit 9579e7d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
3 changes: 1 addition & 2 deletions example/upgrade_server.rb
@@ -1,7 +1,6 @@
require_relative 'helper'
require 'http_parser'
require 'base64'
require 'pry'

options = { port: 8080 }
OptionParser.new do |opts|
Expand Down Expand Up @@ -51,7 +50,7 @@ def <<(data)

@sock.write UPGRADE_RESPONSE

settings = headers['HTTP2-Settings']
settings = headers['http2-settings']
request = {
':scheme' => 'http',
':method' => @parser.http_method,
Expand Down
7 changes: 3 additions & 4 deletions lib/http/2/framer.rb
Expand Up @@ -370,10 +370,9 @@ def parse(buf)
# NOTE: frame[:length] might not match the number of frame[:payload]
# because unknown extensions are ignored.
frame[:payload] = []
# TODO: is this a valid check? It fails on HTTP2-Upgrade data
# unless frame[:length] % 6 == 0
# fail ProtocolError, 'Invalid settings payload length'
# end
unless frame[:length] % 6 == 0
fail ProtocolError, 'Invalid settings payload length'
end

if frame[:stream] != 0
fail ProtocolError, "Invalid stream ID (#{frame[:stream]})"
Expand Down
4 changes: 2 additions & 2 deletions lib/http/2/server.rb
Expand Up @@ -71,9 +71,9 @@ def upgrade(settings, headers, body)
receive(CONNECTION_PREFACE_MAGIC)

# Process received HTTP2-Settings payload
buf = HTTP2::Buffer.new Base64.decode64(settings)
buf = HTTP2::Buffer.new Base64.urlsafe_decode64(settings)
buf.prepend(@framer.common_header(
length: buf.length,
length: buf.bytesize,
type: :settings,
stream: 0,
flags: []
Expand Down

0 comments on commit 9579e7d

Please sign in to comment.