Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server sent event (SSE) incorrect data format [SPR-16459] #21004

Closed
spring-projects-issues opened this issue Feb 2, 2018 · 6 comments
Closed

Server sent event (SSE) incorrect data format [SPR-16459] #21004

spring-projects-issues opened this issue Feb 2, 2018 · 6 comments
Assignees
Labels
in: web status: invalid

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Feb 2, 2018

Alexis opened SPR-16459 and commented

hi, when using webflux with SSE, it is not working under Firefox 52. It is working on last chrome and last FF (57)

to me it comes from that the text/event-stream produced is not complient with
http://www.w3.org/TR/eventsource/#event-stream-interpretation

The problem is similar than herehttps://stackoverflow.com/questions/18800540/javascript-sse-not-working-with-firefox

the produced response misses two \n\n
here is a correct response

data: The server time is: Fri, 02 Feb 2018 06:45:51 -0500

The problem appears if I return a

Flux<User>

or a

Flux<ServerSentEvent<User>>

here is the data corrupted where it misses a \n:

data: The server time is: Fri, 02 Feb 2018 06:45:51 -0500

here is a working exemple with FF52 (for proof)
https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_sse


Affects: 5.0.2

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 2, 2018

Rossen Stoyanchev commented

We do output lines, with an empty line between events. Your example of corrupted data also shows that. What exactly is missing?

I get the following with an Object serialized to JSON which looks correct to me:

$ curl -v -H "Accept:text/event-stream" http://localhost:8080/sse/person
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /sse/person HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.47.0
> Accept:text/event-stream
> 
< HTTP/1.1 200 OK
< transfer-encoding: chunked
< Content-Type: text/event-stream
< 
data:{"name":"foo 0"}

data:{"name":"foo 1"}

data:{"name":"foo 2"}

^C

And ServerSentEvent:

 
$ curl -v -H "Accept:text/event-stream" http://localhost:8080/sse/event
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /sse/event HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.47.0
> Accept:text/event-stream
> 
< HTTP/1.1 200 OK
< transfer-encoding: chunked
< Content-Type: text/event-stream
< 
id:0
:bar
data:foo

id:1
:bar
data:foo

id:2
:bar
data:foo

^C

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 2, 2018

Alexis commented

I think your script (server) is not working on FF 52.
here https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_sse you can see that there is two empty line, not one.
see

****
data: The server time is: Fri, 02 Feb 2018 16:01:56 -0500


****

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 3, 2018

Alexis commented

One more clue maybe not the \n problem, Testing same thing on two different machins with FF ESR 52.6

here is the code

@GetMapping(path = "/persons", produces = "text/event-stream")
	Flux<Long> getPersons() {
	    return Flux.interval(Duration.ofSeconds(1));
	}

this is the data request/response from the one Ko:

Request URL:
http://localhost:9000/sse
Request Method:
GET
Status Code:
200
Remote Address:
[::1]:9000
Referrer Policy:
no-referrer-when-downgrade
Response Headersview source
Content-Type:
text/event-stream;charset=UTF-8
Date:
Sat, 03 Feb 2018 02:56:35 GMT
Transfer-Encoding:
chunked
Request Headersview source
Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding:
gzip, deflate, br
Accept-Language:
fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7
Connection:
keep-alive
Host:
localhost:9000
Upgrade-Insecure-Requests:
1
User-Agent:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36

this is the one working:

general
Request URL:http://localhost:8080/persons
Request Method:GET
Status Code:200 OK
Remote Address:[::1]:8080
Referrer Policy:no-referrer-when-downgrade
response header
HTTP/1.1 200 OK
transfer-encoding: chunked
Content-Type: text/event-stream
request header
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.9
Cache-Control:max-age=0
Connection:keep-alive
Cookie:_ga=GA1.1.1987494875.1471349669
Host:localhost:8080
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/64.0.3282.119 Chrome/64.0.3282.119 Safari/537.36

could it be the UTF-8 encoding? to me it should not. I try force encoding with

produces = "text/event-stream;charset=UTF-8"

but it does not appear in the response of the working one :\

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 5, 2018

Rossen Stoyanchev commented

It's still not clear to me what in the output we produce is wrong, or not spec compliant. I think you're suggesting that there should be two empty lines between events? This is not true. The spec says:

Lines must be processed, in the order they are received, as follows:

If the line is empty (a blank line)
    Dispatch the event, as defined below.

The spec doesn't have many examples but you can see some on the Mozilla help page with line numbers so it's clear. As for the W3C link, that's not producing a proper stream, but it seems to be polling with SSE which makes no sense.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 8, 2018

Alexis commented

Indeed you're right, I have a strange problem on my setup,
if I hit http://localhost:9000/sse with FF it never respond but
if I hit http://[myIpInTheNetwork]:9000/sse it works ...

as I do not understand the difference, I think you can close this and say that spring is not the gulty.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 9, 2018

Sébastien Deleuze commented

Indeed from a CORS POV localhost and myIpInTheNetwork are 2 distinct origins and should be both declared if you want to support both use cases.

@spring-projects-issues spring-projects-issues added type: bug status: invalid in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web status: invalid
Projects
None yet
Development

No branches or pull requests

2 participants