httpx

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureSession

func EnsureSession(ctx context.Context, client *http.Client, baseURL string, extraHeaders map[string]string)

EnsureSession performs a lightweight GET on baseURL to allow the server to issue cookies or perform other session initialization before a long-lived SSE/POST request.

func NewDefaultClient

func NewDefaultClient() *http.Client

NewDefaultClient returns an HTTP client suitable for SSE endpoints and APIs that dislike transparent compression. It also attaches a CookieJar so servers behind anti-bot layers (e.g., Cloudflare) can set session cookies.

func OpenAIStyleDecoder

func OpenAIStyleDecoder(data []byte) (string, bool, bool)

OpenAIStyleDecoder decodes typical OpenAI-like SSE chunks where the payload is a JSON object with `choices[0].delta.content` and optional `type:"metadata"`.

func StreamAggregate

func StreamAggregate(ctx context.Context, r io.Reader, decode ChunkDecoder) (string, error)

StreamAggregate reads text/event-stream content from r, calls decode for each `data:` line, and aggregates the text deltas until completion or EOF.

Types

type ChunkDecoder

type ChunkDecoder func(data []byte) (delta string, done bool, ok bool)

ChunkDecoder extracts a text delta from an SSE data payload. It returns (delta, done, ok).

  • delta: text to append to the aggregate output
  • done: whether the stream signaled completion
  • ok: whether this payload was recognized/consumed

Jump to

Keyboard shortcuts

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