Files
DesignedWorlds/source/http.h

84 lines
2.7 KiB
C

/* #############################################################################
* Http Send and response.
*
* This file handles all of the http response and requests
*
* #############################################################################
* */
#ifndef HTTP_H
#define HTTP_H
#define HTTP_UNKNOWN 0
#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
#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 HttpRequestHeaderFromS(HttpRequestHeader* rh, char* buffer);
int HttpCreate();
int HttpGetReqest(char* buffer);
int HttpSendResponse(int statusCode, const char* type, char* data);
// Freeing Objects
void freeHttpRequest(HttpRequestHeader* request);
void freeHttpResponse(HttpResponseHeader* response);
#endif // HTTP_H