Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl Server Sent Event no output when pipe

I trying to use sse to tail log from server, curl works fine with sse, but when piped, curl will not output anything

# This is ok
curl localhost:8080/logging/tail

OUTPUT

data:2017-06-14 11:57:21.345  WARN 56999 --- [nio-8080-exec-4] a.b.c    : ABC


data:2017-06-14 11:57:21.353  INFO 56999 --- [nio-8080-exec-4] a.b.c    : DEF

With pipe

# Nothing show up, with -s or not
# Without -s, the process show's curl do receive data
curl -s localhost:8080/logging/tail | sed '/^\s*$/d'
curl -s localhost:8080/logging/tail | cat

How to make curl sse work with pipe ? I want to remove the data: prefix and the empty lines for sse output.

$ curl --version
curl 7.51.0 (x86_64-apple-darwin16.0) libcurl/7.51.0 SecureTransport zlib/1.2.8
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz UnixSockets

Server is spring SseEmitter.

like image 603
wener Avatar asked Sep 17 '25 15:09

wener


1 Answers

As per this answer, you can add either --no-buffer or -N to the curl command

-N / --no-buffer

like image 129
user591948 Avatar answered Sep 20 '25 04:09

user591948