hyper-prog / hasses

Hyper's Asynchronous Server Sent event (SSE) notification Server
http://hyperprog.com/hasses/index.html
GNU General Public License v2.0
24 stars 9 forks source link

Can't Encode Messages (JSON) With Semi-Colon (;) #6

Closed dtcooper closed 3 years ago

dtcooper commented 3 years ago

To reproduce, run hasses in first shell,

docker run -p 8080:8080 -p 8085:8085 hyperprog/hassesdaemon

Then subscribe and wait in another shell,

curl -H 'Connection: keep-alive' http://localhost:8080/sse?subscribe=all

Finally, test out some JSON as a message in third shell,

echo '*={"test": "; semi-colon"};' | nc localhost 8085

Expected:

id: 1234567890
data: {"test": "; semi-colon"}

However, I get the following along with this error message in the hasses shell: Wrong formatted message from communication channel (2), ignored.

id: 1234567890
data: {"test": "

Is there a way to encode a semi-colon for JSON purposes here?

Thanks,

David

dtcooper commented 3 years ago

(I suppose I could just use unicode escape character \u003b)

venkyvxl commented 3 years ago

@dtcooper , in hasses.c+1020, @hyper-prog made a specific check to look for semicolon as delimiter and trimming the message before sending the remaining message. But I believe, unfortunately this doesnt work when we have message format as token=data where every data segment needs token else it gets failed in sendmessages api of chat.c. @hyper-prog , can you let us know, why semicolon as delim is added to trim the message..

hyper-prog commented 3 years ago

Hi, All! The answer is located in the main readme under the "Debugging" title where the available commands are listed. "<token>=<message>;<token2>=<message2>" - Send more messages

The hasses can receive more commands in one message in a way the commands are separated by semicolon. (Just like unix commands) So it means that hasses not only trim semicolons, it splits the incoming data by semicolons and interprets the commands each. This is a feature of hasses, not come from SSE specification. To avoid this problem, I suggest you to encode the JSON data with base64.

dtcooper commented 3 years ago

Sounds good. I'll use {"key": "\u003b <rest of JSON string...>"}" for JSON for my needs. Cheers and thanks for hasses!