mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
adds handshake request processing to hybi13 and 00 processors
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2012, Peter Thorson. All rights reserved.
|
||||
* Copyright (c) 2013, Peter Thorson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -136,6 +136,11 @@ public:
|
||||
return lib::error_code();
|
||||
}
|
||||
|
||||
// outgoing client connection processing is not supported for this version
|
||||
lib::error_code handshake_request(request_type& req, uri_ptr uri) const {
|
||||
return error::make_error_code(error::no_protocol_support);
|
||||
}
|
||||
|
||||
std::string get_raw(const response_type& res) const {
|
||||
return res.raw() + res.get_header("Sec-WebSocket-Key3");
|
||||
}
|
||||
|
||||
@@ -195,6 +195,30 @@ public:
|
||||
return lib::error_code();
|
||||
}
|
||||
|
||||
lib::error_code handshake_request(request_type& req, uri_ptr uri) const {
|
||||
req.set_method("GET");
|
||||
req.set_uri(uri->get_resource());
|
||||
req.set_version("HTTP/1.1");
|
||||
|
||||
req.append_header("Upgrade","websocket");
|
||||
req.append_header("Connection","Upgrade");
|
||||
req.replace_header("Sec-WebSocket-Version","13");
|
||||
req.replace_header("Host",uri->get_host_port());
|
||||
|
||||
// Generate handshake key
|
||||
frame::uint32_converter conv;
|
||||
unsigned char raw_key[16];
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
conv.i = m_rng();
|
||||
std::copy(conv.c,conv.c+4,&raw_key[i*4]);
|
||||
}
|
||||
|
||||
req.replace_header("Sec-WebSocket-Key",base64_encode(raw_key, 16));
|
||||
|
||||
return lib::error_code();
|
||||
}
|
||||
|
||||
std::string get_raw(const response_type& res) const {
|
||||
return res.raw();
|
||||
}
|
||||
|
||||
@@ -193,6 +193,15 @@ public:
|
||||
virtual lib::error_code process_handshake(const request_type& req,
|
||||
response_type& res) const = 0;
|
||||
|
||||
/// Fill in an HTTP request for an outgoing connection handshake
|
||||
/**
|
||||
* @param req The request to process.
|
||||
*
|
||||
* @return An error code, 0 on success, non-zero for other errors
|
||||
*/
|
||||
virtual lib::error_code handshake_request(request_type& req, uri_ptr uri)
|
||||
const = 0;
|
||||
|
||||
/// Given a completed response, get the raw bytes to put on the wire
|
||||
virtual std::string get_raw(const response_type& request) const = 0;
|
||||
|
||||
@@ -307,8 +316,8 @@ public:
|
||||
virtual lib::error_code prepare_close(close::status::value code,
|
||||
const std::string & reason, message_ptr out) const = 0;
|
||||
protected:
|
||||
const bool m_secure;
|
||||
const bool m_server;
|
||||
const bool m_secure;
|
||||
const bool m_server;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user