Skip to content

Commit

Permalink
Formatting change: {...} should have spaces inside the braces
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoglan committed Jun 11, 2019
1 parent 9233497 commit e568366
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 40 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,33 +274,33 @@ Note that most of these methods are commands: if they produce data that should
be sent over the socket, they will give this to you by calling
`socket.write(string)`.

#### `driver.on :open, -> (event) { }`
#### `driver.on :open, -> (event) {}`

Adds a callback block to execute when the socket becomes open.

#### `driver.on :message, -> (event) { }`
#### `driver.on :message, -> (event) {}`

Adds a callback block to execute when a message is received. `event` will have a
`data` attribute containing either a string in the case of a text message or an
array of integers in the case of a binary message.

#### `driver.on :error, -> (event) { }`
#### `driver.on :error, -> (event) {}`

Adds a callback to execute when a protocol error occurs due to the other peer
sending an invalid byte sequence. `event` will have a `message` attribute
describing the error.

#### `driver.on :close, -> (event) { }`
#### `driver.on :close, -> (event) {}`

Adds a callback block to execute when the socket becomes closed. The `event`
object has `code` and `reason` attributes.

#### `driver.on :ping, -> (event) { }`
#### `driver.on :ping, -> (event) {}`

Adds a callback block to execute when a ping is received. You do not need to
handle this by sending a pong frame yourself; the driver handles this for you.

#### `driver.on :pong, -> (event) { }`
#### `driver.on :pong, -> (event) {}`

Adds a callback block to execute when a pong is received. If this was in
response to a ping you sent, you can also handle this event via the
Expand Down
2 changes: 1 addition & 1 deletion examples/tcp_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'uri'

class WSClient
DEFAULT_PORTS = {'ws' => 80, 'wss' => 443}
DEFAULT_PORTS = { 'ws' => 80, 'wss' => 443 }

attr_reader :url, :thread

Expand Down
2 changes: 1 addition & 1 deletion lib/websocket/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def self.encode(string, encoding = nil)
def self.validate_options(options, valid_keys)
options.keys.each do |key|
unless valid_keys.include?(key)
raise ConfigurationError, "Unrecognized option: #{key.inspect}"
raise ConfigurationError, "Unrecognized option: #{ key.inspect }"
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions lib/websocket/driver/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def initialize(socket, options = {})

uri = URI.parse(@socket.url)
unless VALID_SCHEMES.include?(uri.scheme)
raise URIError, "#{socket.url} is not a valid WebSocket URL"
raise URIError, "#{ socket.url } is not a valid WebSocket URL"
end

host = uri.host + (uri.port ? ":#{uri.port}" : '')
host = uri.host + (uri.port ? ":#{ uri.port }" : '')
path = (uri.path == '') ? '/' : uri.path
@pathname = path + (uri.query ? '?' + uri.query : '')

Expand All @@ -44,7 +44,7 @@ def initialize(socket, options = {})
end

def version
"hybi-#{VERSION}"
"hybi-#{ VERSION }"
end

def proxy(origin, options = {})
Expand Down Expand Up @@ -73,19 +73,19 @@ def parse(chunk)
parse(@http.body)
end

private
private

def handshake_request
extensions = @extensions.generate_offer
@headers['Sec-WebSocket-Extensions'] = extensions if extensions

start = "GET #{@pathname} HTTP/1.1"
start = "GET #{ @pathname } HTTP/1.1"
headers = [start, @headers.to_s, '']
headers.join("\r\n")
end

def fail_handshake(message)
message = "Error during WebSocket handshake: #{message}"
message = "Error during WebSocket handshake: #{ message }"
@ready_state = 3
emit(:error, ProtocolError.new(message))
emit(:close, CloseEvent.new(ERRORS[:protocol_error], message))
Expand All @@ -96,7 +96,7 @@ def validate_handshake
@headers = Headers.new(@http.headers)

unless @http.code == 101
return fail_handshake("Unexpected response code: #{@http.code}")
return fail_handshake("Unexpected response code: #{ @http.code }")
end

upgrade = @http['Upgrade'] || ''
Expand Down
2 changes: 1 addition & 1 deletion lib/websocket/driver/headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def []=(name, value)
return if value.nil?
key = HTTP.normalize_header(name)
return unless @sent.add?(key) or ALLOWED_DUPLICATES.include?(key)
@lines << "#{name.strip}: #{value.to_s.strip}\r\n"
@lines << "#{ name.strip }: #{ value.to_s.strip }\r\n"
end

def inspect
Expand Down
18 changes: 9 additions & 9 deletions lib/websocket/driver/hybi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def self.generate_accept(key)
MIN_RESERVED_ERROR = 3000
MAX_RESERVED_ERROR = 4999

PACK_FORMATS = {2 => 'n', 8 => 'Q>'}
PACK_FORMATS = { 2 => 'n', 8 => 'Q>' }

def initialize(socket, options = {})
super
Expand All @@ -78,7 +78,7 @@ def initialize(socket, options = {})
end

def version
"hybi-#{VERSION}"
"hybi-#{ VERSION }"
end

def add_extension(extension)
Expand Down Expand Up @@ -228,7 +228,7 @@ def handshake_response
version = @socket.env['HTTP_SEC_WEBSOCKET_VERSION']

unless version == VERSION
raise ProtocolError.new("Unsupported WebSocket version: #{VERSION}")
raise ProtocolError.new("Unsupported WebSocket version: #{ VERSION }")
end

unless sec_key
Expand Down Expand Up @@ -281,17 +281,17 @@ def parse_opcode(octet)

unless @extensions.valid_frame_rsv?(@frame)
return fail(:protocol_error,
"One or more reserved bits are on: reserved1 = #{@frame.rsv1 ? 1 : 0}" +
", reserved2 = #{@frame.rsv2 ? 1 : 0 }" +
", reserved3 = #{@frame.rsv3 ? 1 : 0 }")
"One or more reserved bits are on: reserved1 = #{ @frame.rsv1 ? 1 : 0 }" +
", reserved2 = #{ @frame.rsv2 ? 1 : 0 }" +
", reserved3 = #{ @frame.rsv3 ? 1 : 0 }")
end

unless OPCODES.values.include?(@frame.opcode)
return fail(:protocol_error, "Unrecognized frame opcode: #{@frame.opcode}")
return fail(:protocol_error, "Unrecognized frame opcode: #{ @frame.opcode }")
end

unless MESSAGE_OPCODES.include?(@frame.opcode) or @frame.final
return fail(:protocol_error, "Received fragmented control frame: opcode = #{@frame.opcode}")
return fail(:protocol_error, "Received fragmented control frame: opcode = #{ @frame.opcode }")
end

if @message and OPENING_OPCODES.include?(@frame.opcode)
Expand Down Expand Up @@ -321,7 +321,7 @@ def parse_extended_length(buffer)
@stage = @frame.masked ? 3 : 4

unless MESSAGE_OPCODES.include?(@frame.opcode) or @frame.length <= 125
return fail(:protocol_error, "Received control frame having too long payload: #{@frame.length}")
return fail(:protocol_error, "Received control frame having too long payload: #{ @frame.length }")
end

return unless check_frame_length
Expand Down
8 changes: 4 additions & 4 deletions lib/websocket/driver/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Driver
class Proxy
include EventEmitter

PORTS = {'ws' => 80, 'wss' => 443}
PORTS = { 'ws' => 80, 'wss' => 443 }

attr_reader :status, :headers

Expand All @@ -20,7 +20,7 @@ def initialize(client, origin, options)
@state = 0

@headers = Headers.new
@headers['Host'] = @origin.host + (@origin.port ? ":#{@origin.port}" : '')
@headers['Host'] = @origin.host + (@origin.port ? ":#{ @origin.port }" : '')
@headers['Connection'] = 'keep-alive'
@headers['Proxy-Connection'] = 'keep-alive'

Expand All @@ -41,7 +41,7 @@ def start
@state = 1

port = @origin.port || PORTS[@origin.scheme]
start = "CONNECT #{@origin.host}:#{port} HTTP/1.1"
start = "CONNECT #{ @origin.host }:#{ port } HTTP/1.1"
headers = [start, @headers.to_s, '']

@socket.write(headers.join("\r\n"))
Expand All @@ -58,7 +58,7 @@ def parse(chunk)
if @status == 200
emit(:connect, ConnectEvent.new)
else
message = "Can't establish a connection to the server at #{@socket.url}"
message = "Can't establish a connection to the server at #{ @socket.url }"
emit(:error, ProtocolError.new(message))
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/websocket/driver/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def env
def url
return nil unless e = env

url = "ws://#{e['HTTP_HOST']}"
url = "ws://#{ e['HTTP_HOST'] }"
url << e['PATH_INFO']
url << "?#{e['QUERY_STRING']}" unless e['QUERY_STRING'] == ''
url << "?#{ e['QUERY_STRING'] }" unless e['QUERY_STRING'] == ''
url
end

Expand Down
4 changes: 2 additions & 2 deletions lib/websocket/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def complete
super
@headers.each do |name, value|
rack_name = name.upcase.gsub(/-/, '_')
rack_name = "HTTP_#{rack_name}" unless RESERVED_HEADERS.include?(name)
rack_name = "HTTP_#{ rack_name }" unless RESERVED_HEADERS.include?(name)
@env[rack_name] = value
end
if host = @env['HTTP_HOST']
uri = URI.parse("http://#{host}")
uri = URI.parse("http://#{ host }")
@env['SERVER_NAME'] = uri.host
@env['SERVER_PORT'] = uri.port.to_s
end
Expand Down
12 changes: 6 additions & 6 deletions spec/websocket/driver/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

let :options do
{:protocols => protocols}
{ :protocols => protocols }
end

let :protocols do
Expand Down Expand Up @@ -65,7 +65,7 @@
describe :start do
it "writes the handshake request to the socket" do
expect(socket).to receive(:write).with(
"GET /socket HTTP/1.1\r\n" +
"GET /socket HTTP/1.1\r\n" +
"Host: www.example.com\r\n" +
"Upgrade: websocket\r\n" +
"Connection: Upgrade\r\n" +
Expand All @@ -84,7 +84,7 @@

it "writes the handshake with Sec-WebSocket-Protocol" do
expect(socket).to receive(:write).with(
"GET /socket HTTP/1.1\r\n" +
"GET /socket HTTP/1.1\r\n" +
"Host: www.example.com\r\n" +
"Upgrade: websocket\r\n" +
"Connection: Upgrade\r\n" +
Expand All @@ -101,7 +101,7 @@

it "writes the handshake with Sec-WebSocket-Protocol" do
expect(socket).to receive(:write).with(
"GET /socket HTTP/1.1\r\n" +
"GET /socket HTTP/1.1\r\n" +
"Host: www.example.com\r\n" +
"Upgrade: websocket\r\n" +
"Connection: Upgrade\r\n" +
Expand All @@ -128,7 +128,7 @@

it "writes the handshake with custom headers" do
expect(socket).to receive(:write).with(
"GET /socket HTTP/1.1\r\n" +
"GET /socket HTTP/1.1\r\n" +
"Host: www.example.com\r\n" +
"Upgrade: websocket\r\n" +
"Connection: Upgrade\r\n" +
Expand Down Expand Up @@ -272,7 +272,7 @@
expect(driver.state).to eq :closed
end
end

describe "with a bad Accept header" do
before do
resp = response.gsub(/QV3/, "wrong")
Expand Down
2 changes: 1 addition & 1 deletion spec/websocket/driver/hybi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
end

let :options do
{:masking => false}
{ :masking => false }
end

let :socket do
Expand Down

0 comments on commit e568366

Please sign in to comment.