Github user bgaff commented on a diff in the pull request: https://github.com/apache/trafficserver/pull/624#discussion_r62699378 --- Diff: lib/atscppapi/examples/websocket/WebSocket.cc --- @@ -0,0 +1,246 @@ +#include "WebSocket.hh" + +#include <iostream> +#include "ts/ink_base64.h" +#include "openssl/evp.h" + +using namespace atscppapi; + +#define SAY(a) std::cout << a << std::endl; +#define SHOW(a) std::cout << #a << " = " << a << std::endl + +void TSPluginInit(int argc, const char* argv[]) +{ + RegisterGlobalPlugin("WebSocket", "Apache", "supp...@example.com"); + new WebSocketInstaller(); +} + + +// WebSocketInstaller + +WebSocketInstaller::WebSocketInstaller() + : GlobalPlugin(true /* ignore internal transactions */) +{ + GlobalPlugin::registerHook(Plugin::HOOK_READ_REQUEST_HEADERS_PRE_REMAP); +} + +#define WS_DIGEST_MAX ATS_BASE64_ENCODE_DSTLEN(20) +static const std::string magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; + +static std::string ws_digest(std::string const& key) { + EVP_MD_CTX digest; + EVP_MD_CTX_init(&digest); + + if (!EVP_DigestInit_ex(&digest, EVP_sha1(), NULL)) { + EVP_MD_CTX_cleanup(&digest); + return "init-failed"; + } + if (!EVP_DigestUpdate(&digest, key.data(), key.length())) { + EVP_MD_CTX_cleanup(&digest); + return "update1-failed"; + } + if (!EVP_DigestUpdate(&digest, magic.data(), magic.length())) { + EVP_MD_CTX_cleanup(&digest); + return "update2-failed"; + } + + unsigned char hash_buf[EVP_MAX_MD_SIZE]; + unsigned int hash_len = 0; + if (!EVP_DigestFinal_ex(&digest, hash_buf, &hash_len)) { + EVP_MD_CTX_cleanup(&digest); + return "final-failed"; + } + EVP_MD_CTX_cleanup(&digest); + if (hash_len != 20) { + return "bad-hash-length"; + } + + char digest_buf[WS_DIGEST_MAX]; + size_t digest_len = 0; + + ats_base64_encode(hash_buf, hash_len, digest_buf, WS_DIGEST_MAX, &digest_len); + + return std::string((char*)digest_buf, digest_len); +} + + +void WebSocketInstaller::handleReadRequestHeadersPreRemap(Transaction &transaction) +{ + SAY("Incoming request."); + transaction.addPlugin(new WebSocket(transaction)); + transaction.resume(); +} + +// WebSocket implementation. + +WebSocket::WebSocket(Transaction& transaction) + : InterceptPlugin(transaction, InterceptPlugin::SERVER_INTERCEPT) + , pos_(0) + , ctrl_(0) + , msg_len_(0) + , ws_handshake_done_(false) +{ + ws_key_ = transaction.getClientRequest().getHeaders().values("sec-websocket-key"); + if (ws_key_.size()) { + printf("setting timeouts\n"); + transaction.setTimeout(Transaction::TIMEOUT_ACTIVE, 844000000); --- End diff -- So websockets actually have seperate timeouts that aren't exposed yet into the C++ api (which explains why you weren't seeing them apply). See: https://docs.trafficserver.apache.org/en/latest/admin-guide/files/records.config.en.html#proxy-config-websocket-no-activity-timeout Please feel free top open a pull request that adds them, otherwise please open a TS ticket and assign it to me and I'll add it.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---