Skip to content

Utilities API ​

Common utilities for buffer management and encoding.

Shared Helpers ​

httpx.common provides reusable helpers used across client/server/core modules.

  • queryValue(query, key): Get a query parameter value from a raw query string.
  • parseSetCookiePair(set_cookie): Parse the first name=value pair from a Set-Cookie header value.
  • cookieValue(cookie_header, name): Read a cookie value from a request Cookie header.
  • buildSetCookieHeader(allocator, name, value, options): Build a Set-Cookie header value with RFC 6265 style attributes.
  • mimeTypeFromPath(path): Resolve a best-effort MIME type from file extension for static/file responses.
  • CookieOptions: Cookie attributes (Path, Domain, Max-Age, SameSite, Secure, HttpOnly).
  • SameSite: Enum values lax, strict, none.

Root-level aliases are also available:

  • httpx.queryValue(...)
  • httpx.parseQueryValue(...)
  • httpx.parseSetCookiePair(...)
  • httpx.parseCookiePair(...)
  • httpx.CookieOptions
  • httpx.SameSite

Protocol utility aliases are also available at root-level:

  • httpx.encodeVarInt(...)
  • httpx.decodeVarInt(...)

Compatibility note:

  • httpx.utils remains available as an alias to httpx.common.

Buffers ​

Buffer ​

A dynamic, growable byte buffer.

zig
const buf = try Buffer.init(allocator, 1024);
defer buf.deinit();

try buf.append("Hello");
  • append(bytes: []const u8) !void
  • toOwnedSlice() ![]u8
  • clear()

RingBuffer ​

Circular buffer optimized for streaming data.

zig
var ring = try RingBuffer.init(allocator, 4096);
  • writeBytes(bytes: []const u8) !usize
  • readBytes(buffer: []u8) usize
  • getAvailable() usize
  • getFreeSpace() usize

FixedBuffer ​

Stack-allocated fixed-size buffer.

zig
var buf = FixedBuffer(64){};

Encoding ​

Base64 ​

Base64 encoding (RFC 4648) with support for standard and URL-safe alphabets.

  • encode(allocator: Allocator, data: []const u8) ![]u8
  • decode(allocator: Allocator, data: []const u8) ![]u8
  • encodeUrl(allocator: Allocator, data: []const u8) ![]u8

Hex ​

Hexadecimal encoding/decoding.

  • encode(allocator: Allocator, data: []const u8) ![]u8
  • decode(allocator: Allocator, data: []const u8) ![]u8

PercentEncoding ​

URL encoding/decoding (RFC 3986).

  • encode(allocator: Allocator, input: []const u8) ![]u8
  • decode(allocator: Allocator, input: []const u8) ![]u8

JSON ​

JsonBuilder ​

Fluent builder for constructing JSON strings efficiently.

zig
var jb = JsonBuilder.init(allocator);
defer jb.deinit();

try jb.beginObject();
try jb.key("name");
try jb.string("John");
try jb.endObject();
  • beginObject() !void
  • endObject() !void
  • beginArray() !void
  • endArray() !void
  • key(name: []const u8) !void
  • string(val: []const u8) !void
  • number(val: anytype) !void
  • boolean(val: bool) !void
  • nullValue() !void

Released under the MIT License.