Details
-
Bug
-
Resolution: Duplicate
-
P3: Somewhat important
-
None
-
5.2.1
-
None
-
Windows 7, Visual Studio 2013 Ultimate, Qt 5.2.1
Description
When a chrome browser is setting up a websocket connection with a QWebSocketServer, it fails with the error-message :
WebSocket connection to ‘ws://localhost:9090/’ failed: Invalid UTF-8 sequence in header value.
Works fine on recent versions of Opera, Firefox and IE
What is strange is it worked yesterday (friday 15.08.2014). Today, saturday (16.08.2014) it doesn’t work.
Now, I’ve been investigating this, and I think I have found a possible reason. I think it has something to do with how the class
QWebSocketHandshakeResponse is building it’s headers. Here is how the result looks like TODAY :
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: <XXXXXXXXXXXXXXXXXXXXXXXXXXXX>
Server: wsmanas
Access-Control-Allow-Credentials: false
Access-Control-Allow-Methods: GET
Access-Control-Allow-Headers: content-type
Access-Control-Allow-Origin: *
Date: lø, 16 aug 2014 12:29:41 GMT
Look at the last header, Date. It contains a non-UTF-8 letter : ‘ø’, because saturday in norwegian is LØRDAG. Now look at how the response is being built :
response << QStringLiteral("Server: ") % serverName <<
QStringLiteral("Access-Control-Allow-Credentials: false") <<
QStringLiteral("Access-Control-Allow-Methods: GET") <<
QStringLiteral("Access-Control-Allow-Headers: content-type") <<
QStringLiteral("Access-Control-Allow-Origin: ") % origin <<
QStringLiteral("Date: ") %
QDateTime::currentDateTimeUtc()
.toString(QStringLiteral("ddd, dd MMM yyyy hh:mm:ss 'GMT'"));
So the Date header is built using the QDateTime class. Looking at the toString function :
QString QDateTime::toString(const QString& format) const
{
return QLocale::system().toString(*this, format);
}
it seems to me that it is not possible the change the language, for instance like this :
QLocale loc(QLocale::English, QLocale::Norway);
QLocale::setDefault(loc);
because it’s going to use the system locale anyway. Because of this, i think that QWebSocket connections is not going to work with Chrome on saturdays (LØRDAG; lø) or sundays (SØNDAG; sø).