atmosphere icon indicating copy to clipboard operation
atmosphere copied to clipboard

SSE doesn't output error bodies, just spaces

Open byteit101 opened this issue 1 year ago • 0 comments

Describe the bug SSE transport doesn't allow error bodies to be written, unlike other transports:

(Full source based on samples used in the curl requests is at https://gist.github.com/byteit101/63c5fe645cbfa7e2222948bd77e72d51 )

		if (r.transport() != TRANSPORT.SSE)
			return Response.status(Status.BAD_REQUEST).entity("SSE is the only thing supported").build();
		else
			return Response.status(451).entity("{my-error-body}").build();

Atmosphere Info

  • version 2.7.7

Expected behavior long-polling (actual, correct):

$ curl -s -i -X GET 'http://localhost:8080/chat/the/sse/error' -H 'Accept: text/event-stream,application/json'                           
HTTP/1.1 400 Bad Request
(snip)
Content-Length: 31

SSE is the only thing supported%
$ 

SSE (theoretical response):

$ curl -s -i -X GET 'http://localhost:8080/chat/the/sse/error?X-Atmosphere-Transport=sse' -H 'Accept: text/event-stream,application/json'
HTTP/1.1 451 
(snip)
Content-Length: 15

{my-error-body}%
$

Actual behavior SSE:

$ curl -s -i -X GET 'http://localhost:8080/chat/the/sse/error?X-Atmosphere-Transport=sse' -H 'Accept: text/event-stream,application/json'
HTTP/1.1 451 
(snip)
Content-Length: 15

               %
$

Interestingly, the length (and number of spaces) is the correct size. Note I used the terminal garbage % to show the end of line as there was no newline.

Systems (please complete the following information):

  • OS: linux x64
  • Browser name and version: N/A
  • Java version and distribution: OpenJDK 1.8 && 11
  • Server name and version: Jetty

Additional context A "normal" sse call has lots of spaces, I'm not sure if it's relevant but I noticed it:

$ curl -s -i -X GET 'http://localhost:8080/chat/the/sse/normal?X-Atmosphere-Transport=sse' -H 'Accept: text/event-stream,application/json'
HTTP/1.1 200 OK
(snip)
Transfer-Encoding: chunked

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
data:suspend

data:X

^C
$

byteit101 avatar Sep 19 '22 15:09 byteit101