diff playground/main.c @ 147:6de849867459 hg-web

[HgWeb] Updated logic to use Seobeo Client.
author June Park <parkjune1995@gmail.com>
date Fri, 09 Jan 2026 18:39:34 -0800
parents 893d87124d16
children 827c6ac504cd
line wrap: on
line diff
--- a/playground/main.c	Fri Jan 09 13:45:29 2026 -0800
+++ b/playground/main.c	Fri Jan 09 18:39:34 2026 -0800
@@ -1,113 +1,20 @@
 #include "seobeo/seobeo.h"
 
-void Test_Echo()
-{
-  printf("\n=== Test: Multiple Messages ===\n");
-
-  // Seobeo_Client_Request *foo = Seobeo_Client_Request_Create("http://mrjunejune.com/echo");
-  // Seobeo_Client_Request_Add_Header_Array(foo, "Upgrade: websocket");
-  // Seobeo_Client_Request_Add_Header_Array(foo, "Connection: Upgrade");
-  // Seobeo_Client_Request_Add_Header_Array(foo, "Sec-WebSocket-Key: asbc3e12bA");
-  // Seobeo_Client_Request_Add_Header_Array(foo, "Sec-WebSocket-Version: 13");
-  // Seobeo_Client_Response *foo2 = Seobeo_Client_Request_Execute(foo);
-  // printf("June: %s\n", foo2->body);
-
-
-  Seobeo_WebSocket *p_ws = Seobeo_WebSocket_Connect("ws://mrjunejune.com/echo");
-  // Seobeo_WebSocket *p_ws = Seobeo_WebSocket_Connect("ws://localhost:6969/echo");
-  if (!p_ws)
-  {
-    printf("Failed to connect\n");
-    return;
-  }
-
-  const char *messages[] = {
-    "Message 1",
-    "Message 2",
-    "Message 3"
-  };
-
-  for (int i = 0; i < 3; i++)
-  {
-    printf("Sending: %s\n", messages[i]);
-    Seobeo_WebSocket_Send_Text(p_ws, messages[i]);
-    usleep(100000);
-  }
-
-  printf("Receiving responses...\n");
-  int received = 0;
-  int attempts = 0;
-
-  while (received < 3 && attempts < 200)
-  {
-    Seobeo_WebSocket_Message *p_msg = Seobeo_WebSocket_Receive(p_ws);
-    if (p_msg)
-    {
-      if (p_msg->opcode == SEOBEO_WS_OPCODE_TEXT)
-      {
-        printf("Response %d: %.*s\n", received + 1, (int)p_msg->length, (char*)p_msg->data);
-        received++;
-      }
-      Seobeo_WebSocket_Message_Destroy(p_msg);
-    }
-
-    usleep(10000);
-    attempts++;
-  }
-  printf("Received %d/%d messages\n", received, 3);
-  Seobeo_WebSocket_Destroy(p_ws);
-}
-
-void Test_Chat()
-{
-  printf("\n=== Test: Multiple Messages ===\n");
-
-  Seobeo_WebSocket *p_ws = Seobeo_WebSocket_Connect("ws://127.0.0.1:8080/chat");
-  if (!p_ws)
-  {
-    printf("Failed to connect\n");
-    return;
-  }
-
-  const char *messages[] = {
-    "Message 1",
-    "Message 2",
-    "Message 3"
-  };
-
-  for (int i = 0; i < 3; i++)
-  {
-    printf("Sending: %s\n", messages[i]);
-    Seobeo_WebSocket_Send_Text(p_ws, messages[i]);
-    usleep(100000);
-  }
-
-  printf("Receiving responses...\n");
-  int received = 0;
-  int attempts = 0;
-
-  while (received < 3 && attempts < 200)
-  {
-    Seobeo_WebSocket_Message *p_msg = Seobeo_WebSocket_Receive(p_ws);
-    if (p_msg)
-    {
-      if (p_msg->opcode == SEOBEO_WS_OPCODE_TEXT)
-      {
-        printf("Response %d: %.*s\n", received + 1, (int)p_msg->length, (char*)p_msg->data);
-        received++;
-      }
-      Seobeo_WebSocket_Message_Destroy(p_msg);
-    }
-
-    usleep(10000);
-    attempts++;
-  }
-  printf("Received %d/%d messages\n", received, 3);
-  Seobeo_WebSocket_Destroy(p_ws);
-}
-
 int main(int argc, char *argv[])
 {
-
-  Test_Echo();
+  Seobeo_Client_Request *p_req = Seobeo_Client_Request_Create("http://127.0.0.1:4444/file/tip?style=json");
+  Seobeo_Client_Request_Add_Header_Array(p_req, "User-Agent: Seobeo/1.0 (Array Mode)");
+  Seobeo_Client_Request_Add_Header_Array(p_req, "Accept: application/json");
+  Seobeo_Client_Request_Add_Header_Array(p_req, "X-Test-Header: TestValue");
+  Seobeo_Client_Response *p_resp = Seobeo_Client_Request_Execute(p_req);
+  if (p_resp)
+  {
+    printf("Status: %d\n", p_resp->status_code);
+    if (p_resp->body)
+      printf("Response:\n%s\n", p_resp->body);
+    Seobeo_Client_Response_Destroy(p_resp);
+  }
+  else
+    printf("Request failed\n");
+  Seobeo_Client_Request_Destroy(p_req);
 }