18#define pharos_http_log_strdup _strdup
19#define pharos_http_log_strcasecmp _stricmp
21#define pharos_http_log_strdup strdup
22#define pharos_http_log_strcasecmp strcasecmp
26 const char *ext = strrchr(path,
'.');
42 const unsigned char *cursor;
43 int pending_space = 0;
48 for (cursor = (
const unsigned char *)value; *cursor !=
'\0'; cursor++) {
49 if (*cursor ==
'\r' || *cursor ==
'\n' || isspace(*cursor)) {
53 if (pending_space && buffer.
len > 0) {
61 char single = (char)*cursor;
68 if (buffer.
len > 0 && buffer.
data[buffer.
len - 1] ==
' ') {
69 buffer.
data[buffer.
len - 1] =
'\0';
82 while (cursor != NULL && *cursor !=
'\0') {
83 char *line_end = strchr(cursor,
'\n');
86 if (line_end != NULL) {
90 colon = strchr(line,
':');
98 char *comma = strchr(value,
',');
107 if (line_end == NULL) {
110 cursor = line_end + 1;
118 while (cursor != NULL && *cursor !=
'\0') {
119 char *line_end = strchr(cursor,
'\n');
122 if (line_end != NULL) {
126 colon = strchr(line,
':');
138 if (line_end == NULL) {
141 cursor = line_end + 1;
158 while (cursor != NULL && *cursor !=
'\0') {
159 char *line_end = strchr(cursor,
'\n');
162 if (line_end != NULL) {
166 colon = strchr(line,
':');
173 buffer_append(&buffer, client_ip != NULL ? client_ip :
"unknown", strlen(client_ip != NULL ? client_ip :
"unknown")) != 0 ||
191 if (line_end == NULL) {
194 cursor = line_end + 1;
196 if (!replaced && client_ip != NULL && client_ip[0] !=
'\0') {
210 switch (status_code) {
211 case 200:
return "200 OK";
212 case 302:
return "302 Found";
213 case 400:
return "400 Bad Request";
214 case 404:
return "404 Not Found";
215 case 405:
return "405 Method Not Allowed";
216 case 500:
return "500 Internal Server Error";
217 default:
return "200 OK";
222 const char *line_end;
223 const char *status_start;
224 if (response == NULL || response[0] ==
'\0') {
227 line_end = strstr(response,
"\r\n");
228 if (line_end == NULL) {
229 line_end = strchr(response,
'\n');
231 if (line_end == NULL) {
232 line_end = response + strlen(response);
234 status_start = strchr(response,
' ');
235 if (status_start != NULL && status_start < line_end) {
237 return dup_range(status_start, (
size_t)(line_end - status_start));
239 return dup_range(response, (
size_t)(line_end - response));
243 const char *status_start;
244 if (response == NULL || response[0] ==
'\0') {
247 status_start = strchr(response,
' ');
248 if (status_start == NULL || status_start[1] ==
'\0') {
251 return atoi(status_start + 1);
char * compact_log_text_native(const char *value)
Compacts free-form text into a single-line log-safe representation.
char * request_real_ip_native(const char *headers)
Extracts the best client IP address from request headers.
char * request_headers_with_client_ip_native(const char *headers, const char *client_ip)
Returns request headers with an explicit client IP header applied.
#define pharos_http_log_strdup
char * http_status_line_from_response_native(const char *response)
Extracts the HTTP status line from a raw HTTP response payload.
char * mime_type_for_path(const char *path)
Resolves the MIME type that should be used for a file path.
const char * http_status_text_native(int status_code)
Returns the canonical reason phrase for one HTTP status code.
int http_status_code_from_response_native(const char *response)
Extracts the numeric HTTP status code from a raw HTTP response payload.
#define pharos_http_log_strcasecmp
Declares HTTP logging and response formatting helpers.
void buffer_init(Buffer *buffer)
Initializes a growable buffer to an empty state.
void trim_in_place(char *text)
Trims leading and trailing ASCII whitespace from a string in place.
char * dup_range(const char *start, size_t len)
Duplicates a byte range into a newly allocated NUL-terminated string.
void buffer_free(Buffer *buffer)
Releases memory owned by a growable buffer.
int buffer_append(Buffer *buffer, const void *data, size_t len)
Appends bytes to a growable buffer and maintains a trailing NUL byte.
Declares shared low-level support helpers used across the Pharos native runtime.
Growable byte buffer used by parsing and string assembly helpers.