'cURL on Mac is not outputting streaming result even with -N

I have a Spring Boot streaming result set that should never stop sending data to the client, and it seems to be working:

@RestController
class GreetingRestController {
    @GetMapping("/delayed")
    fun getGreetingsDelayed(): Publisher<Greeting> {
        var counter = 0;
        val gf = Flux.generate<Greeting>{
            it.next(Greeting("Hello ${Instant.now()}"))
            println("Returning ${Instant.now()} ${counter++}")
        }.delayElements(Duration.ofSeconds(1))
        return gf
    }

I am trying to consume this with curl on my Mac:

curl -v -N localhost:8080/delayed

Here is the output:

* Connected to localhost (::1) port 8080 (#0)
> GET /delayed HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.77.0
> Accept: */*
> 

I can leave it for an hour (3600 records produced) and it never changes, but I can see Spring's log messages generating more items to send to the client.

If I add a .take(20) to my producer in Spring (to make it print 20 times and stop) then my curl script will finish after that and print the output, so I know it's working...

I tried disabling the buffering with -N but it's not working.

How do I make curl print these in real-time?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source