Start
Route/admission is accepted; application prepares bounded parser and storage state.
Product knowledge · Advanced · Bounded data flow
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
| Shape | Use when | Required bounds |
|---|---|---|
| Buffered request | Small payload; handler needs the complete value. | Per-request bytes, active work and retained application copies. |
| Streamed request | Large upload or incremental processing without whole-body retention. | Chunk bytes/count, retained chunks, progress deadline and storage queue. |
| Buffered response | Small response with known complete bytes. | Response bytes; compression still has workspace/eligibility limits. |
| Streamed response | Incremental 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
Route/admission is accepted; application prepares bounded parser and storage state.
Consume or copy a borrowed chunk within connector lifetime; never retain a view after its callback.
Trailers exist only after EOF. Finalize validation/storage, then respond exactly once.
Release chunks, temporary files and app state idempotently; dispose does not imply HTTP success.
03 · Upload ownership
Wire parsing, admission, body/chunk ceilings, phase timeout, cancellation and transport outcome.
Host callback/value projection, borrowed/copy law and callback, GC or FFI lifetime.
Media type, filename policy, antivirus/schema/hash, storage path, quota, atomic publication and cleanup.
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.
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.
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.
Register PostStream. Read request.Body as an io.Reader until EOF, then read request.Trailers. Stop and clean up on a read error.
Register postStream. Read the InputStream from request.body (Kotlin) or request.getBody() (Java). Read the trailers after EOF.
Register post_stream. Read bounded chunks from request.body_reader, then check request.trailers when the stream is complete.
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
05 · Response stream lifecycle
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 stateThe 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
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.
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;.Compression(&coakkahttp.Compression{
Mode: coakkahttp.CompressionGZIP,
MinimumBodyBytes: 1,
})import coakka.http.Compression
import coakka.http.CompressionMode
// Add to ServiceBuilder:
.compression(Compression(mode = CompressionMode.GZIP, minimumBodyBytes = 1))import coakka.http.Compression;
import coakka.http.CompressionMode;
// Add to ServiceBuilder:
.compression(new Compression(CompressionMode.GZIP, 1L))from coakka_http import Compression, CompressionMode
# Add to Builder:
.compression(Compression(mode=CompressionMode.GZIP, minimum_body_bytes=1))import { CompressionMode } from "coakka-http-runtime-node";
// Add to Builder:
.compression({ mode: CompressionMode.GZIP, minimumBodyBytes: 1 })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.
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
Wait for a bounded writability/progress signal with a monotonic deadline.
Stop producer, reader or storage work and follow the terminal cleanup contract.
Report the phase timeout; never infer the business effect or cleanup completed.
When full, refuse work instead of creating unlimited tasks or disk queues.
07 · Terminal paths
| Outcome | Application action |
|---|---|
| Normal end | Validate/finalize once, optional trailers, release state. |
| Peer abort/disconnect | Stop I/O, discard or preserve partial artifacts by policy, release state; never fake success. |
| Limit/pressure | Refuse with a stable category; stop collecting. |
| Timeout/cancel | Stop producer/consumer and downstream work; timeout does not prove no effect. |
| Dispose/close | Idempotent cleanup; retain service ownership when close is refused or times out. |
08 · Integration checklist