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

Bug: Extraneous whitespace in event data and extra newline at the end #10

Open
AilurusRP opened this issue Apr 14, 2023 · 0 comments
Open
Labels
bug Something isn't working

Comments

@AilurusRP
Copy link

Bug description

There is extraneous whitespace at the beginning of each line of the event data retrieved from event.data property. I believe this is because the library treats the space between "data:" and the message body in SSE format as part of the message body.

In addition, there is an extra newline character at the end of the event data, which causes some parsing issues.

Steps to reproduce

Create an SSE server with Express.js that returns a text chunk as shown below:

  res.write(`data: part-1\n`);
  res.write(`data: part-2\n`);
  res.write(`data: part-3\n\n`);

Create an SSE client with flutter_client_sse :

SSEClient.subscribeToSSE(
    url: 'http://<My Server Url>/events', 
    header: {
        "Accept": "text/event-stream",
    }).listen((event) {
        event.data?.split("").forEach((element) {
            print("$element ${element.codeUnitAt(0)}");
    });
});

Then print each char and its ascii code of the event.data string after receiving data from the server:

I/flutter ( 1067): --SUBSCRIBING TO SSE---
I/flutter ( 1067):   32
I/flutter ( 1067): p 112
I/flutter ( 1067): a 97
I/flutter ( 1067): r 114
I/flutter ( 1067): t 116
I/flutter ( 1067): - 45
I/flutter ( 1067): 1 49
I/flutter ( 1067):  10
I/flutter ( 1067):   32
I/flutter ( 1067): p 112
I/flutter ( 1067): a 97
I/flutter ( 1067): r 114
I/flutter ( 1067): t 116
I/flutter ( 1067): - 45
I/flutter ( 1067): 2 50
I/flutter ( 1067):  10
I/flutter ( 1067):   32
I/flutter ( 1067): p 112
I/flutter ( 1067): a 97
I/flutter ( 1067): r 114
I/flutter ( 1067): t 116
I/flutter ( 1067): - 45
I/flutter ( 1067): 3 51
I/flutter ( 1067):  10

It can be observed from the output that there is an extraneous whitespace (ASCII code 32) at the beginning of each line, and an extra newline character (ASCII code 10) at the end of the entire message block.

@pratikbaid3 pratikbaid3 added the bug Something isn't working label Apr 14, 2023
@pratikbaid3 pratikbaid3 added enhancement New feature or request and removed enhancement New feature or request labels Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants