rfc-ws-client 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rfc-ws-client.rb CHANGED
@@ -5,7 +5,6 @@ require 'uri'
5
5
  require 'socket'
6
6
  require 'securerandom'
7
7
  require "digest/sha1"
8
- require 'rainbow'
9
8
  require 'base64'
10
9
 
11
10
  module RfcWebSocket
@@ -26,7 +25,6 @@ module RfcWebSocket
26
25
  OPCODE_CLOSE = 0x08
27
26
  OPCODE_PING = 0x09
28
27
  OPCODE_PONG = 0x0a
29
- DEBUG = false
30
28
 
31
29
  def initialize(uri, protocol = "")
32
30
  uri = URI.parse(uri) unless uri.is_a?(URI)
@@ -53,11 +51,11 @@ module RfcWebSocket
53
51
  write(handshake(host, path, request_key))
54
52
  flush()
55
53
 
56
- status_line = gets.chomp
54
+ status_line = @socket.gets.chomp
57
55
  raise WebSocketError.new("bad response: #{status_line}") unless status_line.start_with?("HTTP/1.1 101")
58
56
 
59
57
  header = {}
60
- while line = gets
58
+ while line = @socket.gets
61
59
  line.chomp!
62
60
  break if line.empty?
63
61
  if !(line =~ /\A(\S+): (.*)\z/n)
@@ -84,7 +82,6 @@ module RfcWebSocket
84
82
  # Loop until something returns
85
83
  while true
86
84
  b1, b2 = read(2).unpack("CC")
87
- puts "b1: #{b1.to_s(2).rjust(8, "0")}, b2: #{b2.to_s(2).rjust(8, "0")}" if DEBUG
88
85
  # first byte
89
86
  fin = (b1 & 0x80) != 0
90
87
  raise WebSocketError.new("reserved bits must be 0") if (b1 & 0b01110000) != 0
@@ -175,14 +172,7 @@ module RfcWebSocket
175
172
 
176
173
  private
177
174
 
178
- def gets(delim = $/)
179
- line = @socket.gets(delim)
180
- print line.color(:green) if DEBUG
181
- line
182
- end
183
-
184
175
  def write(data)
185
- print data.color(:yellow) if DEBUG
186
176
  @socket.write(data)
187
177
  @socket.flush
188
178
  end
@@ -190,7 +180,6 @@ module RfcWebSocket
190
180
  def read(num_bytes)
191
181
  str = @socket.read(num_bytes)
192
182
  if str && str.bytesize == num_bytes
193
- print str.color(:green) if DEBUG
194
183
  str
195
184
  else
196
185
  raise(EOFError)
@@ -257,12 +246,8 @@ module RfcWebSocket
257
246
  end
258
247
  end
259
248
 
260
- def force_utf8(str)
261
- str.force_encoding("UTF-8")
262
- end
263
-
264
249
  def valid_utf8?(str)
265
- force_utf8(str).valid_encoding?
250
+ str.force_encoding("UTF-8").valid_encoding?
266
251
  end
267
252
  end
268
253
  end
@@ -1,3 +1,3 @@
1
1
  module RfcWebSocket
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfc-ws-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-19 00:00:00.000000000 Z
12
+ date: 2012-11-20 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: