slidge-whatsapp 0.3.7__cp312-cp312-manylinux_2_41_aarch64.whl → 0.3.8__cp312-cp312-manylinux_2_41_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. slidge_whatsapp/config.py +7 -2
  2. slidge_whatsapp/contact.py +3 -2
  3. slidge_whatsapp/event.go +14 -9
  4. slidge_whatsapp/gateway.go +7 -1
  5. slidge_whatsapp/generated/_whatsapp.cpython-312-aarch64-linux-gnu.h +182 -178
  6. slidge_whatsapp/generated/_whatsapp.cpython-312-aarch64-linux-gnu.so +0 -0
  7. slidge_whatsapp/generated/build.py +146 -142
  8. slidge_whatsapp/generated/whatsapp.c +1456 -1376
  9. slidge_whatsapp/generated/whatsapp.go +1069 -1045
  10. slidge_whatsapp/generated/whatsapp.py +1324 -1298
  11. slidge_whatsapp/generated/whatsapp_go.h +182 -178
  12. slidge_whatsapp/go.mod +6 -6
  13. slidge_whatsapp/go.sum +12 -12
  14. slidge_whatsapp/group.py +25 -0
  15. slidge_whatsapp/session.go +69 -67
  16. slidge_whatsapp/session.py +11 -1
  17. slidge_whatsapp/vendor/github.com/coder/websocket/LICENSE.txt +13 -0
  18. slidge_whatsapp/vendor/github.com/coder/websocket/Makefile +18 -0
  19. slidge_whatsapp/vendor/github.com/coder/websocket/README.md +162 -0
  20. slidge_whatsapp/vendor/github.com/coder/websocket/accept.go +378 -0
  21. slidge_whatsapp/vendor/github.com/coder/websocket/close.go +335 -0
  22. slidge_whatsapp/vendor/github.com/coder/websocket/compress.go +234 -0
  23. slidge_whatsapp/vendor/github.com/coder/websocket/conn.go +306 -0
  24. slidge_whatsapp/vendor/github.com/coder/websocket/dial.go +347 -0
  25. slidge_whatsapp/vendor/github.com/coder/websocket/doc.go +33 -0
  26. slidge_whatsapp/vendor/github.com/coder/websocket/errors.go +8 -0
  27. slidge_whatsapp/vendor/github.com/coder/websocket/frame.go +173 -0
  28. slidge_whatsapp/vendor/github.com/coder/websocket/hijack.go +33 -0
  29. slidge_whatsapp/vendor/github.com/coder/websocket/internal/bpool/bpool.go +25 -0
  30. slidge_whatsapp/vendor/github.com/coder/websocket/internal/errd/wrap.go +14 -0
  31. slidge_whatsapp/vendor/github.com/coder/websocket/internal/util/util.go +15 -0
  32. slidge_whatsapp/vendor/github.com/coder/websocket/internal/wsjs/wsjs_js.go +169 -0
  33. slidge_whatsapp/vendor/github.com/coder/websocket/mask.go +128 -0
  34. slidge_whatsapp/vendor/github.com/coder/websocket/mask_amd64.s +127 -0
  35. slidge_whatsapp/vendor/github.com/coder/websocket/mask_arm64.s +72 -0
  36. slidge_whatsapp/vendor/github.com/coder/websocket/mask_asm.go +26 -0
  37. slidge_whatsapp/vendor/github.com/coder/websocket/mask_go.go +7 -0
  38. slidge_whatsapp/vendor/github.com/coder/websocket/netconn.go +233 -0
  39. slidge_whatsapp/vendor/github.com/coder/websocket/netconn_js.go +11 -0
  40. slidge_whatsapp/vendor/github.com/coder/websocket/netconn_notjs.go +19 -0
  41. slidge_whatsapp/vendor/github.com/coder/websocket/read.go +540 -0
  42. slidge_whatsapp/vendor/github.com/coder/websocket/stringer.go +91 -0
  43. slidge_whatsapp/vendor/github.com/coder/websocket/write.go +384 -0
  44. slidge_whatsapp/vendor/github.com/coder/websocket/ws_js.go +598 -0
  45. slidge_whatsapp/vendor/github.com/ebitengine/purego/func.go +1 -1
  46. slidge_whatsapp/vendor/github.com/ebitengine/purego/struct_amd64.go +1 -1
  47. slidge_whatsapp/vendor/github.com/ebitengine/purego/struct_arm64.go +3 -1
  48. slidge_whatsapp/vendor/github.com/ebitengine/purego/struct_loong64.go +1 -1
  49. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/directive.go +3 -0
  50. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/selection.go +3 -0
  51. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/value.go +4 -3
  52. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate/encode.go +3 -0
  53. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate.go +18 -4
  54. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/broadcast.go +3 -3
  55. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/call.go +6 -4
  56. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/client.go +90 -80
  57. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/connectionevents.go +14 -11
  58. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/download.go +4 -1
  59. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/group.go +47 -48
  60. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/handshake.go +3 -2
  61. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/internals.go +79 -75
  62. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/keepalive.go +8 -6
  63. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/mediaconn.go +1 -2
  64. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/mediaretry.go +2 -2
  65. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/message.go +42 -40
  66. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/newsletter.go +35 -32
  67. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/notification.go +2 -3
  68. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/pair-code.go +2 -4
  69. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/pair.go +19 -19
  70. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/prekeys.go +9 -8
  71. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/presence.go +9 -9
  72. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/privacysettings.go +4 -5
  73. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloAddMessage/InstamadilloAddMessage.pb.go +1 -1
  74. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeActionLog/InstamadilloCoreTypeActionLog.pb.go +1 -1
  75. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeAdminMessage/InstamadilloCoreTypeAdminMessage.pb.go +1 -1
  76. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeCollection/InstamadilloCoreTypeCollection.pb.go +1 -1
  77. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeLink/InstamadilloCoreTypeLink.pb.go +1 -1
  78. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeMedia/InstamadilloCoreTypeMedia.pb.go +1 -1
  79. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeText/InstamadilloCoreTypeText.pb.go +1 -1
  80. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloDeleteMessage/InstamadilloDeleteMessage.pb.go +1 -1
  81. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloSupplementMessage/InstamadilloSupplementMessage.pb.go +1 -1
  82. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloTransportPayload/InstamadilloTransportPayload.pb.go +1 -1
  83. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloXmaContentRef/InstamadilloXmaContentRef.pb.go +1 -1
  84. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waAICommon/WAAICommon.pb.go +1145 -335
  85. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waAICommon/WAAICommon.proto +78 -0
  86. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waAdv/WAAdv.pb.go +1 -1
  87. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waArmadilloApplication/WAArmadilloApplication.pb.go +1 -1
  88. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waArmadilloXMA/WAArmadilloXMA.pb.go +1 -1
  89. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCert/WACert.pb.go +1 -1
  90. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waChatLockSettings/WAProtobufsChatLockSettings.pb.go +1 -1
  91. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCommon/WACommon.pb.go +1 -1
  92. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCompanionReg/WACompanionReg.pb.go +22 -4
  93. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCompanionReg/WACompanionReg.proto +2 -0
  94. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waConsumerApplication/WAConsumerApplication.pb.go +1 -1
  95. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waDeviceCapabilities/WAProtobufsDeviceCapabilities.pb.go +104 -30
  96. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waDeviceCapabilities/WAProtobufsDeviceCapabilities.proto +7 -0
  97. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waE2E/WAWebProtobufsE2E.pb.go +1037 -963
  98. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waE2E/WAWebProtobufsE2E.proto +15 -8
  99. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waHistorySync/WAWebProtobufsHistorySync.pb.go +1 -1
  100. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waLidMigrationSyncPayload/WAWebProtobufLidMigrationSyncPayload.pb.go +1 -1
  101. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMediaTransport/WAMediaTransport.pb.go +1 -1
  102. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMmsRetry/WAMmsRetry.pb.go +1 -1
  103. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMsgApplication/WAMsgApplication.pb.go +1 -1
  104. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMsgTransport/WAMsgTransport.pb.go +1 -1
  105. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMultiDevice/WAMultiDevice.pb.go +1 -1
  106. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waServerSync/WAServerSync.pb.go +1 -1
  107. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waStatusAttributions/WAStatusAttributions.pb.go +40 -35
  108. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waStatusAttributions/WAStatusAttributions.proto +1 -0
  109. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waSyncAction/WASyncAction.pb.go +921 -653
  110. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waSyncAction/WASyncAction.proto +44 -15
  111. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waUserPassword/WAProtobufsUserPassword.pb.go +1 -1
  112. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waVnameCert/WAWebProtobufsVnameCert.pb.go +1 -1
  113. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWa6/WAWebProtobufsWa6.pb.go +9 -5
  114. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWa6/WAWebProtobufsWa6.proto +1 -0
  115. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWeb/WAWebProtobufsWeb.pb.go +193 -115
  116. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWeb/WAWebProtobufsWeb.proto +9 -0
  117. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/push.go +2 -4
  118. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/receipt.go +12 -12
  119. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/request.go +25 -19
  120. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/retry.go +2 -2
  121. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/send.go +43 -27
  122. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/sendfb.go +4 -4
  123. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/socket/constants.go +1 -1
  124. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/socket/framesocket.go +43 -56
  125. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/socket/noisehandshake.go +9 -3
  126. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/socket/noisesocket.go +36 -22
  127. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/clientpayload.go +24 -4
  128. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/store.go +12 -0
  129. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/events/appstate.go +2 -1
  130. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/upload.go +1 -1
  131. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/user.go +79 -40
  132. slidge_whatsapp/vendor/golang.org/x/sys/unix/mkerrors.sh +2 -0
  133. slidge_whatsapp/vendor/golang.org/x/sys/unix/syscall_linux.go +6 -0
  134. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux.go +359 -0
  135. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsyscall_linux.go +10 -0
  136. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux.go +31 -0
  137. slidge_whatsapp/vendor/golang.org/x/sys/windows/syscall_windows.go +15 -0
  138. slidge_whatsapp/vendor/golang.org/x/sys/windows/types_windows.go +76 -0
  139. slidge_whatsapp/vendor/golang.org/x/sys/windows/zsyscall_windows.go +37 -0
  140. slidge_whatsapp/vendor/modules.txt +12 -8
  141. {slidge_whatsapp-0.3.7.dist-info → slidge_whatsapp-0.3.8.dist-info}/METADATA +1 -1
  142. {slidge_whatsapp-0.3.7.dist-info → slidge_whatsapp-0.3.8.dist-info}/RECORD +145 -136
  143. slidge_whatsapp/vendor/github.com/gorilla/websocket/.gitignore +0 -25
  144. slidge_whatsapp/vendor/github.com/gorilla/websocket/AUTHORS +0 -9
  145. slidge_whatsapp/vendor/github.com/gorilla/websocket/LICENSE +0 -22
  146. slidge_whatsapp/vendor/github.com/gorilla/websocket/README.md +0 -33
  147. slidge_whatsapp/vendor/github.com/gorilla/websocket/client.go +0 -434
  148. slidge_whatsapp/vendor/github.com/gorilla/websocket/compression.go +0 -148
  149. slidge_whatsapp/vendor/github.com/gorilla/websocket/conn.go +0 -1238
  150. slidge_whatsapp/vendor/github.com/gorilla/websocket/doc.go +0 -227
  151. slidge_whatsapp/vendor/github.com/gorilla/websocket/join.go +0 -42
  152. slidge_whatsapp/vendor/github.com/gorilla/websocket/json.go +0 -60
  153. slidge_whatsapp/vendor/github.com/gorilla/websocket/mask.go +0 -55
  154. slidge_whatsapp/vendor/github.com/gorilla/websocket/mask_safe.go +0 -16
  155. slidge_whatsapp/vendor/github.com/gorilla/websocket/prepared.go +0 -102
  156. slidge_whatsapp/vendor/github.com/gorilla/websocket/proxy.go +0 -77
  157. slidge_whatsapp/vendor/github.com/gorilla/websocket/server.go +0 -365
  158. slidge_whatsapp/vendor/github.com/gorilla/websocket/tls_handshake.go +0 -21
  159. slidge_whatsapp/vendor/github.com/gorilla/websocket/tls_handshake_116.go +0 -21
  160. slidge_whatsapp/vendor/github.com/gorilla/websocket/util.go +0 -298
  161. slidge_whatsapp/vendor/github.com/gorilla/websocket/x_net_proxy.go +0 -473
  162. {slidge_whatsapp-0.3.7.dist-info → slidge_whatsapp-0.3.8.dist-info}/WHEEL +0 -0
  163. {slidge_whatsapp-0.3.7.dist-info → slidge_whatsapp-0.3.8.dist-info}/entry_points.txt +0 -0
  164. {slidge_whatsapp-0.3.7.dist-info → slidge_whatsapp-0.3.8.dist-info}/licenses/LICENSE +0 -0
@@ -1,365 +0,0 @@
1
- // Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2
- // Use of this source code is governed by a BSD-style
3
- // license that can be found in the LICENSE file.
4
-
5
- package websocket
6
-
7
- import (
8
- "bufio"
9
- "errors"
10
- "io"
11
- "net/http"
12
- "net/url"
13
- "strings"
14
- "time"
15
- )
16
-
17
- // HandshakeError describes an error with the handshake from the peer.
18
- type HandshakeError struct {
19
- message string
20
- }
21
-
22
- func (e HandshakeError) Error() string { return e.message }
23
-
24
- // Upgrader specifies parameters for upgrading an HTTP connection to a
25
- // WebSocket connection.
26
- //
27
- // It is safe to call Upgrader's methods concurrently.
28
- type Upgrader struct {
29
- // HandshakeTimeout specifies the duration for the handshake to complete.
30
- HandshakeTimeout time.Duration
31
-
32
- // ReadBufferSize and WriteBufferSize specify I/O buffer sizes in bytes. If a buffer
33
- // size is zero, then buffers allocated by the HTTP server are used. The
34
- // I/O buffer sizes do not limit the size of the messages that can be sent
35
- // or received.
36
- ReadBufferSize, WriteBufferSize int
37
-
38
- // WriteBufferPool is a pool of buffers for write operations. If the value
39
- // is not set, then write buffers are allocated to the connection for the
40
- // lifetime of the connection.
41
- //
42
- // A pool is most useful when the application has a modest volume of writes
43
- // across a large number of connections.
44
- //
45
- // Applications should use a single pool for each unique value of
46
- // WriteBufferSize.
47
- WriteBufferPool BufferPool
48
-
49
- // Subprotocols specifies the server's supported protocols in order of
50
- // preference. If this field is not nil, then the Upgrade method negotiates a
51
- // subprotocol by selecting the first match in this list with a protocol
52
- // requested by the client. If there's no match, then no protocol is
53
- // negotiated (the Sec-Websocket-Protocol header is not included in the
54
- // handshake response).
55
- Subprotocols []string
56
-
57
- // Error specifies the function for generating HTTP error responses. If Error
58
- // is nil, then http.Error is used to generate the HTTP response.
59
- Error func(w http.ResponseWriter, r *http.Request, status int, reason error)
60
-
61
- // CheckOrigin returns true if the request Origin header is acceptable. If
62
- // CheckOrigin is nil, then a safe default is used: return false if the
63
- // Origin request header is present and the origin host is not equal to
64
- // request Host header.
65
- //
66
- // A CheckOrigin function should carefully validate the request origin to
67
- // prevent cross-site request forgery.
68
- CheckOrigin func(r *http.Request) bool
69
-
70
- // EnableCompression specify if the server should attempt to negotiate per
71
- // message compression (RFC 7692). Setting this value to true does not
72
- // guarantee that compression will be supported. Currently only "no context
73
- // takeover" modes are supported.
74
- EnableCompression bool
75
- }
76
-
77
- func (u *Upgrader) returnError(w http.ResponseWriter, r *http.Request, status int, reason string) (*Conn, error) {
78
- err := HandshakeError{reason}
79
- if u.Error != nil {
80
- u.Error(w, r, status, err)
81
- } else {
82
- w.Header().Set("Sec-Websocket-Version", "13")
83
- http.Error(w, http.StatusText(status), status)
84
- }
85
- return nil, err
86
- }
87
-
88
- // checkSameOrigin returns true if the origin is not set or is equal to the request host.
89
- func checkSameOrigin(r *http.Request) bool {
90
- origin := r.Header["Origin"]
91
- if len(origin) == 0 {
92
- return true
93
- }
94
- u, err := url.Parse(origin[0])
95
- if err != nil {
96
- return false
97
- }
98
- return equalASCIIFold(u.Host, r.Host)
99
- }
100
-
101
- func (u *Upgrader) selectSubprotocol(r *http.Request, responseHeader http.Header) string {
102
- if u.Subprotocols != nil {
103
- clientProtocols := Subprotocols(r)
104
- for _, serverProtocol := range u.Subprotocols {
105
- for _, clientProtocol := range clientProtocols {
106
- if clientProtocol == serverProtocol {
107
- return clientProtocol
108
- }
109
- }
110
- }
111
- } else if responseHeader != nil {
112
- return responseHeader.Get("Sec-Websocket-Protocol")
113
- }
114
- return ""
115
- }
116
-
117
- // Upgrade upgrades the HTTP server connection to the WebSocket protocol.
118
- //
119
- // The responseHeader is included in the response to the client's upgrade
120
- // request. Use the responseHeader to specify cookies (Set-Cookie). To specify
121
- // subprotocols supported by the server, set Upgrader.Subprotocols directly.
122
- //
123
- // If the upgrade fails, then Upgrade replies to the client with an HTTP error
124
- // response.
125
- func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (*Conn, error) {
126
- const badHandshake = "websocket: the client is not using the websocket protocol: "
127
-
128
- if !tokenListContainsValue(r.Header, "Connection", "upgrade") {
129
- return u.returnError(w, r, http.StatusBadRequest, badHandshake+"'upgrade' token not found in 'Connection' header")
130
- }
131
-
132
- if !tokenListContainsValue(r.Header, "Upgrade", "websocket") {
133
- return u.returnError(w, r, http.StatusBadRequest, badHandshake+"'websocket' token not found in 'Upgrade' header")
134
- }
135
-
136
- if r.Method != http.MethodGet {
137
- return u.returnError(w, r, http.StatusMethodNotAllowed, badHandshake+"request method is not GET")
138
- }
139
-
140
- if !tokenListContainsValue(r.Header, "Sec-Websocket-Version", "13") {
141
- return u.returnError(w, r, http.StatusBadRequest, "websocket: unsupported version: 13 not found in 'Sec-Websocket-Version' header")
142
- }
143
-
144
- if _, ok := responseHeader["Sec-Websocket-Extensions"]; ok {
145
- return u.returnError(w, r, http.StatusInternalServerError, "websocket: application specific 'Sec-WebSocket-Extensions' headers are unsupported")
146
- }
147
-
148
- checkOrigin := u.CheckOrigin
149
- if checkOrigin == nil {
150
- checkOrigin = checkSameOrigin
151
- }
152
- if !checkOrigin(r) {
153
- return u.returnError(w, r, http.StatusForbidden, "websocket: request origin not allowed by Upgrader.CheckOrigin")
154
- }
155
-
156
- challengeKey := r.Header.Get("Sec-Websocket-Key")
157
- if !isValidChallengeKey(challengeKey) {
158
- return u.returnError(w, r, http.StatusBadRequest, "websocket: not a websocket handshake: 'Sec-WebSocket-Key' header must be Base64 encoded value of 16-byte in length")
159
- }
160
-
161
- subprotocol := u.selectSubprotocol(r, responseHeader)
162
-
163
- // Negotiate PMCE
164
- var compress bool
165
- if u.EnableCompression {
166
- for _, ext := range parseExtensions(r.Header) {
167
- if ext[""] != "permessage-deflate" {
168
- continue
169
- }
170
- compress = true
171
- break
172
- }
173
- }
174
-
175
- h, ok := w.(http.Hijacker)
176
- if !ok {
177
- return u.returnError(w, r, http.StatusInternalServerError, "websocket: response does not implement http.Hijacker")
178
- }
179
- var brw *bufio.ReadWriter
180
- netConn, brw, err := h.Hijack()
181
- if err != nil {
182
- return u.returnError(w, r, http.StatusInternalServerError, err.Error())
183
- }
184
-
185
- if brw.Reader.Buffered() > 0 {
186
- netConn.Close()
187
- return nil, errors.New("websocket: client sent data before handshake is complete")
188
- }
189
-
190
- var br *bufio.Reader
191
- if u.ReadBufferSize == 0 && bufioReaderSize(netConn, brw.Reader) > 256 {
192
- // Reuse hijacked buffered reader as connection reader.
193
- br = brw.Reader
194
- }
195
-
196
- buf := bufioWriterBuffer(netConn, brw.Writer)
197
-
198
- var writeBuf []byte
199
- if u.WriteBufferPool == nil && u.WriteBufferSize == 0 && len(buf) >= maxFrameHeaderSize+256 {
200
- // Reuse hijacked write buffer as connection buffer.
201
- writeBuf = buf
202
- }
203
-
204
- c := newConn(netConn, true, u.ReadBufferSize, u.WriteBufferSize, u.WriteBufferPool, br, writeBuf)
205
- c.subprotocol = subprotocol
206
-
207
- if compress {
208
- c.newCompressionWriter = compressNoContextTakeover
209
- c.newDecompressionReader = decompressNoContextTakeover
210
- }
211
-
212
- // Use larger of hijacked buffer and connection write buffer for header.
213
- p := buf
214
- if len(c.writeBuf) > len(p) {
215
- p = c.writeBuf
216
- }
217
- p = p[:0]
218
-
219
- p = append(p, "HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: "...)
220
- p = append(p, computeAcceptKey(challengeKey)...)
221
- p = append(p, "\r\n"...)
222
- if c.subprotocol != "" {
223
- p = append(p, "Sec-WebSocket-Protocol: "...)
224
- p = append(p, c.subprotocol...)
225
- p = append(p, "\r\n"...)
226
- }
227
- if compress {
228
- p = append(p, "Sec-WebSocket-Extensions: permessage-deflate; server_no_context_takeover; client_no_context_takeover\r\n"...)
229
- }
230
- for k, vs := range responseHeader {
231
- if k == "Sec-Websocket-Protocol" {
232
- continue
233
- }
234
- for _, v := range vs {
235
- p = append(p, k...)
236
- p = append(p, ": "...)
237
- for i := 0; i < len(v); i++ {
238
- b := v[i]
239
- if b <= 31 {
240
- // prevent response splitting.
241
- b = ' '
242
- }
243
- p = append(p, b)
244
- }
245
- p = append(p, "\r\n"...)
246
- }
247
- }
248
- p = append(p, "\r\n"...)
249
-
250
- // Clear deadlines set by HTTP server.
251
- netConn.SetDeadline(time.Time{})
252
-
253
- if u.HandshakeTimeout > 0 {
254
- netConn.SetWriteDeadline(time.Now().Add(u.HandshakeTimeout))
255
- }
256
- if _, err = netConn.Write(p); err != nil {
257
- netConn.Close()
258
- return nil, err
259
- }
260
- if u.HandshakeTimeout > 0 {
261
- netConn.SetWriteDeadline(time.Time{})
262
- }
263
-
264
- return c, nil
265
- }
266
-
267
- // Upgrade upgrades the HTTP server connection to the WebSocket protocol.
268
- //
269
- // Deprecated: Use websocket.Upgrader instead.
270
- //
271
- // Upgrade does not perform origin checking. The application is responsible for
272
- // checking the Origin header before calling Upgrade. An example implementation
273
- // of the same origin policy check is:
274
- //
275
- // if req.Header.Get("Origin") != "http://"+req.Host {
276
- // http.Error(w, "Origin not allowed", http.StatusForbidden)
277
- // return
278
- // }
279
- //
280
- // If the endpoint supports subprotocols, then the application is responsible
281
- // for negotiating the protocol used on the connection. Use the Subprotocols()
282
- // function to get the subprotocols requested by the client. Use the
283
- // Sec-Websocket-Protocol response header to specify the subprotocol selected
284
- // by the application.
285
- //
286
- // The responseHeader is included in the response to the client's upgrade
287
- // request. Use the responseHeader to specify cookies (Set-Cookie) and the
288
- // negotiated subprotocol (Sec-Websocket-Protocol).
289
- //
290
- // The connection buffers IO to the underlying network connection. The
291
- // readBufSize and writeBufSize parameters specify the size of the buffers to
292
- // use. Messages can be larger than the buffers.
293
- //
294
- // If the request is not a valid WebSocket handshake, then Upgrade returns an
295
- // error of type HandshakeError. Applications should handle this error by
296
- // replying to the client with an HTTP error response.
297
- func Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header, readBufSize, writeBufSize int) (*Conn, error) {
298
- u := Upgrader{ReadBufferSize: readBufSize, WriteBufferSize: writeBufSize}
299
- u.Error = func(w http.ResponseWriter, r *http.Request, status int, reason error) {
300
- // don't return errors to maintain backwards compatibility
301
- }
302
- u.CheckOrigin = func(r *http.Request) bool {
303
- // allow all connections by default
304
- return true
305
- }
306
- return u.Upgrade(w, r, responseHeader)
307
- }
308
-
309
- // Subprotocols returns the subprotocols requested by the client in the
310
- // Sec-Websocket-Protocol header.
311
- func Subprotocols(r *http.Request) []string {
312
- h := strings.TrimSpace(r.Header.Get("Sec-Websocket-Protocol"))
313
- if h == "" {
314
- return nil
315
- }
316
- protocols := strings.Split(h, ",")
317
- for i := range protocols {
318
- protocols[i] = strings.TrimSpace(protocols[i])
319
- }
320
- return protocols
321
- }
322
-
323
- // IsWebSocketUpgrade returns true if the client requested upgrade to the
324
- // WebSocket protocol.
325
- func IsWebSocketUpgrade(r *http.Request) bool {
326
- return tokenListContainsValue(r.Header, "Connection", "upgrade") &&
327
- tokenListContainsValue(r.Header, "Upgrade", "websocket")
328
- }
329
-
330
- // bufioReaderSize size returns the size of a bufio.Reader.
331
- func bufioReaderSize(originalReader io.Reader, br *bufio.Reader) int {
332
- // This code assumes that peek on a reset reader returns
333
- // bufio.Reader.buf[:0].
334
- // TODO: Use bufio.Reader.Size() after Go 1.10
335
- br.Reset(originalReader)
336
- if p, err := br.Peek(0); err == nil {
337
- return cap(p)
338
- }
339
- return 0
340
- }
341
-
342
- // writeHook is an io.Writer that records the last slice passed to it vio
343
- // io.Writer.Write.
344
- type writeHook struct {
345
- p []byte
346
- }
347
-
348
- func (wh *writeHook) Write(p []byte) (int, error) {
349
- wh.p = p
350
- return len(p), nil
351
- }
352
-
353
- // bufioWriterBuffer grabs the buffer from a bufio.Writer.
354
- func bufioWriterBuffer(originalWriter io.Writer, bw *bufio.Writer) []byte {
355
- // This code assumes that bufio.Writer.buf[:1] is passed to the
356
- // bufio.Writer's underlying writer.
357
- var wh writeHook
358
- bw.Reset(&wh)
359
- bw.WriteByte(0)
360
- bw.Flush()
361
-
362
- bw.Reset(originalWriter)
363
-
364
- return wh.p[:cap(wh.p)]
365
- }
@@ -1,21 +0,0 @@
1
- //go:build go1.17
2
- // +build go1.17
3
-
4
- package websocket
5
-
6
- import (
7
- "context"
8
- "crypto/tls"
9
- )
10
-
11
- func doHandshake(ctx context.Context, tlsConn *tls.Conn, cfg *tls.Config) error {
12
- if err := tlsConn.HandshakeContext(ctx); err != nil {
13
- return err
14
- }
15
- if !cfg.InsecureSkipVerify {
16
- if err := tlsConn.VerifyHostname(cfg.ServerName); err != nil {
17
- return err
18
- }
19
- }
20
- return nil
21
- }
@@ -1,21 +0,0 @@
1
- //go:build !go1.17
2
- // +build !go1.17
3
-
4
- package websocket
5
-
6
- import (
7
- "context"
8
- "crypto/tls"
9
- )
10
-
11
- func doHandshake(ctx context.Context, tlsConn *tls.Conn, cfg *tls.Config) error {
12
- if err := tlsConn.Handshake(); err != nil {
13
- return err
14
- }
15
- if !cfg.InsecureSkipVerify {
16
- if err := tlsConn.VerifyHostname(cfg.ServerName); err != nil {
17
- return err
18
- }
19
- }
20
- return nil
21
- }
@@ -1,298 +0,0 @@
1
- // Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2
- // Use of this source code is governed by a BSD-style
3
- // license that can be found in the LICENSE file.
4
-
5
- package websocket
6
-
7
- import (
8
- "crypto/rand"
9
- "crypto/sha1"
10
- "encoding/base64"
11
- "io"
12
- "net/http"
13
- "strings"
14
- "unicode/utf8"
15
- )
16
-
17
- var keyGUID = []byte("258EAFA5-E914-47DA-95CA-C5AB0DC85B11")
18
-
19
- func computeAcceptKey(challengeKey string) string {
20
- h := sha1.New()
21
- h.Write([]byte(challengeKey))
22
- h.Write(keyGUID)
23
- return base64.StdEncoding.EncodeToString(h.Sum(nil))
24
- }
25
-
26
- func generateChallengeKey() (string, error) {
27
- p := make([]byte, 16)
28
- if _, err := io.ReadFull(rand.Reader, p); err != nil {
29
- return "", err
30
- }
31
- return base64.StdEncoding.EncodeToString(p), nil
32
- }
33
-
34
- // Token octets per RFC 2616.
35
- var isTokenOctet = [256]bool{
36
- '!': true,
37
- '#': true,
38
- '$': true,
39
- '%': true,
40
- '&': true,
41
- '\'': true,
42
- '*': true,
43
- '+': true,
44
- '-': true,
45
- '.': true,
46
- '0': true,
47
- '1': true,
48
- '2': true,
49
- '3': true,
50
- '4': true,
51
- '5': true,
52
- '6': true,
53
- '7': true,
54
- '8': true,
55
- '9': true,
56
- 'A': true,
57
- 'B': true,
58
- 'C': true,
59
- 'D': true,
60
- 'E': true,
61
- 'F': true,
62
- 'G': true,
63
- 'H': true,
64
- 'I': true,
65
- 'J': true,
66
- 'K': true,
67
- 'L': true,
68
- 'M': true,
69
- 'N': true,
70
- 'O': true,
71
- 'P': true,
72
- 'Q': true,
73
- 'R': true,
74
- 'S': true,
75
- 'T': true,
76
- 'U': true,
77
- 'W': true,
78
- 'V': true,
79
- 'X': true,
80
- 'Y': true,
81
- 'Z': true,
82
- '^': true,
83
- '_': true,
84
- '`': true,
85
- 'a': true,
86
- 'b': true,
87
- 'c': true,
88
- 'd': true,
89
- 'e': true,
90
- 'f': true,
91
- 'g': true,
92
- 'h': true,
93
- 'i': true,
94
- 'j': true,
95
- 'k': true,
96
- 'l': true,
97
- 'm': true,
98
- 'n': true,
99
- 'o': true,
100
- 'p': true,
101
- 'q': true,
102
- 'r': true,
103
- 's': true,
104
- 't': true,
105
- 'u': true,
106
- 'v': true,
107
- 'w': true,
108
- 'x': true,
109
- 'y': true,
110
- 'z': true,
111
- '|': true,
112
- '~': true,
113
- }
114
-
115
- // skipSpace returns a slice of the string s with all leading RFC 2616 linear
116
- // whitespace removed.
117
- func skipSpace(s string) (rest string) {
118
- i := 0
119
- for ; i < len(s); i++ {
120
- if b := s[i]; b != ' ' && b != '\t' {
121
- break
122
- }
123
- }
124
- return s[i:]
125
- }
126
-
127
- // nextToken returns the leading RFC 2616 token of s and the string following
128
- // the token.
129
- func nextToken(s string) (token, rest string) {
130
- i := 0
131
- for ; i < len(s); i++ {
132
- if !isTokenOctet[s[i]] {
133
- break
134
- }
135
- }
136
- return s[:i], s[i:]
137
- }
138
-
139
- // nextTokenOrQuoted returns the leading token or quoted string per RFC 2616
140
- // and the string following the token or quoted string.
141
- func nextTokenOrQuoted(s string) (value string, rest string) {
142
- if !strings.HasPrefix(s, "\"") {
143
- return nextToken(s)
144
- }
145
- s = s[1:]
146
- for i := 0; i < len(s); i++ {
147
- switch s[i] {
148
- case '"':
149
- return s[:i], s[i+1:]
150
- case '\\':
151
- p := make([]byte, len(s)-1)
152
- j := copy(p, s[:i])
153
- escape := true
154
- for i = i + 1; i < len(s); i++ {
155
- b := s[i]
156
- switch {
157
- case escape:
158
- escape = false
159
- p[j] = b
160
- j++
161
- case b == '\\':
162
- escape = true
163
- case b == '"':
164
- return string(p[:j]), s[i+1:]
165
- default:
166
- p[j] = b
167
- j++
168
- }
169
- }
170
- return "", ""
171
- }
172
- }
173
- return "", ""
174
- }
175
-
176
- // equalASCIIFold returns true if s is equal to t with ASCII case folding as
177
- // defined in RFC 4790.
178
- func equalASCIIFold(s, t string) bool {
179
- for s != "" && t != "" {
180
- sr, size := utf8.DecodeRuneInString(s)
181
- s = s[size:]
182
- tr, size := utf8.DecodeRuneInString(t)
183
- t = t[size:]
184
- if sr == tr {
185
- continue
186
- }
187
- if 'A' <= sr && sr <= 'Z' {
188
- sr = sr + 'a' - 'A'
189
- }
190
- if 'A' <= tr && tr <= 'Z' {
191
- tr = tr + 'a' - 'A'
192
- }
193
- if sr != tr {
194
- return false
195
- }
196
- }
197
- return s == t
198
- }
199
-
200
- // tokenListContainsValue returns true if the 1#token header with the given
201
- // name contains a token equal to value with ASCII case folding.
202
- func tokenListContainsValue(header http.Header, name string, value string) bool {
203
- headers:
204
- for _, s := range header[name] {
205
- for {
206
- var t string
207
- t, s = nextToken(skipSpace(s))
208
- if t == "" {
209
- continue headers
210
- }
211
- s = skipSpace(s)
212
- if s != "" && s[0] != ',' {
213
- continue headers
214
- }
215
- if equalASCIIFold(t, value) {
216
- return true
217
- }
218
- if s == "" {
219
- continue headers
220
- }
221
- s = s[1:]
222
- }
223
- }
224
- return false
225
- }
226
-
227
- // parseExtensions parses WebSocket extensions from a header.
228
- func parseExtensions(header http.Header) []map[string]string {
229
- // From RFC 6455:
230
- //
231
- // Sec-WebSocket-Extensions = extension-list
232
- // extension-list = 1#extension
233
- // extension = extension-token *( ";" extension-param )
234
- // extension-token = registered-token
235
- // registered-token = token
236
- // extension-param = token [ "=" (token | quoted-string) ]
237
- // ;When using the quoted-string syntax variant, the value
238
- // ;after quoted-string unescaping MUST conform to the
239
- // ;'token' ABNF.
240
-
241
- var result []map[string]string
242
- headers:
243
- for _, s := range header["Sec-Websocket-Extensions"] {
244
- for {
245
- var t string
246
- t, s = nextToken(skipSpace(s))
247
- if t == "" {
248
- continue headers
249
- }
250
- ext := map[string]string{"": t}
251
- for {
252
- s = skipSpace(s)
253
- if !strings.HasPrefix(s, ";") {
254
- break
255
- }
256
- var k string
257
- k, s = nextToken(skipSpace(s[1:]))
258
- if k == "" {
259
- continue headers
260
- }
261
- s = skipSpace(s)
262
- var v string
263
- if strings.HasPrefix(s, "=") {
264
- v, s = nextTokenOrQuoted(skipSpace(s[1:]))
265
- s = skipSpace(s)
266
- }
267
- if s != "" && s[0] != ',' && s[0] != ';' {
268
- continue headers
269
- }
270
- ext[k] = v
271
- }
272
- if s != "" && s[0] != ',' {
273
- continue headers
274
- }
275
- result = append(result, ext)
276
- if s == "" {
277
- continue headers
278
- }
279
- s = s[1:]
280
- }
281
- }
282
- return result
283
- }
284
-
285
- // isValidChallengeKey checks if the argument meets RFC6455 specification.
286
- func isValidChallengeKey(s string) bool {
287
- // From RFC6455:
288
- //
289
- // A |Sec-WebSocket-Key| header field with a base64-encoded (see
290
- // Section 4 of [RFC4648]) value that, when decoded, is 16 bytes in
291
- // length.
292
-
293
- if s == "" {
294
- return false
295
- }
296
- decoded, err := base64.StdEncoding.DecodeString(s)
297
- return err == nil && len(decoded) == 16
298
- }