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

Unified Diff: net/server/web_socket_encoder.h

Issue 1340523002: Fix WebSocketServer extension parser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ws-constructor-fix
Patch Set: Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: net/server/web_socket_encoder.h
diff --git a/net/server/web_socket_encoder.h b/net/server/web_socket_encoder.h
index 23f0d9cc075b15471ce7c3ef0b54f877f9be809a..47b08716c256a8a567f967811d84f49f333d1627 100644
--- a/net/server/web_socket_encoder.h
+++ b/net/server/web_socket_encoder.h
@@ -16,61 +16,49 @@
namespace net {
-class WebSocketEncoder {
+class WebSocketDeflateParameters;
+
+class WebSocketEncoder final {
public:
+ static const char kClientExtensions[];
~WebSocketEncoder();
- static WebSocketEncoder* CreateServer(const std::string& request_extensions,
- std::string* response_extensions);
-
- static const char kClientExtensions[];
+ // Creates and returns an encoder for a server without deflate extension.
+ static scoped_ptr<WebSocketEncoder> CreateServer();
+ // Creates and returns an encoder for a server with deflate extension.
+ // Returns nullptr when there is an error.
+ static scoped_ptr<WebSocketEncoder> CreateServer(
+ const std::string& request_extensions,
+ WebSocketDeflateParameters* response_params,
+ std::string* failure_message);
+ // TODO(yhirano): Return a scoped_ptr instead of a raw pointer.
static WebSocketEncoder* CreateClient(const std::string& response_extensions);
WebSocket::ParseResult DecodeFrame(const base::StringPiece& frame,
int* bytes_consumed,
std::string* output);
-
void EncodeFrame(const std::string& frame,
int masking_key,
std::string* output);
+ bool deflate_enabled() const { return deflater_; }
+
private:
- explicit WebSocketEncoder(bool is_server);
- WebSocketEncoder(bool is_server,
- int deflate_bits,
- int inflate_bits,
- bool no_context_takeover);
-
- // Parses a value in the Sec-WebSocket-Extensions header. If it contains a
- // single element of the permessage-deflate extension, stores the result of
- // parsing the parameters of the extension into the given variables.
- // Otherwise, returns with *deflate set to false.
- //
- // - If the client_max_window_bits parameter is missing, *client_window_bits
- // defaults to 15.
- // - If the client_max_window_bits parameter has an invalid value,
- // *client_window_bits will be set to 0.
- // - If the server_max_window_bits parameter is missing, *server_window_bits
- // defaults to 15.
- // - If the server_max_window_bits parameter has an invalid value,
- // *client_window_bits will be set to 0.
- //
- // TODO(tyoshino): Consider using a struct than taking a lot of pointers for
- // output.
- static void ParseExtensions(const std::string& header_value,
- bool* deflate,
- bool* has_client_window_bits,
- int* client_window_bits,
- int* server_window_bits,
- bool* client_no_context_takeover,
- bool* server_no_context_takeover);
+ class AsServer {};
+ class AsClient {};
+
+ explicit WebSocketEncoder(const AsServer&);
+ explicit WebSocketEncoder(const AsClient&);
+ WebSocketEncoder(const AsServer&, const WebSocketDeflateParameters& params);
+ WebSocketEncoder(const AsClient&, const WebSocketDeflateParameters& params);
bool Inflate(std::string* message);
bool Deflate(const std::string& message, std::string* output);
+ bool is_server_;
+ bool has_error_;
scoped_ptr<WebSocketDeflater> deflater_;
scoped_ptr<WebSocketInflater> inflater_;
- bool is_server_;
DISALLOW_COPY_AND_ASSIGN(WebSocketEncoder);
};

Powered by Google App Engine
This is Rietveld 408576698