Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › http › Server › Request › respondUnflushed Public Function respondUnflushed Doc Source Public Function std.http.Server.Request.respondUnflushed
pub fn respondUnflushed (
request : *Request ,
content : []const u8 ,
options : RespondOptions ,
) ExpectContinueError !void Params File http/Server.zig: 332
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387 pub fn respondUnflushed (
request : *Request ,
content : []const u8 ,
options : RespondOptions ,
) ExpectContinueError !void {
assert (options .status != .@"continue" );
if (std .debug .runtime_safety ) {
for (options .extra_headers ) |header | {
assert (header .name .len != 0 );
assert (std .mem .findScalar (u8 , header .name , ':' ) == null );
assert (std .mem .findPosLinear (u8 , header .name , 0 , "\r\n" ) == null );
assert (std .mem .findPosLinear (u8 , header .value , 0 , "\r\n" ) == null );
}
}
try writeExpectContinue (request );
const transfer_encoding_none = (options .transfer_encoding orelse .chunked ) == .none ;
const server_keep_alive = !transfer_encoding_none and options .keep_alive ;
const keep_alive = request .discardBody (server_keep_alive );
const phrase = options .reason orelse options .status .phrase () orelse "" ;
const out = request .server .out ;
try out .print ("{s} {d} {s}\r\n" , .{
@tagName (options .version ), @backingInt (options .status ), phrase ,
});
switch (options .version ) {
.@"HTTP/1.0" => if (keep_alive ) try out .writeAll ("connection: keep-alive\r\n" ),
.@"HTTP/1.1" => if (!keep_alive ) try out .writeAll ("connection: close\r\n" ),
}
if (options .transfer_encoding ) |transfer_encoding | switch (transfer_encoding ) {
.none => {},
.chunked => try out .writeAll ("transfer-encoding: chunked\r\n" ),
} else {
try out .print ("content-length: {d}\r\n" , .{content .len });
}
for (options .extra_headers ) |header | {
var vecs : [4 ][]const u8 = .{ header .name , ": " , header .value , "\r\n" };
try out .writeVecAll (&vecs );
}
try out .writeAll ("\r\n" );
if (request .head .method != .HEAD ) {
const is_chunked = (options .transfer_encoding orelse .none ) == .chunked ;
if (is_chunked ) {
if (content .len > 0 ) try out .print ("{x}\r\n{s}\r\n" , .{ content .len , content });
try out .writeAll ("0\r\n\r\n" );
} else if (content .len > 0 ) {
try out .writeAll (content );
}
}
}