File: handshake_requests.rb

package info (click to toggle)
ruby-websocket 1.2.9-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 464 kB
  • sloc: ruby: 2,669; makefile: 4
file content (91 lines) | stat: -rw-r--r-- 3,205 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# frozen_string_literal: true

def client_handshake_75(args = {})
  <<-REQUEST
GET #{args[:path] || '/demo'}#{"?#{args[:query]}" if args[:query]} HTTP/1.1\r
Upgrade: WebSocket\r
Connection: Upgrade\r
Host: #{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}\r
Origin: http://example.com\r
#{(args[:headers] || {}).map { |key, value| "#{key}: #{value}\r\n" }.join('')}\r
  REQUEST
end

def server_handshake_75(args = {})
  <<-REQUEST
HTTP/1.1 101 Web Socket Protocol Handshake\r
Upgrade: WebSocket\r
Connection: Upgrade\r
#{(args[:headers] || {}).map { |key, value| "#{key}: #{value}\r\n" }.join('')}WebSocket-Origin: http://example.com\r
WebSocket-Location: ws#{args[:secure] ? 's' : ''}://#{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}#{args[:path] || '/demo'}\r
\r
  REQUEST
end

def client_handshake_76(args = {})
  request = <<-REQUEST
GET #{args[:path] || '/demo'}#{"?#{args[:query]}" if args[:query]} HTTP/1.1\r
Upgrade: WebSocket\r
Connection: Upgrade\r
Host: #{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}\r
Origin: http://example.com\r
#{(args[:headers] || {}).map { |key, value| "#{key}: #{value}\r\n" }.join('')}Sec-WebSocket-Key1: #{args[:key1] || '4 @1  46546xW%0l 1 5'}\r
Sec-WebSocket-Key2: #{args[:key2] || '12998 5 Y3 1  .P00'}\r
\r
#{args[:key3] || '^n:ds[4U'}
  REQUEST
  request[0..-2]
end

def server_handshake_76(args = {})
  request = <<-REQUEST
HTTP/1.1 101 WebSocket Protocol Handshake\r
Upgrade: WebSocket\r
Connection: Upgrade\r
#{(args[:headers] || {}).map { |key, value| "#{key}: #{value}\r\n" }.join('')}Sec-WebSocket-Origin: http://example.com\r
Sec-WebSocket-Location: ws#{args[:secure] ? 's' : ''}://#{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}#{args[:path] || '/demo'}\r
\r
#{args[:challenge] || "8jKS'y:G*Co,Wxa-"}
  REQUEST
  request[0..-2]
end

def client_handshake_04(args = {})
  <<-REQUEST
GET #{args[:path] || '/demo'}#{"?#{args[:query]}" if args[:query]} HTTP/1.1\r
Upgrade: websocket\r
Connection: Upgrade\r
Host: #{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}\r
#{(args[:headers] || {}).map { |key, value| "#{key}: #{value}\r\n" }.join('')}Sec-WebSocket-Origin: http://example.com\r
Sec-WebSocket-Version: #{args[:version] || '4'}\r
Sec-WebSocket-Key: #{args[:key] || 'dGhlIHNhbXBsZSBub25jZQ=='}\r
\r
  REQUEST
end

def server_handshake_04(args = {})
  <<-REQUEST
HTTP/1.1 101 Switching Protocols\r
Upgrade: websocket\r
Connection: Upgrade\r
#{(args[:headers] || {}).map { |key, value| "#{key}: #{value}\r\n" }.join('')}Sec-WebSocket-Accept: #{args[:accept] || 's3pPLMBiTxaQ9kYGzzhZRbK+xOo='}\r
\r
  REQUEST
end

def client_handshake_11(args = {})
  <<-REQUEST
GET #{args[:path] || '/demo'}#{"?#{args[:query]}" if args[:query]} HTTP/1.1\r
Upgrade: websocket\r
Connection: Upgrade\r
Host: #{args[:host] || 'example.com'}#{":#{args[:port]}" if args[:port]}\r
#{(args[:headers] || {}).map { |key, value| "#{key}: #{value}\r\n" }.join('')}Origin: http://example.com\r
Sec-WebSocket-Version: #{args[:version] || '4'}\r
Sec-WebSocket-Key: #{args[:key] || 'dGhlIHNhbXBsZSBub25jZQ=='}\r
\r
  REQUEST
end

def server_handshake_11(args = {})
  server_handshake_04(args)
end