Sample code for 30+ languages & platforms
Zig

HTTP Response Inspection

See more HTTP Examples

Demonstrates how to inspect the HTTP response, including the status code, status text, and response headers, for Chilkat methods that don't use an HttpResponse object.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    const http = try chilkat.Http.init();
    defer http.deinit();

    // Returns the contents of the response body.
    _ = try http.quickGetStr(alloc, "https://chilkatsoft.com/helloWorld.json");

    // Examine the response status code.
    std.debug.print("response status code: {d}\n", .{http.getLastStatus()});

    // Examine the response status text
    std.debug.print("response status text: {s}\n", .{try http.getLastStatusText(alloc)});

    // Examine the full response header.
    std.debug.print("response header:\n", .{});
    std.debug.print("{s}\n", .{try http.getLastResponseHeader(alloc)});
    std.debug.print("----\n", .{});

    // Examine the response content-type
    std.debug.print("LastContentType = {s}\n", .{try http.getLastContentType(alloc)});

    // Examine the response last-mod date
    std.debug.print("LastModDate = {s}\n", .{try http.getLastModDate(alloc)});

    // Load the response header into a Chilkat MIME object to access its fields individually.
    const mime = try chilkat.Mime.init();
    defer mime.deinit();
    mime.loadMime(try http.getLastResponseHeader(alloc)) catch {};

    const num_headers = mime.getNumHeaderFields();
    var i: i32 = 0;
    std.debug.print("---- MIME Headers ----\n", .{});
    while (i < num_headers) {
        std.debug.print("name:  {s}\n", .{try mime.getHeaderFieldName(alloc, i)});
        std.debug.print("value: {s}\n", .{try mime.getHeaderFieldValue(alloc, i)});
        i = i + 1;
    }

    std.debug.print("----\n", .{});

    // Get a header field value by name:
    std.debug.print("ETag: {s}\n", .{try mime.getHeaderField(alloc, "ETag")});

    // Output:

    // response status code: 200
    // response status text: OK
    // response header:
    // Content-Type: application/json
    // Last-Modified: Sun, 20 Aug 2023 11:36:27 GMT
    // Accept-Ranges: bytes
    // ETag: "34c27f8e5ad3d91:0"
    // Server: Microsoft-IIS/10.0
    // X-Powered-By: ASP.NET
    // Date: Sat, 30 Aug 2025 14:38:13 GMT
    // Content-Length: 22
    // ----
    // LastContentType = application/json
    // LastModDate = 2023-08-20
    // ---- MIME Headers ----
    // name:  Content-Type
    // value: application/json
    // name:  Last-Modified
    // value: Sun, 20 Aug 2023 11:36:27 GMT
    // name:  Accept-Ranges
    // value: bytes
    // name:  ETag
    // value: "34c27f8e5ad3d91:0"
    // name:  Server
    // value: Microsoft-IIS/10.0
    // name:  X-Powered-By
    // value: ASP.NET
    // name:  Date
    // value: Sat, 30 Aug 2025 14:38:13 GMT
    // name:  Content-Length
    // value: 22
    // ----
    // ETag: "34c27f8e5ad3d91:0"
}