Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: WebCore/websockets/WebSocketRequest.cpp

Issue 155079: WebSocket implementation in WebKit (Closed)
Patch Set: Rewrite to use SocketStreamHandle Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « WebCore/websockets/WebSocketRequest.h ('k') | WebCore/websockets/WebSocketResponse.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "WebSocketRequest.h"
32
33 #include "KURL.h"
34 #include "StringBuilder.h"
35
36 namespace WebCore {
37
38 WebSocketRequest::WebSocketRequest(const KURL& url, const String& protocol, cons t String& origin)
39 : m_url(url)
40 , m_protocol(protocol)
41 , m_secure(m_url.protocolIs("wss"))
42 , m_origin(origin)
43 {
44 }
45
46 WebSocketRequest::~WebSocketRequest()
47 {
48 }
49
50 const KURL& WebSocketRequest::url() const
51 {
52 return m_url;
53 }
54
55 void WebSocketRequest::setURL(const KURL& url)
56 {
57 m_url = url;
58 }
59
60 const String WebSocketRequest::host() const
61 {
62 return m_url.host().lower();
63 }
64
65 const String& WebSocketRequest::protocol() const
66 {
67 return m_protocol;
68 }
69
70 void WebSocketRequest::setProtocol(const String& protocol)
71 {
72 m_protocol = protocol;
73 }
74
75 bool WebSocketRequest::secure() const
76 {
77 return m_secure;
78 }
79
80 void WebSocketRequest::setSecure(bool secure)
81 {
82 m_secure = secure;
83 }
84
85 const String& WebSocketRequest::origin() const
86 {
87 return m_origin;
88 }
89
90 void WebSocketRequest::setOrigin(const String& origin)
91 {
92 m_origin = origin;
93 }
94
95 String WebSocketRequest::location() const
96 {
97 StringBuilder builder;
98 if (m_secure) {
99 builder.append("wss");
100 } else {
101 builder.append("ws");
102 }
103 builder.append("://");
104 builder.append(host());
105 if ((!m_secure && m_url.port() != 81) || (m_secure && m_url.port() != 815)) {
106 builder.append(":");
107 builder.append(String::number(m_url.port()));
108 }
109 builder.append(m_url.path());
110 return builder.toString();
111 }
112
113 CString WebSocketRequest::flattenToString() const
114 {
115 StringBuilder builder;
116
117 builder.append("GET ");
118 builder.append(url().path());
119 if (!url().query().isEmpty()) {
120 builder.append("?");
121 builder.append(url().query());
122 }
123 if (url().hasRef()) {
124 builder.append("#");
125 builder.append(url().ref());
126 }
127 builder.append(" HTTP/1.1\r\n");
128 builder.append("Upgrade: WebSocket\r\n");
129 builder.append("Connection: Upgrade\r\n");
130 builder.append("Host: ");
131 builder.append(host());
132 builder.append("\r\n");
133 builder.append("Origin: ");
134 builder.append(origin());
135 builder.append("\r\n");
136 if (!protocol().isEmpty()) {
137 builder.append("WebSocket-Protocol: ");
138 builder.append(protocol());
139 builder.append("\r\n");
140 }
141 // FIXME: add auth info
142 builder.append("\r\n");
143 return builder.toString().utf8();
144 }
145
146 } // namespace WebCore
OLDNEW
« no previous file with comments | « WebCore/websockets/WebSocketRequest.h ('k') | WebCore/websockets/WebSocketResponse.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698