From 079a5eb582d55a062f570953e70cbf2f509dc0e2 Mon Sep 17 00:00:00 2001 From: David Baird Date: Sat, 30 Nov 2013 16:57:27 -0700 Subject: [PATCH] Exclude port from Host: header if port is 80. --- easywsclient.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/easywsclient.cpp b/easywsclient.cpp index a36c89b..c76deef 100644 --- a/easywsclient.cpp +++ b/easywsclient.cpp @@ -398,7 +398,12 @@ easywsclient::WebSocket::pointer from_url(std::string url, bool useMask) { int status; int i; snprintf(line, 256, "GET /%s HTTP/1.1\r\n", path); ::send(sockfd, line, strlen(line), 0); - snprintf(line, 256, "Host: %s:%d\r\n", host, port); ::send(sockfd, line, strlen(line), 0); + if (port == 80) { + snprintf(line, 256, "Host: %s\r\n", host); ::send(sockfd, line, strlen(line), 0); + } + else { + snprintf(line, 256, "Host: %s:%d\r\n", host, port); ::send(sockfd, line, strlen(line), 0); + } snprintf(line, 256, "Upgrade: websocket\r\n"); ::send(sockfd, line, strlen(line), 0); snprintf(line, 256, "Connection: Upgrade\r\n"); ::send(sockfd, line, strlen(line), 0); snprintf(line, 256, "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n"); ::send(sockfd, line, strlen(line), 0);