working on the web side of things
This commit is contained in:
@@ -35,7 +35,7 @@ HttpRequestHeader* createHttpRequest(char* uri, unsigned char method, char* host
|
||||
|
||||
// Function to receive an HTTP response
|
||||
HttpResponseHeader* createHttpResponse(int statusCode,const char* contextType,
|
||||
char* data, char* buffer, int bs) {
|
||||
char* data, char* buffer, int bufferSize) {
|
||||
// TO DO: implement the actual receiving logic
|
||||
HttpResponseHeader* response = (HttpResponseHeader*)malloc(sizeof(HttpResponseHeader));
|
||||
response->http_version = (char*) malloc(strlen("HTTP/1.1") + 1);
|
||||
@@ -76,15 +76,15 @@ HttpResponseHeader* createHttpResponse(int statusCode,const char* contextType,
|
||||
break;
|
||||
}
|
||||
|
||||
HttpResponseHeaderToS(response, data, buffer, bs);
|
||||
HttpResponseHeaderToS(response, data, buffer, bufferSize);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
void HttpResponseHeaderToS(HttpResponseHeader* rh,char* d, char* buffer, int bs) {
|
||||
void HttpResponseHeaderToS(HttpResponseHeader* rh,char* d, char* buffer, int bufferSize) {
|
||||
|
||||
|
||||
snprintf(buffer, 512,
|
||||
snprintf(buffer, bufferSize,
|
||||
"%s %u %s\r\n"
|
||||
"Content-Type: %s\r\n"
|
||||
"Content-Length: %d\r\n"
|
||||
@@ -94,6 +94,45 @@ void HttpResponseHeaderToS(HttpResponseHeader* rh,char* d, char* buffer, int bs)
|
||||
|
||||
}
|
||||
|
||||
void HttpRequestHeaderFromS(HttpRequestHeader* rh, char* buffer) {
|
||||
|
||||
int methodLen = 0;
|
||||
char methodStr[8] = "";
|
||||
if (strstr(buffer, "GET") != NULL) {
|
||||
rh->method = HTTP_GET;
|
||||
} else if (strstr(buffer, "POST") != NULL) {
|
||||
rh->method = HTTP_POST;
|
||||
} else if (strstr(buffer, "PUT") != NULL) {
|
||||
rh->method = HTTP_PUT;
|
||||
} else if (strstr(buffer, "DELETE") != NULL) {
|
||||
rh->method = HTTP_DELETE;
|
||||
} else if (strstr(buffer, "HEAD") != NULL) {
|
||||
rh->method = HTTP_HEAD;
|
||||
} else if (strstr(buffer, "OPTIONS") != NULL) {
|
||||
rh->method = HTTP_OPTIONS;
|
||||
} else if (strstr(buffer, "PATCH") != NULL) {
|
||||
rh->method = HTTP_PATCH;
|
||||
} else if (strstr(buffer, "CONNECT") != NULL) {
|
||||
rh->method = HTTP_CONNECT;
|
||||
} else if (strstr(buffer, "CONNECT") != NULL) {
|
||||
rh->method = HTTP_CONNECT;
|
||||
} else {
|
||||
rh->method = HTTP_UNKNOWN;
|
||||
}
|
||||
|
||||
int bufferLen, wordIndex;
|
||||
|
||||
// Find the bufferLen of the string
|
||||
bufferLen = strlen(buffer);
|
||||
int start, end = 0;
|
||||
|
||||
|
||||
|
||||
// GET /path/to/file/ HTTP:1.1
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Function to free the memory allocated for an HTTP request header
|
||||
void freeHttpRequest(HttpRequestHeader* request) {
|
||||
if (request == NULL) return;
|
||||
|
||||
Reference in New Issue
Block a user