httpkit

package
v0.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package httpkit holds shared HTTP transport helpers for the API surfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteSSEHeaders

func WriteSSEHeaders(w http.ResponseWriter)

WriteSSEHeaders sets the Server-Sent Events headers shared by every streaming endpoint. Callers still own WriteHeader and Flush.

Types

type StreamWriter added in v0.6.9

type StreamWriter struct {
	// contains filtered or unexported fields
}

StreamWriter is the single owner of streaming response commitment. The 200 status and SSE headers go out with the first byte, not before routing: a failure before any output (unknown provider, no credential, rate limit) still answers with its real HTTP status and headers such as Retry-After. Every write flushes, so each event reaches the client immediately instead of waiting in the server's output buffer.

func NewStreamWriter added in v0.6.9

func NewStreamWriter(w http.ResponseWriter) (stream *StreamWriter, ok bool)

NewStreamWriter wraps w. ok is false when w cannot flush: the caller then answers with a plain error instead of streaming.

func (*StreamWriter) Flush added in v0.6.9

func (s *StreamWriter) Flush()

Flush flushes committed output. Before the first byte it does nothing, so an early flush never commits a 200.

func (*StreamWriter) Started added in v0.6.9

func (s *StreamWriter) Started() bool

Started reports whether the stream committed (status 200 sent). Once true, failures must be reported inside the stream.

func (*StreamWriter) Write added in v0.6.9

func (s *StreamWriter) Write(p []byte) (int, error)

Write commits the stream on first use, writes p and flushes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL