summaryrefslogtreecommitdiffstats
path: root/net/websockets
diff options
context:
space:
mode:
authorukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-06 06:32:06 +0000
committerukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-06 06:32:06 +0000
commit8cb9e2de37879b1bdda07e2fb3490720859910f4 (patch)
tree818e0dcbe44201dfe1bc6f691956a53a0cac64c7 /net/websockets
parentaa3d892d9b41af9fa95bb15ba8b21e879f92471b (diff)
downloadchromium_src-8cb9e2de37879b1bdda07e2fb3490720859910f4.zip
chromium_src-8cb9e2de37879b1bdda07e2fb3490720859910f4.tar.gz
chromium_src-8cb9e2de37879b1bdda07e2fb3490720859910f4.tar.bz2
Add error reporting in net/websockets
Fix response code for websocket authentication. BUG=none TEST=none Review URL: http://codereview.chromium.org/368003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31211 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/websockets')
-rw-r--r--net/websockets/websocket.cc15
-rw-r--r--net/websockets/websocket.h8
2 files changed, 22 insertions, 1 deletions
diff --git a/net/websockets/websocket.cc b/net/websockets/websocket.cc
index 0ccce69..57db486 100644
--- a/net/websockets/websocket.cc
+++ b/net/websockets/websocket.cc
@@ -141,6 +141,11 @@ void WebSocket::OnClose(SocketStream* socket_stream) {
NewRunnableMethod(this, &WebSocket::DoClose));
}
+void WebSocket::OnError(const SocketStream* socket_stream, int error) {
+ origin_loop_->PostTask(FROM_HERE,
+ NewRunnableMethod(this, &WebSocket::DoError, error));
+}
+
IOBufferWithSize* WebSocket::CreateClientHandshakeMessage() const {
std::string msg;
msg = "GET ";
@@ -176,6 +181,7 @@ IOBufferWithSize* WebSocket::CreateClientHandshakeMessage() const {
}
// TODO(ukai): Add cookie if necessary.
msg += "\r\n";
+ DLOG(INFO) << "ClientHandshakeMsg=" << msg;
IOBufferWithSize* buf = new IOBufferWithSize(msg.size());
memcpy(buf->data(), msg.data(), msg.size());
return buf;
@@ -188,6 +194,7 @@ int WebSocket::CheckHandshake() {
const char *start = current_read_buf_->StartOfBuffer() + read_consumed_len_;
const char *p = start;
size_t len = current_read_buf_->offset() - read_consumed_len_;
+ DLOG(INFO) << "CheckHandshake response=" << std::string(start, len);
if (len < kServerHandshakeHeaderLength) {
return -1;
}
@@ -199,7 +206,7 @@ int WebSocket::CheckHandshake() {
return -1;
scoped_refptr<HttpResponseHeaders> headers(
new HttpResponseHeaders(HttpUtil::AssembleRawHeaders(p, eoh)));
- if (headers->response_code() == 401) {
+ if (headers->response_code() == 407) {
mode_ = MODE_AUTHENTICATE;
// TODO(ukai): Implement authentication handlers.
}
@@ -446,4 +453,10 @@ void WebSocket::DoClose() {
delegate->OnClose(this);
}
+void WebSocket::DoError(int error) {
+ DCHECK(MessageLoop::current() == origin_loop_);
+ if (delegate_)
+ delegate_->OnError(this, error);
+}
+
} // namespace net
diff --git a/net/websockets/websocket.h b/net/websockets/websocket.h
index 2279681..8ce5e83 100644
--- a/net/websockets/websocket.h
+++ b/net/websockets/websocket.h
@@ -45,6 +45,9 @@ class WebSocketDelegate {
// Called when |socket| is closed.
virtual void OnClose(WebSocket* socket) = 0;
+
+ // Called when an error occured on |socket|.
+ virtual void OnError(const WebSocket* socket, int error) {}
};
class WebSocket : public base::RefCountedThreadSafe<WebSocket>,
@@ -110,6 +113,7 @@ class WebSocket : public base::RefCountedThreadSafe<WebSocket>,
// |delegate| must be alive while this object is alive.
WebSocket(Request* req, WebSocketDelegate* delegate);
+ const Request* request() const { return request_.get(); }
WebSocketDelegate* delegate() const { return delegate_; }
State ready_state() const { return ready_state_; }
@@ -132,6 +136,7 @@ class WebSocket : public base::RefCountedThreadSafe<WebSocket>,
virtual void OnReceivedData(SocketStream* socket_stream,
const char* data, int len);
virtual void OnClose(SocketStream* socket);
+ virtual void OnError(const SocketStream* socket, int error);
private:
enum Mode {
@@ -183,6 +188,9 @@ class WebSocket : public base::RefCountedThreadSafe<WebSocket>,
// Handles closed connection.
void DoClose();
+ // Handles error report.
+ void DoError(int error);
+
State ready_state_;
Mode mode_;
scoped_ptr<Request> request_;