Chrome продолжает посылать GET для SSE - PullRequest
0 голосов
/ 09 марта 2020

Почему браузер (Chrome) продолжает отправлять GET-запросы на SSE (события, отправленные сервером)? Любая идея, почему?

Я запускаю функцию «subscribeMe» ниже один раз , нажимая кнопку на странице HTML.

Я понимаю, что SSE работает только один GET отправляется, и один 200 OK получен .. затем с изменениями сервер только проталкивает «данные: .....» через постоянно открытое соединение TCP HTTP / HTTPS.

const state = ['connecting', 'open', 'closed'];
let EPEvent;
function subscribeMe() {
  EPEvent = new EventSource(`/event/${window.sessionStorage.getItem("Token")}/EPRegistration`);
  EPEvent.onmessage = function (e) { console.log(state[this.readyState]); console.log(e); console.log(JSON.parse(e.data)) }
  EPEvent.onopen = function () { console.log(state[this.readyState]) }
}
GET /event/MTSE-960a8337-1f95-495c-a313-92659ba8ba5d/EPRegistration HTTP/1.1
Host: 192.168.1.2
Connection: keep-alive
Accept: text/event-stream
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36
Referer: http://192.168.1.2/manage
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8

HTTP/1.1 200 OK
Connection: keep-alive
Content-Type: text/event-stream
Cache-Control: no-cache
Date: Sun, 08 Mar 2020 21:07:45 GMT
Server: Home SE
Content-Length: 14

data: null

GET /event/MTSE-960a8337-1f95-495c-a313-92659ba8ba5d/EPRegistration HTTP/1.1
Host: 192.168.1.2
Connection: keep-alive
Accept: text/event-stream
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36
Referer: http://192.168.1.2/manage
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8

HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: keep-alive
Content-Type: text/event-stream
Date: Sun, 08 Mar 2020 21:07:48 GMT
Server: Home SE
Content-Length: 14

data: null

GET /event/MTSE-960a8337-1f95-495c-a313-92659ba8ba5d/EPRegistration HTTP/1.1
Host: 192.168.1.2
Connection: keep-alive
Accept: text/event-stream
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36
Referer: http://192.168.1.2/manage
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8

HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: keep-alive
Content-Type: text/event-stream
Date: Sun, 08 Mar 2020 21:07:51 GMT
Server: Home SE
Content-Length: 14

data: null

GET /event/MTSE-960a8337-1f95-495c-a313-92659ba8ba5d/EPRegistration HTTP/1.1
Host: 192.168.1.2
Connection: keep-alive
Accept: text/event-stream
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36
Referer: http://192.168.1.2/manage
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8

HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: keep-alive
Content-Type: text/event-stream
Date: Sun, 08 Mar 2020 21:07:54 GMT
Server: Home SE
Content-Length: 14

data: null

GET /event/MTSE-960a8337-1f95-495c-a313-92659ba8ba5d/EPRegistration HTTP/1.1
Host: 192.168.1.2
Connection: keep-alive
Accept: text/event-stream
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36
Referer: http://192.168.1.2/manage
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8

HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: keep-alive
Content-Type: text/event-stream
Date: Sun, 08 Mar 2020 21:07:57 GMT
Server: Home SE
Content-Length: 14

data: null

GET /event/MTSE-960a8337-1f95-495c-a313-92659ba8ba5d/EPRegistration HTTP/1.1
Host: 192.168.1.2
Connection: keep-alive
Accept: text/event-stream
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36
Referer: http://192.168.1.2/manage
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8

HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: keep-alive
Content-Type: text/event-stream
Date: Sun, 08 Mar 2020 21:08:00 GMT
Server: Home SE
Content-Length: 14

data: null

1 Ответ

0 голосов
/ 09 марта 2020

Исправлено!

Я не должен был указывать 'Content-Length' в своем ответе! .. Это поток, Content-Length не имеет смысла.

Теперь он работает нормально.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...