From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Yu-Chen Lin" <npes87184@gmail.com>,
"Daniel P. Berrangé" <berrange@redhat.com>
Subject: [PULL 1/3] io/channel-websock: treat 'binary' and no sub-protocol as the same
Date: Fri, 7 Feb 2020 12:24:38 +0000 [thread overview]
Message-ID: <20200207122440.2650229-2-berrange@redhat.com> (raw)
In-Reply-To: <20200207122440.2650229-1-berrange@redhat.com>
From: Yu-Chen Lin <npes87184@gmail.com>
noVNC doesn't use 'binary' protocol by default after
commit c912230309806aacbae4295faf7ad6406da97617.
It will cause qemu return 400 when handshaking.
To overcome this problem and remain compatibility of
older noVNC client.
We treat 'binary' and no sub-protocol as the same
so that we can support different version of noVNC
client.
Tested on noVNC before c912230 and after c912230.
Buglink: https://bugs.launchpad.net/qemu/+bug/1849644
Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
io/channel-websock.c | 36 ++++++++++++++++++++++++------------
1 file changed, 24 insertions(+), 12 deletions(-)
diff --git a/io/channel-websock.c b/io/channel-websock.c
index fc36d44eba..47a0e941d9 100644
--- a/io/channel-websock.c
+++ b/io/channel-websock.c
@@ -49,13 +49,20 @@
"Server: QEMU VNC\r\n" \
"Date: %s\r\n"
+#define QIO_CHANNEL_WEBSOCK_HANDSHAKE_WITH_PROTO_RES_OK \
+ "HTTP/1.1 101 Switching Protocols\r\n" \
+ QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_COMMON \
+ "Upgrade: websocket\r\n" \
+ "Connection: Upgrade\r\n" \
+ "Sec-WebSocket-Accept: %s\r\n" \
+ "Sec-WebSocket-Protocol: binary\r\n" \
+ "\r\n"
#define QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_OK \
"HTTP/1.1 101 Switching Protocols\r\n" \
QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_COMMON \
"Upgrade: websocket\r\n" \
"Connection: Upgrade\r\n" \
"Sec-WebSocket-Accept: %s\r\n" \
- "Sec-WebSocket-Protocol: binary\r\n" \
"\r\n"
#define QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_NOT_FOUND \
"HTTP/1.1 404 Not Found\r\n" \
@@ -336,6 +343,7 @@ qio_channel_websock_find_header(QIOChannelWebsockHTTPHeader *hdrs,
static void qio_channel_websock_handshake_send_res_ok(QIOChannelWebsock *ioc,
const char *key,
+ const bool use_protocols,
Error **errp)
{
char combined_key[QIO_CHANNEL_WEBSOCK_CLIENT_KEY_LEN +
@@ -361,8 +369,14 @@ static void qio_channel_websock_handshake_send_res_ok(QIOChannelWebsock *ioc,
}
date = qio_channel_websock_date_str();
- qio_channel_websock_handshake_send_res(
- ioc, QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_OK, date, accept);
+ if (use_protocols) {
+ qio_channel_websock_handshake_send_res(
+ ioc, QIO_CHANNEL_WEBSOCK_HANDSHAKE_WITH_PROTO_RES_OK,
+ date, accept);
+ } else {
+ qio_channel_websock_handshake_send_res(
+ ioc, QIO_CHANNEL_WEBSOCK_HANDSHAKE_RES_OK, date, accept);
+ }
g_free(date);
g_free(accept);
@@ -387,10 +401,6 @@ static void qio_channel_websock_handshake_process(QIOChannelWebsock *ioc,
protocols = qio_channel_websock_find_header(
hdrs, nhdrs, QIO_CHANNEL_WEBSOCK_HEADER_PROTOCOL);
- if (!protocols) {
- error_setg(errp, "Missing websocket protocol header data");
- goto bad_request;
- }
version = qio_channel_websock_find_header(
hdrs, nhdrs, QIO_CHANNEL_WEBSOCK_HEADER_VERSION);
@@ -430,10 +440,12 @@ static void qio_channel_websock_handshake_process(QIOChannelWebsock *ioc,
trace_qio_channel_websock_http_request(ioc, protocols, version,
host, connection, upgrade, key);
- if (!g_strrstr(protocols, QIO_CHANNEL_WEBSOCK_PROTOCOL_BINARY)) {
- error_setg(errp, "No '%s' protocol is supported by client '%s'",
- QIO_CHANNEL_WEBSOCK_PROTOCOL_BINARY, protocols);
- goto bad_request;
+ if (protocols) {
+ if (!g_strrstr(protocols, QIO_CHANNEL_WEBSOCK_PROTOCOL_BINARY)) {
+ error_setg(errp, "No '%s' protocol is supported by client '%s'",
+ QIO_CHANNEL_WEBSOCK_PROTOCOL_BINARY, protocols);
+ goto bad_request;
+ }
}
if (!g_str_equal(version, QIO_CHANNEL_WEBSOCK_SUPPORTED_VERSION)) {
@@ -467,7 +479,7 @@ static void qio_channel_websock_handshake_process(QIOChannelWebsock *ioc,
goto bad_request;
}
- qio_channel_websock_handshake_send_res_ok(ioc, key, errp);
+ qio_channel_websock_handshake_send_res_ok(ioc, key, !!protocols, errp);
return;
bad_request:
--
2.24.1
next prev parent reply other threads:[~2020-02-07 12:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-07 12:24 [PULL 0/3] Misc patches Daniel P. Berrangé
2020-02-07 12:24 ` Daniel P. Berrangé [this message]
2020-02-07 12:24 ` [PULL 2/3] authz: fix usage of bool in listfile.c Daniel P. Berrangé
2020-02-07 12:24 ` [PULL 3/3] docs: stop documenting the e1000 NIC model as the default Daniel P. Berrangé
2020-02-07 18:02 ` [PULL 0/3] Misc patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200207122440.2650229-2-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=npes87184@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).