Skip to content
Snippets Groups Projects
Commit 6f6caf9a authored by Paul Ripault's avatar Paul Ripault
Browse files

7.1 rewrite fonctionne

parent bcf0f38e
No related branches found
No related tags found
No related merge requests found
CFLAGS=-Wall -Wextra -Werror -g
LIB=libhttp_parse.a
SRC=$(wildcard *.c)
OBJS=$(SRC:.c=.o)
HDR=$(wildcard *.h)
$(LIB): $(OBJS)
ar rs $@ $^
ranlib $@
makefile.dep: $(SRC) $(HDR)
$(CC) $(CFLAGS) -MM $(SRC) > $@
.PHONY: clean mrproper
clean:
$(RM) $(OBJS)
mrproper: clean
$(RM) $(LIB)
include makefile.dep
\ No newline at end of file
File added
http_parse.o: http_parse.c http_parse.h
...@@ -9,10 +9,11 @@ ...@@ -9,10 +9,11 @@
#include "http_parse.h" #include "http_parse.h"
char* rewrite_target(char *target){ char* rewrite_target(char *target){
char* ret = strchr(target, '?'); char* ret = strrchr(target, '?');
char* rep =""; char* rep = malloc(strlen(target)*sizeof(char));
if (ret!= NULL){ if (ret!= NULL){
strncpy(rep,target,atoi(ret)-1); size_t i = (int)(strlen(target)-strlen(ret));
rep = strncpy(rep,target,i);
} }
return rep; return rep;
} }
...@@ -51,13 +52,11 @@ void send_status(FILE *client, int code, const char *reason_phrase){ ...@@ -51,13 +52,11 @@ void send_status(FILE *client, int code, const char *reason_phrase){
} }
void send_response(FILE *client, int code, const char *reason_phrase, const char *message_body){ void send_response(FILE *client, int code, const char *reason_phrase, const char *message_body){
fprintf(client, "entree dans send_response\n");
send_status(client,code,reason_phrase); send_status(client,code,reason_phrase);
//transmet la réponse complète (la suite) //transmet la réponse complète (la suite)
fprintf(client,"Content-Lenght: %u\r\n",(unsigned int)strlen(message_body)); fprintf(client,"Content-Lenght: %u\r\n",(unsigned int)strlen(message_body));
fprintf(client,"\r\n"); fprintf(client,"\r\n");
fprintf(client,"%s\r\n",message_body); fprintf(client,"%s\r\n",message_body);
fprintf(client, "sortie de send_response\n");
fflush(client); fflush(client);
} }
...@@ -79,25 +78,24 @@ int traitementClient(int socket_client){ ...@@ -79,25 +78,24 @@ int traitementClient(int socket_client){
fgets_or_exit(str,8000,fd); fgets_or_exit(str,8000,fd);
int parse_ret = parse_http_request(str,&request); int parse_ret = parse_http_request(str,&request);
skip_headers(fd); skip_headers(fd);
fprintf(fd, "avant if parse_ret\n");
if (parse_ret == -1) { if (parse_ret == -1) {
if (request.method == HTTP_UNSUPPORTED){ if (request.method == HTTP_UNSUPPORTED){
send_response(fd, 405, "Method Not Allowed", "Method Not Allowed"); send_response(fd, 405, "Method Not Allowed", "Method Not Allowed");
}else{ }else{
send_response(fd, 400, "Bad Request", "Bad request"); send_response(fd, 400, "Bad Request", "Bad request");
} }
}else if (strcmp(request.target, "/") == 0){ }else if (strcmp(request.target, "/test?aled") == 0){
send_response(fd, 200, "OK", motd); send_response(fd, 200, "OK", motd);
fprintf(fd, "fin du else-if\n");
}else{ }else{
send_response(fd, 404, "Not Found", "Not Found"); send_response(fd, 404, "Not Found", "Not Found");
} }
fflush(fd); fflush(fd);
fprintf(fd, "après if parse_ret\n");
//partie 7 //partie 7
fprintf(fd, "avant rewrite\n");
char* absolute_path = rewrite_target(request.target); char* absolute_path = rewrite_target(request.target);
fprintf(fd,"test - - - - - - - - %s\n",absolute_path); printf("test - - - - - - - - %s\n",absolute_path);
fclose(fd); fclose(fd);
return 0; return 0;
} }
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment