Compare commits

...

4 Commits

4 changed files with 24 additions and 7 deletions

12
main.c Normal file
View File

@@ -0,0 +1,12 @@
#include "url.h"
#include "request.h"
#include <stdio.h>
int main() {
char* url_str = "http://www.google.com";
// URL* url = new_url(url_str);
// printf("Schema is %s\nHostname is %s\nPort is %s\nFilepath is %s\n",get_schema(url),get_hostname(url),get_port(url),get_filepath(url));
Request* req = new_request(url_str,"GET");
printf("%s",make_request(req));
}

View File

@@ -1,4 +1,5 @@
#include <stdlib.h>
#include <string.h>
#include "url.h"
#include "request.h"
@@ -25,18 +26,18 @@ char* make_request(Request* req) {
strcat(request_str,req->req_type);
strcat(request_str," ");
strcat(request_str,req->url->filepath);
strcat(request_str,get_filepath(req->url));
strcat(request_str," HTTP/1.1");
strcat(request_str,"\r\n");
strcat(request_str,"Host: ");
strcat(request_str,req->url->hostname);
strcat(request_str,get_hostname(req->url));
strcat(request_str,"\r\n\r\n");
return request_str;
if (strcmp(get_schema(req->url),"http") == 0) {
if (strcmp(req->url->schema,"http") == 0) {
} else if (strcmp(req->url->schema,"https") == 0) {
} else if (strcmp(get_schema(req->url),"https") == 0) {
}
}

View File

@@ -1,3 +1,7 @@
#include "url.h"
typedef struct Request_s Request;
Request* new_request(char* url,char* req_type);
URL* get_url(Request* req);
char* make_request(Request* req);

2
url.c
View File

@@ -47,7 +47,7 @@ URL* new_url(char* url_str) {
url->filepath = strtok(NULL,"/");
if (url->filepath == NULL) {
url->filepath = "/index.html";
url->filepath = "/";
}
return url;