added function to create HTTP response object from buffer
authorHolger Schemel <info@artsoft.org>
Fri, 24 Sep 2021 14:08:47 +0000 (16:08 +0200)
committerHolger Schemel <info@artsoft.org>
Fri, 24 Sep 2021 14:08:47 +0000 (16:08 +0200)
src/libgame/http.c
src/libgame/http.h

index b494ac42bd9d57d04bf84f14ed3d6189ef35c305..a179620e141b64c913df7f4151f1280bed3ae279 100644 (file)
@@ -65,6 +65,22 @@ static void SetHttpResponseToDefaults(struct HttpResponse *response)
   response->status_text[0] = '\0';
 }
 
+struct HttpResponse *GetHttpResponseFromBuffer(void *buffer, int size)
+{
+  if (size > MAX_HTTP_BODY_SIZE)
+    return NULL;
+
+  struct HttpResponse *response = checked_calloc(sizeof(struct HttpResponse));
+
+  SetHttpResponseToDefaults(response);
+
+  strncpy(response->body, buffer, MAX_HTTP_BODY_SIZE);
+  response->body[MAX_HTTP_BODY_SIZE] = '\0';
+  response->body_size = MIN(size, MAX_HTTP_BODY_SIZE);
+
+  return response;
+}
+
 static boolean SetHTTPResponseCode(struct HttpResponse *response, char *buffer)
 {
   char *prefix = "HTTP/1.1 ";
index 3a1dc3e3ca5f233b6dc44d0fe405138e9d5a7295..2523bc721a8b985ed56fc94c4ad3e6c9dc5491d1 100644 (file)
@@ -46,6 +46,7 @@ struct HttpResponse
 char *GetHttpError(void);
 void ConvertHttpRequestBodyToServerEncoding(struct HttpRequest *);
 void ConvertHttpResponseBodyToClientEncoding(struct HttpResponse *);
+struct HttpResponse *GetHttpResponseFromBuffer(void *, int);
 boolean DoHttpRequest(struct HttpRequest *, struct HttpResponse *);
 
 #endif