When I am trying to receive a message from Socket.IO using the native socket module, instead of receiving the message, I receive this:
GET /socket.io/?EIO=3&transport=polling&t=MIlsTQ_ HTTP/1.1
Host: localhost:5000
Connection: keep-alive
Accept: */*
Origin: http://localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
DNT: 1
Referer: http://localhost:8080/
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
How do I fix this, and receive the message rather than the data?
Client code:
socketsSend: function() {
const socket = io.connect('http://localhost:5000');
/*var socket = io.Socket('http://localhost', {
port: 5000
});*/
socket.connect();
socket._connectTimer = setTimeout(function() {
socket.close();
}, 500);
socket.on('connect', function() {
// socket connected successfully, clear the timer
clearTimeout(socket._connectTimer);
});
Server code:
import socket
import json
addr = 'localhost',5000
sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(addr)
sock.listen(3)
while True:
connection, client_address = sock.accept()
data = connection.recv(100000)
print(data.decode('utf-8'))
From this how to guide:
In general, they [socket's recv and send functions] return when the associated network buffers have been filled (send) or
emptied (recv). They then tell you how many bytes they handled. It is your
responsibility to call them again until your message has been completely dealt with.
So, from my understanding, connection.recv(100000) won't return any data until its buffer fills up, so to fix this you would need to set buffer to something low, (maybe 2048?).
Related
I was just trying to make covid vaccine alert using Cowin Setu API (India) in nodejs. But I am facing some strange thing, whenever I hit get request I got 403 response code from cloudfront says 'Request Blocked' but the same is working from postman as well as from browser. Please help me in this
Getting this error:-
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Request blocked.
We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: Q1RZ94qgFp6AjUUKE4e9urMB85VejcqMbaJO6Y8Xq5Qp4kNjDBre9A==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>
Here's my nodejs code:
var express = require("express");
var app = express();
var bodyParser = require("body-parser");
const axios = require("axios");
const { Telegram } = require("telegraf");
const fetch = require("node-fetch");
var cors = require('cors');
var request=require('request');
const tg = new Telegram(process.env.BOT_TOKEN);
const bot = new Telegram(process.env.BOT_TOKEN, {
polling: true
});
//bot.start((ctx) => ctx.reply('Welcom to Covid Vaccine Finder'))
/*bot.hears("about", ctx => {
ctx.reply("Hey, I am CoviBot!");
});
bot.launch();*/
app.use(bodyParser.json());
app.use(cors());
app.use(
bodyParser.urlencoded({
extended: true
})
);
app.get("/", function(req, res) {
res.send("Welcom to Covid Vaccine Finder");
});
app.get("/test", function(req, res, next) {
var d = new Date();
var options = {
year: "numeric",
month: "2-digit",
day: "2-digit"
};
var date = String(d.toLocaleDateString("en", options));
date = date.replace(/\//g, "-");
console.log(date);
const URL =
"https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/findByPinpincode=110088&date=13-05-2021";
var options = {
url: URL,
method: 'GET',
headers: {
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-GB,en;q=0.8,en-US;q=0.6,hu;q=0.4',
'Cache-Control': 'max-age=0',
Connection: 'keep-alive',
Host: 'cdn-api.co-vin.in',
'User-Agent': 'request',
}
};
request(options,function(err,res,body){
let json = body;
console.log(json);
});
const txt = "Finding vaccine centres for you....";
//tg.sendMessage(process.env.GROUP_ID, txt);
res.send(txt);
});
// Finally, start our server
app.listen(process.env.PORT, function() {
console.log("Covid app listening on port 3000!");
});
I hope this problem will solve
Thanks
I added a user-agent header to the request so that the API would recognize that my request is coming from a browser, rather than a script.
headers = {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
}
url = "https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id=303&date="+date
response = requests.get(url, headers=headers)
Use following
var options = {
url: URL,
method: 'GET',
headers: {
Host: 'cdn-api.co-vin.in',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'
}
};
Try These Headers They worked for me on local server (not production)
let options = {
headers: {
"user-agent":
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36",
},
};
These will not work in production because Cowin APIs are geofenced and can't be accessed from IP address other than Indian. In most free hosting sites like Heroku, Indian IP is not an option. So alternative solution might be to use AWS, GCP, Azure with an Indian server (not tried yet).
Reference - https://github.com/cowinapi/developer.cowin/issues/228
It seems the api is blocked from using outside India. Try to combine some Indian proxy/use in Indian server
You have to use User Agent Identifier API
Please refer this
https://devcenter.heroku.com/articles/useragentidentifier#using-with-python
You have to make your request in the following format, I am attaching sample format for states metadata API:
curl --location --request GET 'https://cdn-api.co-vin.in/api/v2/admin/location/states' --header 'Accept-Language: hi_IN' --header 'Accept: application/json' --header 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'
Its not about the request user-agent or format. I faced the same issue and further testing proved cloudFront is blocking the IP if multiple requests are coming from same IP back to back. Its also unblocking after couple minutes.
Basically they don't want these alerting this, probably its overloading their server.
Ok if you want to work local you can use
let headers = {
'accept': 'application/json',
'Accept-Language': 'hi_IN',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36',
}
Now if you want to deploy to Heroku or firebase, then it will return 403, I think it's mostly that they are blocking any IP hit outside from Indian server.
Github link: https://github.com/manojkumar3692/reactjs_nodejs_cowin
I Will keep you posted here
I'm making an api that communicates with a website to pull player statistics. I've made multiple POST/GET HTTP/1 requests to the server to get a session token and player ID. I then use those values(valid values which I have tested before passing to my function) in my last function to fetch player statistics. The last request is a HTTP/2 GET request. I'm using the got library and vanilla Node. Here is my request:
//THESE ALL HAVE SOME VALUE AFTER I USE SOME OF MY FUNCTIONS; THE FUNCTION I'M
//HAVING TROUBLE WITH IS THE LAST FUNCTION AND IS PASSED VERIFIED NON-NULL VALUES
var session = {
app_id: '3587dcbb-7f81-457c-9781-0e3f29f6f56a',
space_id: '5172a557-50b5-4665-b7db-e3f2e8c5041d',
session_id: null,
ticket: null,
};
var player = {
name: null,
id: null,
platform: 'uplay',
kills: null,
deaths: null,
rank: null,
};
async function get_player_stats(session, player) {
var platform = 'PC';
if (player.platform === 'uplay') {
platform = 'PC';
}
var options = {
':authority': 'r6s-stats.ubisoft.com',
':method': 'GET',
':path': `/v1/current/operators/${player.id}?gameMode=all,ranked,casual,unranked&platform=${platform}&teamRole=attacker,defender&startDate=20200723&endDate=20201120`,
':scheme': 'https',
'authorization': `ubi_v1 t=${session.ticket}`,
'ubi-appid': session.app_id,
'ubi-sessionid': session.session_id,
'content-type': 'application/json',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.193 Safari/537.36',
}
const url = `https://r6s-stats.ubisoft.com/v1/current/operators/${player.id}?gameMode=all,ranked,casual,unranked&platform=${platform}&teamRole=attacker,defender&startDate=20200723&endDate=20201120`;
try {
const response = got(url, {headers: options, http2: true});
console.log(response);
}
catch (err) {
console.log(err);
}
}
//FUNCTION CALL
async function fetch(user) {
var stats_string = await get_player_stats(session, player);
console.log(stats_string);
}
fetch(username);
Chrome's request header from network log:
:authority: r6s-stats.ubisoft.com
:method: GET
:path: /v1/current/operators/e96ae749-8939-43ed-895f-bf1817e849d9?gameMode=all,ranked,casual,unranked&platform=PC&teamRole=attacker,defender&startDate=20200723&endDate=20201120
:scheme: https
accept: */
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
authorization: ubi_v1 t= LONG TOKEN
dnt: 1
expiration: 2020-11-21T09:13:54.804Z
origin: https://www.ubisoft.com
referer: https://www.ubisoft.com/
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-site
ubi-appid: 3587dcbb-7f81-457c-9781-0e3f29f6f56a
ubi-sessionid: d78f3306-0e5c-4ac8-ad63-5a711b816f76
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.193 Safari/537.36
Chrome's Response header from network tools:
access-control-allow-credentials: true
access-control-allow-origin: https://www.ubisoft.com
content-encoding: gzip
content-length: 16969
content-type: application/json
date: Sat, 21 Nov 2020 06:14:47 GMT
status: 200
vary: Origin
What I've tried:
I've tried just about everything. I've googled what causes 400 errors, which apparently are mostly user error, and I've looked through my code for days and also looked at Chrome's network activity. I've tried matching Chrome's request header with mine to no avail(my header variable is one of many iterations I've tried--pretty sure I've tried every combination of possible headers). However, sometimes I'll get 400 bad error, or an invalid header response from the server. I've tried using the vanilla Node http2Client.request and that gives me an invalid header/400 as well.
Okay, finally figured out why this wasn't working. I missed one tiny line in what I thought I already tried millions of times.
In the request header on the Chrome Network activity there is a field for expiration.
I needed to set the expiration value in the header to get the data.
So the value I needed to add to my header in my code was:
expiration: 2020-11-21T09:13:54.804Z
Future edit: The expiration is the date in ISO format. You can make a date Object and convert to ISO:
var time = new Date();
var expiration = time.toISOString();
function someRequest() {
var options = {
'expiration': expiration,
}
}
I am using selenium and requests aimed at getting some data from a website. Since the data is acquired by Ajex request, I decided to use requests to imitate the post request. Some parameters are needed in this case. Chrome checking results are as follows:
:authority: www.miaomiaozhe.com
:method: POST
:path: /api/pricehistory/getUrlPriceHistory
:scheme: https
accept: /
accept-encoding: gzip, deflate, br
accept-language: zh-CN,zh;q=0.9
content-length: 3284
content-type: application/x-www-form-urlencoded; charset=UTF-8
cookie: HZBID=db556a075167c32227609e6871911beb; gr_user_id=bd42c97e-3291-4b18-bc37-0c12b367967d;
PHPSESSID=qsksp6v3t4m7880j0ptjshc7u7; MMZUFLAG=104163326; MMZUSS=3531fecdefc1b40c34c9b568cde18326; gr_session_id_b49be8fba0e9e60a=74e18968-dad1-449d-b248-71c2b2d855cd; gr_session_id_b49be8fba0e9e60a_74e18968-dad1-449d-b248-71c2b2d855cd=true
origin: https://www.miaomiaozhe.com
referer: https://www.miaomiaozhe.com/pricehistory
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36
x-requested-with: XMLHttpRequest
Above are the request headers of the post.
and the form data is as follows:
As is shown in the picture, there is a parameter named nvcVal in the post.
by checking the JS codes of the website, I found it's from nvcVal: window.getNVCVal().
so I coded the following codes to get the data.
from time import sleep
import requests
import json
chrome_opt = webdriver.ChromeOptions()
prefs = {"profile.managed_default_content_settings.images": 1}
# chrome_opt.add_experimental_option("prefs", prefs)
# chrome_opt.add_experimental_option('excludeSwitches', ['enable-automation'])
chrome_opt.add_argument('user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36"')
driver = webdriver.Chrome(chrome_options=chrome_opt)
driver.get("https://www.miaomiaozhe.com/pricehistory")
# driver.find_element_by_class_name('pl').click()
good3 = "https://detail.tmall.com/item.htm?spm=a220m.1000858.1000725.1.e748471bZmg76Q&id=594572481181&skuId=4360012669001&areaId=420100&user_id=1809177149&cat_id=2&is_b=1&rn=04e4c83fcb68c340abf88983da82b1b7"
good2 = "https://detail.tmall.com/item.htm?spm=a220m.1000858.1000725.7.e748471bIRN6jQ&id=554640570620&skuId=4341085905022&areaId=420100&user_id=2928380385&cat_id=2&is_b=1&rn=6ba9712cf53485a574d73191e05d0cbf"
goodURL = "https://detail.tmall.com/item.htm?id=569343149791&spm=875.7931836/B.2017081.2.66144265gU7Lgd&scm=1007.12144.81309.73299_0_0&pvid=10ae9600-6e84-4ad0-8e1e-a8379cea71c3&utparam=%7B%22x_hestia_source%22:%2273299%22,%22x_object_type%22:%22item%22,%22x_mt%22:9,%22x_src%22:%2273299%22,%22x_pos%22:1,%22x_pvid%22:%2210ae9600-6e84-4ad0-8e1e-a8379cea71c3%22,%22x_object_id%22:569343149791%7D"
driver.find_element_by_id('ipt').send_keys(good3)
# driver.find_element_by_id('search-btn').click()
sleep(2)
js = " return window.getNVCVal()"
nvcVal = driver.execute_script(js)
print("nvcVal = "+str(nvcVal))
# new_nvcVal = "%7B%22a%22%3A%22FFFF0N0N000000006AFF%22%2C%22c%22%3A%221590723506842%3A0.99342660331515%22%2C%22d%22%3A%22nvc_activity%22%2C%22h%22%3A%7B%22key1%22%3A%22code0%22%2C%22nvcCode%22%3A400%2C%22umidToken%22%3A%22T21B886C0F961A98E862F5CF69393964795B83A19E0D643903B04E06AD6%22%7D%2C%22j%22%3A%7B%22test%22%3A1%7D%2C%22b%22%3A%22124%23YhFPnxFZxG0xA7yf6JMuAlDS%2BUOvpV9oiw8W9aZ3qg%2FOqdJA%2Fe%2BbSWcxIK5G%2FETKzoSdFuvXCK%2BnhxCNTe1hYMCi6JdG32LOCkudgS9CR6yNrGk8moL4XOOzVHI8Xm%2Bl0i8EJrE8p1Rc0hsLv%2Fef58%2FZCD0mxKtronkZ6a84khvKaJtwZvIENL4eTBPXNywFpTcpLoDJy3LZLgR1UkkoaT%2F%2Ba8aXsPY73H92xbk3epwEzEoezisui2xzIi7Ji20WFFfm7s52HyARgOzgfXs5kTtIQlcj%2BJYcpA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BztEtxqUkbXFTI44Jg3fQL4AgAKAuC%2Ftv7vNFGHHz6NZeCs5idxQleLgz5EmqrXWboLBwppQcWkXFh35VFqXyC0JfGIeE743B9stqjO5H5jbyD4qy1vsISbm0G0LzGrXkZUgHBThjBRinW78jnWKYdlHB%2F5AR2IZG1XdV6nIoj10twUTIdLuZ0fR6JsbLZXW%2Fn%2F%2FbPv6O9yfqz4Co2JjPaIL8NTwX9vxnpi%2Fg8i8EhXB1dy6iJwT7btl1AmVWx4dnsCHOcHjcTKAd%2BwvYEWJavJIvCI8FcfqStlLbJDoHl2bOo9W6UedB35e5V9WpyHrqy8pSkfuRzm9T5hlgwjEFB6%2FzgFbyADaV0Z9JP3I3Q7F%2BsWzUEBGmKbC3LsuZ2khjquN2Be9BJ%3D%22%2C%22e%22%3A%22KfLnQbaexlHsDdRdQx0L4Q0fMePRlUSPsuteAtUngD99tuEUdiugeouLEJG0uvIa-9Z-k-lQ6fL3lpbcTxPN4fk9Wu-Q71ExCDYni5eDYwVSG_W5NXXiw0SnMK_GknTTTFhOiVDaaNOdAoCLDoRnw7GQkCz_wBSon-RNF-5mxkqAc4zx0vPSPsaMl7xGzFOWYizM9JlKkpiqJYbEB2zQGA%22%7D"
# res = driver.execute_script("return " + ajax_query)
url = "https://www.miaomiaozhe.com/api/pricehistory/getUrlPriceHistory"
data = {'url': good3, 'nvcVal': nvcVal}
header = {"authority": "www.miaomiaozhe.com", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36"}
# cookie = {"HZBID":"db556a075167c32227609e6871911beb", "gr_user_id":"bd42c97e-3291-4b18-bc37-0c12b367967d", "PHPSESSID":"qsksp6v3t4m7880j0ptjshc7u", "MMZUFLAG":"104163326", "MMZUSS":"3531fecdefc1b40c34c9b568cde18326", "gr_session_id_b49be8fba0e9e60a":"c1c318c3-8db5-4bbd-8f78-e893b0dea1ec", "gr_session_id_b49be8fba0e9e60a_c1c318c3-8db5-4bbd-8f78-e893b0dea1ec":"true"}
req = requests.post(url, data, headers=header)
print(req.text)
driver.close()'''
I failed, unawaring what's been wrong.
I guess it could be the problem of the parameter of nvcVal, but I don't have any idea how I can get it right.
I want to extract specific values from http request headers, below is an example of the header information
GET ***/agencychannel-uiapiservices/api/ken/AccountProfile/GetAccountProfileWithViewingPeriod*** HTTP/1.1
Cookie: __utma=132118163.703100490.1447412805.1456837339.1458655276.3; _em_vt=98cf395181af797bbccffc582cf957fe2438c7f254-0905822558184c34; A03RNB-PHRS2-80-PORTAL-PSJSESSIONID=a1Sfb2ZGJdR4VlBvyDvRDxSHOseo9kZa!-351035759; https%3a%2f%2fpeoplesoft.multichoice.co.za%2fpsp%2fhrprd%2femployee%2fhrms%2frefresh=list:%20%3Ftab%3Dhc_ux_manager_dashboard%7C%3Frp%3Dhc_ux_manager_dashboard%7C%3Ftab%3Dhc_talent_summary%7C%3Frp%3Dhc_talent_summary%7C%3Ftab%3Dremoteunifieddashboard%7C%3Frp%3Dremoteunifieddashboard
Host: ***apidtgateway.multichoice.co.za:9800***
Accept: */*
Content-Type: application/json
Accept-Language: en-ZA,en-GB;q=0.8,en-US;q=0.6,en;q=0.4
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36
Connection: keep-alive
komodo-sessiontoken: a2f960a2-f359-4ed9-a926-41630d37ae06
Accept-Encoding: gzip, deflate, sdch
When I get the request I need to extract the host and the path, end results should be like this apidtgateway.multichoice.co.za:9800/agencychannel-uiapiservices/api/ken/AccountProfile/GetAccountProfileWithViewingPeriod
Example
function TControllerAplicacao.EchoString(Value: string): string;
var
objWebModule: TWebModule; //need Web.HTTPApp
host :string;
xxx :string;
begin
objWebModule := GetDataSnapWebModule; //need Datasnap.DSHTTPWebBroker
host := objWebModule.Request.host;
//see on Delphi IDE other possibilities, code complete will show to you)
//key header that you know the name, is possible to be custom header:
xxx := objWebModule.Request.GetFieldByName('Content-Type');
Result := Value; //from original datasnap example EchoString
end;
I'm writing my own script to connect to a websocket server with JavaScript using the WebSocket API. I'm having problems with the connection closing straight away.
Here's the client side script:
var host = 'ws://localhost:8080';
try
{
debug.add('Connection request submitted for ' + host);
socket = new WebSocket(host);
debug.readyStateListener();
debug.add('Socket request started');
socket.onopen = function()
{
debug.add('Connection opened');
}
socket.onmessage = function(message)
{
debug.add('data received ' + message.data);
}
socket.onclose = function()
{
debug.add('Connection closed');
}
}
catch(e)
{
debug.add('WebSockets error ' + e.toString() );
}
This is the debug I receive:
Connection request submitted for ws://localhost:8080
socket readyState change to 0
Socket request started
socket readyState change to 3
Connection closed
The debug.readyStateListener() polls socket.readyState for changes. What's happening is it changes to 0 meaning the connection is opening, then straight away changes to 3 that the connection has been closed.
The server receives the connection fine but the connection is then closed straight away by the client.
I've tried it in Opera 11 with WebSockets enabled and in the latest version of Chrome. Both time's I get the same result.
I can communicate perfectly with the server through a raw connection, or simply by visiting http://localhost:8080/ in my browser this is the result:
GET / HTTP/1.1
User-Agent: Opera/9.80 (Windows NT 6.1; U; IBM EVV/3.0/EAK01AG9/LE; en) Presto/2.9.168 Version/11.51
Host: localhost:8080
Accept: application/xhtml+voice+xml;version=1.2, application/x-xhtml+voice+xml;version=1.2, text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
Accept-Language: nl-NL,nl;q=0.9,en;q=0.8
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
The connection also stays alive without any flaws by sending a request through http until I end it.
Going through the JavaScript WebSocket API the server receives this request:
GET / HTTP/1.1
Host: localhost:8080
Origin: http://localhost
Upgrade: WebSocket
Sec-WebSocket-key1: L58(b Q]'9 4 9\ 0 *+ 6 a4
Connection: Upgrade
Sec-WebSocket-Key2: \+ 1 5d/9541840N*4
My last guess would be Connection: upgrade or Upgrade: WebSocket not being supported properly by the client. To me it would be more logical to receive Connection: keep-alive but I have no idea how to reslove this.