Class: LibWebSocket::Handshake::Server
- Inherits:
-
LibWebSocket::Handshake
- Object
- LibWebSocket::Handshake
- LibWebSocket::Handshake::Server
- Defined in:
- lib/libwebsocket/handshake/server.rb
Overview
Construct or parse a server WebSocket handshake. This module is written for convenience, since using request and response directly requires the same code again and again.
SYNOPSIS
h = LibWebSocket::Handshake::Server.new
# Parse client request
h.parse \<<EOF
GET /demo HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: example.com
Origin: http://example.com
Sec-WebSocket-Key1: 18x 6]8vM;54 *(5: { U1]8 z [ 8
Sec-WebSocket-Key2: 1_ tx7X d < nw 334J702) 7]o}` 0
Tm[K T2u
EOF
h.error # Check if there were any errors
h.idone? # Returns true
# Create response
h.to_s # HTTP/1.1 101 WebSocket Protocol Handshake
# Upgrade: WebSocket
# Connection: Upgrade
# Sec-WebSocket-Origin: http://example.com
# Sec-WebSocket-Location: ws://example.com/demo
#
# fQJ,fN/4F4!~K~MH
Instance Attribute Summary
Attributes inherited from LibWebSocket::Handshake
Instance Method Summary collapse
-
#done? ⇒ Boolean
Check if request is correct and done.
-
#parse(opts) ⇒ Object
Parse client request.
-
#to_rack ⇒ Object
Create response in rack format.
-
#to_s ⇒ Object
Create response in string format.
Methods inherited from LibWebSocket::Handshake
Constructor Details
This class inherits a constructor from LibWebSocket::Handshake
Instance Method Details
#done? ⇒ Boolean
Check if request is correct and done
80 81 82 |
# File 'lib/libwebsocket/handshake/server.rb', line 80 def done? req.done? end |
#parse(opts) ⇒ Object
Parse client request
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/libwebsocket/handshake/server.rb', line 50 def parse(opts) req = self.req res = self.res unless req.done? unless req.parse(opts) self.error = req.error return end if req.done? res.version = req.version res.host = req.host # res.secure = req.secure res.resource_name = req.resource_name res.origin = req.origin if req.version > 75 res.number1 = req.number1 res.number2 = req.number2 res.challenge = req.challenge end end end return true end |
#to_rack ⇒ Object
Create response in rack format
108 109 110 |
# File 'lib/libwebsocket/handshake/server.rb', line 108 def to_rack res.to_rack end |
#to_s ⇒ Object
Create response in string format
93 94 95 |
# File 'lib/libwebsocket/handshake/server.rb', line 93 def to_s res.to_s end |