Package: groovy.http

## [Groovy] Class HttpStreamResult

- groovy.http.HttpStreamResult

-     @Incubating
      @RecordType
      class HttpStreamResult
      extends Object

  Streaming response wrapper for HttpBuilder's `streamAsync` family.

  Unlike HttpResult, this does not buffer the response body. The body is exposed as a Flow.Publisher of byte chunks that can be consumed incrementally — typically via `for await (chunk in result.bodyAsPublisher())` once the `groovy-concurrent-java` `FlowPublisherAdapter` is on the classpath.

  Parameters:
    `status` - the HTTP status code
    `headers` - the response headers
    `raw` - the underlying JDK streaming response
  Since:
    6.0.0

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `static class` | `HttpStreamResult.LinePublisher` | Adapts a chunked byte publisher into a publisher of complete lines.
    `static class` | `HttpStreamResult.MappedPublisher` | One-shot mapping Flow.Publisher that delegates subscription to a source publisher and applies a transformer per signalled item.
    `static class` | `HttpStreamResult.MappingSubscriber` | Subscriber that applies a mapping closure before forwarding items downstream.

  - ### Properties Summary

    Properties
    Type | Name and description
    --- | ---
    `HttpHeaders` | `headers`
    `HttpResponse<Flow.Publisher<List<ByteBuffer>>>` | `raw`
    `int` | `status` Streaming response wrapper for HttpBuilder's `streamAsync` family.

  - ### Constructor Summary

    Constructors
    Constructor and description
    `HttpStreamResult(Publisher<List<ByteBuffer>> response)` Creates a streaming result wrapper from a JDK HTTP response.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `Flow.Publisher<String>` | `bodyAsLinePublisher(Charset charset)` Returns the response body as a publisher of newline-terminated strings.
    `` | `Flow.Publisher<List<ByteBuffer>>` | `bodyAsPublisher()` Returns the response body as a publisher of `List<ByteBuffer>` chunks, exactly as JDK `HttpResponse.BodyHandlers.ofPublisher()` provides it.
    `` | `Flow.Publisher<String>` | `bodyAsTextPublisher(Charset charset)` Returns the response body as a publisher of decoded strings, one per arriving chunk.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Property Detail

    - #### final HttpHeaders headers

    - #### final HttpResponse<Flow.Publisher<List<ByteBuffer>>> raw

    - #### final int status

      Streaming response wrapper for HttpBuilder's `streamAsync` family.

      Unlike HttpResult, this does not buffer the response body. The body is exposed as a Flow.Publisher of byte chunks that can be consumed incrementally — typically via `for await (chunk in result.bodyAsPublisher())` once the `groovy-concurrent-java` `FlowPublisherAdapter` is on the classpath.

      Parameters:
        `status` - the HTTP status code
        `headers` - the response headers
        `raw` - the underlying JDK streaming response
      Since:
        6.0.0

  - ### Constructor Detail

    - #### HttpStreamResult(Publisher<List<ByteBuffer>> response)

      Creates a streaming result wrapper from a JDK HTTP response.

      Parameters:
        `response` - the response to wrap
      Since:
        6.0.0

  - ### Method Detail

    - #### Flow.Publisher<String> bodyAsLinePublisher(Charset charset)

      Returns the response body as a publisher of newline-terminated strings. Useful for line-oriented streaming protocols (NDJSON, SSE without event framing, log tails). Trailing partial lines are emitted on completion.

      Parameters:
        `charset` - the charset to decode bytes with (defaults to UTF-8)
      Since:
        6.0.0

    - #### Flow.Publisher<List<ByteBuffer>> bodyAsPublisher()

      Returns the response body as a publisher of `List<ByteBuffer>` chunks, exactly as JDK `HttpResponse.BodyHandlers.ofPublisher()` provides it.

      Since:
        6.0.0

    - #### Flow.Publisher<String> bodyAsTextPublisher(Charset charset)

      Returns the response body as a publisher of decoded strings, one per arriving chunk. Each emitted string corresponds to one upstream HTTP frame (often a complete SSE event or a JSON line, but boundaries are not guaranteed). Use bodyAsLinePublisher for line-aligned delivery.

      Parameters:
        `charset` - the charset to decode bytes with (defaults to UTF-8)
      Since:
        6.0.0