x.websocket: add header to client (#9517)
parent
3ced970b17
commit
9b9ef5fe1b
|
@ -22,7 +22,12 @@ fn (mut ws Client) handshake() ? {
|
|||
sb.write_string('\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n')
|
||||
sb.write_string('Sec-WebSocket-Key: ')
|
||||
sb.write_string(seckey)
|
||||
sb.write_string('\r\nSec-WebSocket-Version: 13\r\n\r\n')
|
||||
sb.write_string('\r\nSec-WebSocket-Version: 13')
|
||||
for key in ws.header.keys() {
|
||||
val := ws.header.values_str(key).join(',')
|
||||
sb.write_string('\r\n$key:$val')
|
||||
}
|
||||
sb.write_string('\r\n\r\n')
|
||||
handshake := sb.str()
|
||||
defer {
|
||||
unsafe { handshake.free() }
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
module websocket
|
||||
|
||||
import net
|
||||
import net.http
|
||||
import x.openssl
|
||||
import net.urllib
|
||||
import time
|
||||
|
@ -30,6 +31,7 @@ pub:
|
|||
uri Uri // uri of current connection
|
||||
id string // unique id of client
|
||||
pub mut:
|
||||
header http.Header // headers that will be passed when connecting
|
||||
conn &net.TcpConn // underlying TCP socket connection
|
||||
nonce_size int = 16 // size of nounce used for masking
|
||||
panic_on_callback bool // set to true of callbacks can panic
|
||||
|
@ -85,6 +87,7 @@ pub fn new_client(address string) ?&Client {
|
|||
uri: uri
|
||||
state: .closed
|
||||
id: rand.uuid_v4()
|
||||
header: http.new_header()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -486,5 +489,6 @@ pub fn (c &Client) free() {
|
|||
c.error_callbacks.free()
|
||||
c.open_callbacks.free()
|
||||
c.close_callbacks.free()
|
||||
c.header.free()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue