@@ -211,12 +211,12 @@ def close(error = nil)
211211 end
212212
213213 def open!
214- if @state == :idle
215- @state = :open
216- else
214+ unless @state == :idle
217215 raise ProtocolError , "Cannot open connection in state: #{ @state } !"
218216 end
219217
218+ @state = :open
219+
220220 return self
221221 end
222222
@@ -231,7 +231,7 @@ def write_request(authority, method, path, version, headers)
231231
232232 def write_response ( version , status , headers , reason = Reason ::DESCRIPTIONS [ status ] )
233233 unless @state == :open or @state == :half_closed_remote
234- raise ProtocolError , "Cannot write response in #{ @state } !"
234+ raise ProtocolError , "Cannot write response in state: #{ @state } !"
235235 end
236236
237237 # Safari WebSockets break if no reason is given:
@@ -242,7 +242,7 @@ def write_response(version, status, headers, reason = Reason::DESCRIPTIONS[statu
242242
243243 def write_interim_response ( version , status , headers , reason = Reason ::DESCRIPTIONS [ status ] )
244244 unless @state == :open or @state == :half_closed_remote
245- raise ProtocolError , "Cannot write interim response in #{ @state } !"
245+ raise ProtocolError , "Cannot write interim response in state: #{ @state } !"
246246 end
247247
248248 @stream . write ( "#{ version } #{ status } #{ reason } \r \n " )
@@ -336,7 +336,7 @@ def read_response_line
336336
337337 def read_response ( method )
338338 unless @state == :open or @state == :half_closed_local
339- raise ProtocolError , "Cannot read response in #{ @state } !"
339+ raise ProtocolError , "Cannot read response in state: #{ @state } !"
340340 end
341341
342342 version , status , reason = read_response_line
@@ -381,7 +381,7 @@ def send_end_stream!
381381 elsif @state == :half_closed_remote
382382 self . close!
383383 else
384- raise ProtocolError , "Cannot send end stream in #{ @state } !"
384+ raise ProtocolError , "Cannot send end stream in state: #{ @state } !"
385385 end
386386 end
387387
@@ -590,7 +590,7 @@ def receive_end_stream!
590590 elsif @state == :half_closed_local
591591 self . close!
592592 else
593- raise ProtocolError , "Cannot receive end stream in #{ @state } !"
593+ raise ProtocolError , "Cannot receive end stream in state: #{ @state } !"
594594 end
595595 end
596596
0 commit comments