Skip to content

Commit 1cf4593

Browse files
arman-bdclaude
andcommitted
fix: Add POSIX feature macros and fix C compilation errors
- Add _POSIX_C_SOURCE and _XOPEN_SOURCE macros for strdup declaration - Include strings.h for strcasecmp function - Fix http2_request signature to accept const request parameter - Fix C23 label-declaration warning by wrapping in block scope 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 41a2bca commit 1cf4593

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/core/httpmorph.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@
99
* - Connection pooling
1010
*/
1111

12+
#define _POSIX_C_SOURCE 200809L
13+
#define _XOPEN_SOURCE 700
14+
1215
#include "../include/httpmorph.h"
1316
#include "../tls/browser_profiles.h"
1417
#include "io_engine.h"
1518

1619
#include <stdio.h>
1720
#include <stdlib.h>
1821
#include <string.h>
22+
#include <strings.h> /* for strcasecmp */
1923
#include <time.h>
2024
#include <zlib.h>
2125

@@ -1409,7 +1413,7 @@ static int http2_on_frame_recv_callback(nghttp2_session *session,
14091413
}
14101414

14111415
/* Perform HTTP/2 request */
1412-
static int http2_request(SSL *ssl, httpmorph_request_t *request,
1416+
static int http2_request(SSL *ssl, const httpmorph_request_t *request,
14131417
const char *host, const char *path,
14141418
httpmorph_response_t *response) {
14151419
nghttp2_session *session;
@@ -2047,8 +2051,9 @@ httpmorph_response_t* httpmorph_request_execute(
20472051
#endif
20482052

20492053
/* 5. Decompress gzip if Content-Encoding: gzip or body starts with gzip magic bytes */
2050-
const char *content_encoding = httpmorph_response_get_header(response, "Content-Encoding");
2051-
bool should_decompress = false;
2054+
{
2055+
const char *content_encoding = httpmorph_response_get_header(response, "Content-Encoding");
2056+
bool should_decompress = false;
20522057

20532058
if (content_encoding && strstr(content_encoding, "gzip")) {
20542059
should_decompress = true;
@@ -2064,14 +2069,15 @@ httpmorph_response_t* httpmorph_request_execute(
20642069
decompress_gzip(response);
20652070
}
20662071

2067-
/* 6. Check if total time exceeded timeout */
2068-
uint64_t elapsed_us = get_time_us() - start_time;
2069-
uint64_t timeout_us = (uint64_t)request->timeout_ms * 1000;
2070-
if (elapsed_us > timeout_us) {
2071-
response->error = HTTPMORPH_ERROR_TIMEOUT;
2072-
response->error_message = strdup("Request timed out");
2073-
} else {
2074-
response->error = HTTPMORPH_OK;
2072+
/* 6. Check if total time exceeded timeout */
2073+
uint64_t elapsed_us = get_time_us() - start_time;
2074+
uint64_t timeout_us = (uint64_t)request->timeout_ms * 1000;
2075+
if (elapsed_us > timeout_us) {
2076+
response->error = HTTPMORPH_ERROR_TIMEOUT;
2077+
response->error_message = strdup("Request timed out");
2078+
} else {
2079+
response->error = HTTPMORPH_OK;
2080+
}
20752081
}
20762082

20772083
cleanup:

0 commit comments

Comments
 (0)