Product knowledge · Advanced · Bounded data flow

Streaming is not a very large buffered body.

Buffering keeps code simple for small bounded payloads. Streaming adds chunk ownership, pressure, cancellation, trailers and cleanup; choose it only when incremental flow provides real value.

01 · Choose the body shape

Start buffered; switch for a measured reason

ShapeUse whenRequired bounds
Buffered requestSmall payload; handler needs the complete value.Per-request bytes, active work and retained application copies.
Streamed requestLarge upload or incremental processing without whole-body retention.Chunk bytes/count, retained chunks, progress deadline and storage queue.
Buffered responseSmall response with known complete bytes.Response bytes; compression still has workspace/eligibility limits.
Streamed responseIncremental generation or early first byte.Chunk bytes/count, pending output, writability wait and write timeout.

Streaming does not remove per-request or service capacity. It changes ownership shape; it never grants unlimited memory, tasks or disk queue.

02 · Request stream lifecycle

Many events, one ownership chain

1

Start

Route/admission is accepted; application prepares bounded parser and storage state.

2

Data

Consume or copy a borrowed chunk within connector lifetime; never retain a view after its callback.

3

Trailers + end

Trailers exist only after EOF. Finalize validation/storage, then respond exactly once.

4

Cancel/dispose

Release chunks, temporary files and app state idempotently; dispose does not imply HTTP success.

03 · Upload ownership

Reading bytes does not make a file safe

Runtime-owned

Wire parsing, admission, body/chunk ceilings, phase timeout, cancellation and transport outcome.

Connector-owned

Host callback/value projection, borrowed/copy law and callback, GC or FFI lifetime.

Application-owned

Media type, filename policy, antivirus/schema/hash, storage path, quota, atomic publication and cleanup.

Completion law

Publish only after EOF, validation and storage success. Peer disconnect may require cleanup without a response.

Upload differs from file response/sendfile. Download grants Core a confined file authority. Upload still requires bounded request consumption and application storage policy.

Run the upload labs · Multipart streaming

Read an upload in your language

Register a streaming POST on a standalone listener and set a body size limit. Read a small chunk at a time and count it against that limit. A short read is not the end; wait for EOF or the end event before checking trailers or reporting success.

C/C++

Set COAKKA_HTTP_HOST_ROUTE_STREAMING_REQUEST in the route flags. Handle COAKKA_HTTP_HOST_REQUEST_DATA, then optional COAKKA_HTTP_HOST_REQUEST_TRAILERS and COAKKA_HTTP_HOST_REQUEST_END. Release each event after reading it. On COAKKA_HTTP_HOST_REQUEST_CANCELLED, discard partial output.

Go

Register PostStream. Read request.Body as an io.Reader until EOF, then read request.Trailers. Stop and clean up on a read error.

Kotlin / Java

Register postStream. Read the InputStream from request.body (Kotlin) or request.getBody() (Java). Read the trailers after EOF.

Python

Register post_stream. Read bounded chunks from request.body_reader, then check request.trailers when the stream is complete.

Node.js / Bun

Register postStream. Prepare per-request state on start, consume chunks on data, and read end.trailers on end. Release state on dispose; disposal does not imply success.

If the caller disconnects during upload, discard the partial file. For the other direction, the SSE exercise shows how to send a response as a stream.

04 · Multipart

Bound structure before trusting content

Fields / parts
Finite count; reject excess before allocating unbounded application state.
Names / headers
Bound count and bytes; filename and content type remain untrusted metadata.
Part / total bytes
Bound each part and the complete request; streaming does not remove total policy.
Temporary state
Bound memory/disk and define owner/cleanup for end, cancel, timeout, disconnect and close.

05 · Response stream lifecycle

Writability is temporary permission, not a queue

start response with status + initial headers
  → wait until writable
  → submit bounded chunk
  → repeat while producer and exchange are live
  → finish once with optional trailers

cancel / timeout / closed → stop producer → release retained state

The producer stops when the exchange is terminal. Never busy-loop while unwritable, retain an unbounded backlog, write after finish/cancel, or assemble HTTP chunk framing yourself.

Advanced · HTTP/1.1 · gzip

Enable gzip for eligible buffered responses

Start from the first HTTP/1.1 service for your language. Keep the handler response as plain text; Core decides whether to compress it based on the policy, body, and Accept-Encoding. Use a repetitive text body of at least 256 bytes for this lab.

Add the configuration before Start() / start(). The native C and C++ first programs also need the response header shown below.

C/C++
C/C++
configuration.compression.enabled = 1U;
configuration.compression.minimum_body_bytes = 1U;

// Before submitting the response:
const coakka_http_host_header_t type = {bytes("content-type"), bytes("text/plain")};
response.headers = &type;
response.header_count = 1U;
Go
Go
.Compression(&coakkahttp.Compression{
    Mode:             coakkahttp.CompressionGZIP,
    MinimumBodyBytes: 1,
})
Kotlin/JVM
Kotlin/JVM
import coakka.http.Compression
import coakka.http.CompressionMode

// Add to ServiceBuilder:
.compression(Compression(mode = CompressionMode.GZIP, minimumBodyBytes = 1))
Java/JVM
Java/JVM
import coakka.http.Compression;
import coakka.http.CompressionMode;

// Add to ServiceBuilder:
.compression(new Compression(CompressionMode.GZIP, 1L))
Python
Python
from coakka_http import Compression, CompressionMode

# Add to Builder:
.compression(Compression(mode=CompressionMode.GZIP, minimum_body_bytes=1))
Node.js
Node.js
import { CompressionMode } from "coakka-http-runtime-node";

// Add to Builder:
.compression({ mode: CompressionMode.GZIP, minimumBodyBytes: 1 })
Bun
Bun
import { CompressionMode } from "coakka-http-runtime-bun";

// Add to Builder:
.compression({ mode: CompressionMode.GZIP, minimumBodyBytes: 1 })

Use the port printed by the service. For C/C++, change the path to /hello and restart the first-request program between the 2 probes. The gzip request should show Content-Encoding: gzip and the original text decoded by curl. The identity request should return the same text without that header.

Terminal
url='http://127.0.0.1:PORT/hello/Ada'
curl -isS --compressed -H 'Accept-Encoding: gzip' "$url"
curl -isS -H 'Accept-Encoding: identity' "$url"

The minimum of 1 byte is for this exercise. In an application, keep the default threshold unless you have measurements. This policy does not gzip SSE or streamed bodies; an identity-refusing client can receive 406 for those streams. If gzip is absent, check the capability, body size and content type before tuning.

06 · Pressure

Backpressure is normal control flow

Wait

Wait for a bounded writability/progress signal with a monotonic deadline.

Cancel

Stop producer, reader or storage work and follow the terminal cleanup contract.

Timeout

Report the phase timeout; never infer the business effect or cleanup completed.

Shed/refuse

When full, refuse work instead of creating unlimited tasks or disk queues.

07 · Terminal paths

Every terminal reaches the same cleanup owner

OutcomeApplication action
Normal endValidate/finalize once, optional trailers, release state.
Peer abort/disconnectStop I/O, discard or preserve partial artifacts by policy, release state; never fake success.
Limit/pressureRefuse with a stable category; stop collecting.
Timeout/cancelStop producer/consumer and downstream work; timeout does not prove no effect.
Dispose/closeIdempotent cleanup; retain service ownership when close is refused or times out.

08 · Integration checklist

Before choosing a language API