ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
http_date.h File Reference

Render a Unix epoch as an RFC 7231 IMF-fixdate. More...

#include <stdint.h>
#include <time.h>
#include "shared_primitives/time_compat.h"

Go to the source code of this file.

Macros

#define PC_HTTP_DATE_MAX   30
 Smallest buffer that holds an RFC 7231 IMF-fixdate plus its NUL.
 

Functions

uint8_t pc_http_date (time_t epoch, char *out, uint32_t out_cap)
 Write epoch into out as an IMF-fixdate in GMT.
 

Detailed Description

Render a Unix epoch as an RFC 7231 IMF-fixdate.

One formatter serves every header that carries a timestamp (Date, Last-Modified, Expires), so the wire rendering is fixed in one place. The break-down is reentrant (gmtime_r, never the shared static tm), which is what makes it callable from any worker.

Every rejection - no epoch, no buffer, a time that will not break down - returns 0 and leaves out an empty string, so a caller that ignores the length still emits a well-formed header value rather than whatever the buffer held.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file http_date.h.

Macro Definition Documentation

◆ PC_HTTP_DATE_MAX

#define PC_HTTP_DATE_MAX   30

Smallest buffer that holds an RFC 7231 IMF-fixdate plus its NUL.

Sun, 06 Nov 1994 08:49:37 GMT is 29 characters and the format is fixed-width, so this is a property of the protocol rather than a tuning choice. A smaller buffer truncates silently, because strftime writes nothing and returns 0 when the result does not fit.

Definition at line 35 of file http_date.h.

Function Documentation

◆ pc_http_date()

uint8_t pc_http_date ( time_t  epoch,
char *  out,
uint32_t  out_cap 
)
inline

Write epoch into out as an IMF-fixdate in GMT.

Returns
characters written, excluding the NUL, or 0 with an empty out on any rejection.

Definition at line 41 of file http_date.h.

References pc_gmtime_r().

Referenced by pc_ntp_http_date(), and pc_time_http_date().