This commit is contained in:
2025-10-01 16:55:32 -07:00
commit 761b559f0a
59 changed files with 6568 additions and 0 deletions

80
source/http.h Normal file
View File

@@ -0,0 +1,80 @@
/* #############################################################################
* Http Send and response.
*
* This file handles all of the http response and requests
*
* #############################################################################
* */
#ifndef HTTP_H
#define HTTP_H
#define HTTP_GET 1
#define HTTP_POST 2
#define HTTP_PUT 3
#define HTTP_DELETE 4
#define HTTP_HEAD 5
#define HTTP_OPTIONS 6
#define HTTP_PATCH 7
#define HTTP_CONNECT 8
#define HTTP_TRACE 9
#ifndef HTTP_CONTENT_TYPES_H
#define HTTP_CONTENT_TYPES_H
// Define HTTP Content Types
#define HTTP_CONTENT_TYPE_HTML "text/html"
#define HTTP_CONTENT_TYPE_CSS "text/css"
#define HTTP_CONTENT_TYPE_JS "application/javascript"
#define HTTP_CONTENT_TYPE_JSON "application/json"
#define HTTP_CONTENT_TYPE_XML "application/xml"
#define HTTP_CONTENT_TYPE_TEXT "text/plain"
#define HTTP_CONTENT_TYPE_FORM "application/x-www-form-urlencoded"
#define HTTP_CONTENT_TYPE_IMAGE_GIF "image/gif"
#define HTTP_CONTENT_TYPE_IMAGE_JPG "image/jpeg"
#define HTTP_CONTENT_TYPE_IMAGE_PNG "image/png"
#define HTTP_CONTENT_TYPE_IMAGE_BMP "image/bmp"
#endif // HTTP_CONTENT_TYPES_H
typedef struct {
char* http_version; // HTTP version and status code (e.g., "HTTP/1.1 200 OK")
char* content_type; // Content type (e.g., "text/html; charset=UTF-8")
int content_length; // Size of the response body in bytes
char* last_modified; // Date and time when the resource was last modified
char* etag; // Unique identifier for the resource (e.g., "abcdefg")
char* server; // Information about the web server software (e.g., "Apache/2.4.41 (Ubuntu)")
unsigned int status_code;
char* status_text;
} HttpResponseHeader;
typedef struct {
unsigned char method; // e.g., "GET", "POST", etc.
char* uri; // The requested URI
char* http_version; // The HTTP version (e.g., "HTTP/1.1")
char* host; // The host name or IP address of the server
char* accept; // The accepted content type(s)
char* user_agent; // The user agent string
} HttpRequestHeader;
HttpRequestHeader* createHttpRequest(char* uri, unsigned char method,
char* host, char* accept, char* user_agent);
HttpResponseHeader* createHttpResponse(int statusCode,const char* contentType,
char* data, char* buffer, int bs);
void HttpResponseHeaderToS(HttpResponseHeader* rh, char* d, char* buffer, int bs);
void HttpRequestHeaderToS(HttpRequestHeader* rh, char* buffer);
// Freeing Objects
void freeHttpRequest(HttpRequestHeader* request);
void freeHttpResponse(HttpResponseHeader* response);
#endif // HTTP_H