diff seobeo/tests/seobeo_http_framing_test.c @ 279:b3b547563ec7

Add Google connector service and agent wiki Implement the C/Seobeo Google Drive and Gmail connector with encrypted OAuth storage, Zenbu authentication, browser testing, AI tool discovery, chunked HTTP decoding, and Bazel coverage. Consolidate repository guidance into progressive wiki documentation and enforce arena-first allocation for new first-party C code. Co-authored-by: Copilot <[email protected]> Copilot-Session: 84c338fd-0939-4bb3-b7f3-1062eb213e5d
author MrJuneJune <me@mrjunejune.com>
date Mon, 17 Aug 2026 22:22:36 -0700
parents ce7f4400c2de
children
line wrap: on
line diff
--- a/seobeo/tests/seobeo_http_framing_test.c	Mon Aug 17 22:16:14 2026 -0700
+++ b/seobeo/tests/seobeo_http_framing_test.c	Mon Aug 17 22:22:36 2026 -0700
@@ -12,17 +12,36 @@
 static void *serve_close_delimited_response(void *argument)
 {
   Framing_Server *server = argument;
-  int client = accept(server->listener, NULL, NULL);
-  if (client >= 0) {
+  for (int response_index = 0; response_index < 2; response_index++) {
+    int client = accept(server->listener, NULL, NULL);
+    if (client < 0)
+      continue;
     char request[1024];
     (void)read(client, request, sizeof(request));
-    const char response[] =
-        "HTTP/1.1 200 OK\r\n"
-        "Content-Type: text/plain\r\n"
-        "Connection: close\r\n"
-        "\r\n"
-        "buffered-body";
-    (void)write(client, response, sizeof(response) - 1);
+    if (response_index == 0) {
+      const char response[] =
+          "HTTP/1.1 200 OK\r\n"
+          "Content-Type: text/plain\r\n"
+          "Connection: close\r\n"
+          "\r\n"
+          "buffered-body";
+      (void)write(client, response, sizeof(response) - 1);
+    } else {
+      const char response[] =
+          "HTTP/1.1 200 OK\r\n"
+          "Content-Type: application/json\r\n"
+          "Transfer-Encoding: chunked\r\n"
+          "Connection: close\r\n"
+          "\r\n"
+          "7;sample=yes\r\n"
+          "{\"ok\":t\r\n"
+          "4\r\n"
+          "rue}\r\n"
+          "0\r\n"
+          "X-Trailer: ignored\r\n"
+          "\r\n";
+      (void)write(client, response, sizeof(response) - 1);
+    }
     close(client);
   }
   return NULL;
@@ -59,7 +78,9 @@
   }
 
   char url[128];
-  snprintf(url, sizeof(url), "http://127.0.0.1:%u/", ntohs(address.sin_port));
+  snprintf(
+      url, sizeof(url), "http://127.0.0.1:%u/close",
+      ntohs(address.sin_port));
   Seobeo_Client_Request *request = Seobeo_Client_Request_Create(url);
   Seobeo_Client_Request_Set_Timeout_Milliseconds(request, 1000);
   Seobeo_Client_Response *response = Seobeo_Client_Request_Execute(request);
@@ -73,6 +94,23 @@
 
   Seobeo_Client_Response_Destroy(response);
   Seobeo_Client_Request_Destroy(request);
+
+  snprintf(
+      url, sizeof(url), "http://127.0.0.1:%u/chunked",
+      ntohs(address.sin_port));
+  request = Seobeo_Client_Request_Create(url);
+  Seobeo_Client_Request_Set_Timeout_Milliseconds(request, 1000);
+  response = Seobeo_Client_Request_Execute(request);
+  int chunked_failed = !response ||
+      response->status_code != 200 ||
+      response->body_length != strlen("{\"ok\":true}") ||
+      memcmp(response->body, "{\"ok\":true}", strlen("{\"ok\":true}")) != 0;
+  if (chunked_failed)
+    fprintf(stderr, "Chunked response body was not decoded\n");
+  failed = failed || chunked_failed;
+
+  Seobeo_Client_Response_Destroy(response);
+  Seobeo_Client_Request_Destroy(request);
   pthread_join(thread, NULL);
   close(listener);
   return failed;