diff options
Diffstat (limited to 'src/unstable/protocolwebsocket.cpp')
-rw-r--r-- | src/unstable/protocolwebsocket.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/unstable/protocolwebsocket.cpp b/src/unstable/protocolwebsocket.cpp index 8d4a124..08ac176 100644 --- a/src/unstable/protocolwebsocket.cpp +++ b/src/unstable/protocolwebsocket.cpp | |||
@@ -66,6 +66,11 @@ void Bu::ProtocolWebSocket::onNewData( Bu::Client * /*pClient*/ ) | |||
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | bool onProcessHeaders( Bu::StringList & /*lHeadersOut*/ ) | ||
70 | { | ||
71 | return true; | ||
72 | } | ||
73 | |||
69 | void Bu::ProtocolWebSocket::writeMessage( const Bu::String &sData, | 74 | void Bu::ProtocolWebSocket::writeMessage( const Bu::String &sData, |
70 | Bu::ProtocolWebSocket::Operation eOp ) | 75 | Bu::ProtocolWebSocket::Operation eOp ) |
71 | { | 76 | { |
@@ -237,12 +242,24 @@ bool Bu::ProtocolWebSocket::processHeaders() | |||
237 | 242 | ||
238 | DEBUG( Bu::println("accept: %1").arg( mbOut.getString() ) ); | 243 | DEBUG( Bu::println("accept: %1").arg( mbOut.getString() ) ); |
239 | 244 | ||
240 | pClient->write("HTTP/1.1 101 Switching Protocols\r\n" | 245 | Bu::StringList lHeadersOut; |
241 | "Upgrade: websocket\r\n" | 246 | lHeadersOut.append("Upgrade: websocket"); |
242 | "Connection: Upgrade\r\n" | 247 | lHeadersOut.append("Connection: Upgrade"); |
243 | "Sec-WebSocket-Accept: " + mbOut.getString() + "\r\n" | 248 | lHeadersOut.append("Sec-WebSocket-Accept: " + mbOut.getString()); |
244 | "\r\n" | 249 | |
245 | ); | 250 | if( !onProcessHeaders( lHeadersOut ) ) |
251 | { | ||
252 | pClient->disconnect(); | ||
253 | return false; | ||
254 | } | ||
255 | |||
256 | Bu::String sHeaderBlock("HTTP/1.1 101 Switching Protocols\r\n"); | ||
257 | for( Bu::StringList::iterator i = lHeadersOut.begin(); i; i++ ) | ||
258 | { | ||
259 | sHeaderBlock += (*i) + "\r\n"; | ||
260 | } | ||
261 | sHeaderBlock += "\r\n"; | ||
262 | pClient->write( sHeaderBlock ); | ||
246 | 263 | ||
247 | DEBUG( Bu::println("websocket: Switching protocols.") ); | 264 | DEBUG( Bu::println("websocket: Switching protocols.") ); |
248 | 265 | ||