From 76f17729b4e75443db3c505d5d7e423aa5d5e61a Mon Sep 17 00:00:00 2001 From: Win Date: Wed, 22 May 2024 20:58:28 +0700 Subject: [PATCH] added response func --- Makefile | 2 +- goffy | Bin 16024 -> 0 bytes goffy.c | 24 ----------------------- server | Bin 16912 -> 17184 bytes src/server.c | 53 ++++++++++++++++++++++++++++++--------------------- src/server.h | 2 +- 6 files changed, 33 insertions(+), 48 deletions(-) delete mode 100755 goffy delete mode 100644 goffy.c diff --git a/Makefile b/Makefile index eaebd20..54fdb36 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CC=clang +CC=/usr/bin/clang all: webserver.c $(CC) webserver.c -o webserver diff --git a/goffy b/goffy deleted file mode 100755 index 72460613e2f87142a2d95320562355541bafa38b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16024 zcmeHOZ)_CD6`wo)ISF9n;MPEkmn5!CiWeWoE(vlt|2eZx4R*k&pq4Ca-=2Ny-K~4K zN9-t~P(u_4St3%~^g}+-5{XLv(5On=FC{V!qBN>1=qFdIDyvE)Q{@j$X_U5s>w7cr z?X9=xrpkx@k#^+WH}Ch}Z)Wz*?0WWg=Ie?6-e@EuI4u*83Dl0&C?rmXxpvBch>Klf z4V)XqX0a0VhvUi{&8IcbFveP(|K6@#cx=Nvdz2 zB*znDg2yh3XHaTj!=%Zx5JBEy;ss?7`Lo12Fdcl$O@5O428ox^WHBNrw<%b#I`4g=*CRjx6m|G_X3Dl#KMKUrPB1744TdYbNbA2m0f`B2}$^|;&r4HVHgO; zOmQ9}a!etEW#ouL9%E$cY6ScS6xy^HeMF(PWi$r9x4k*qWh@USh!ad@*`hvIjS{|`?D$^E5mK%(wKpl z#mJ^*yPKfI<#4?EUa9mIkZ*!K4e~a~9@KA@N-u%LZ>N|dPahDGiJHi!)vKz`!LJO6 zE!+$}k% zpQlBGyhiXjeCdP4YY(rH{aytN{$P9`>GdS*NU|WBSfF)_y!KJP^MMn--(ljljGtDj zsHch;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Rfzm@o}wJEQSAH)9#h{9HD diff --git a/goffy.c b/goffy.c deleted file mode 100644 index f76ca5b..0000000 --- a/goffy.c +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include - -int main() { - - const char src[20] = "HA! poopoohead!"; - char dest[100]; - - int eh = sprintf(dest, "%s", "goofy"); - - memcpy(dest + 6, src, strlen(src) + 1); - - printf("Output: %s\n", dest); - - printf("src[0] %p\n", &src[0]); - printf("src[0] %p\n\n", src); - printf("src[1] %p\n", &src[1]); - printf("src[1] %p\n", src + 1); - printf("src[50] %p\n", src + 49); - - printf("%ld", sizeof(dest)); - - return 0; -} diff --git a/server b/server index 9c9a369abf99d91b2f638df1217181756ca0046e..6379fb5140342c098f46726eb47527c4976d8958 100755 GIT binary patch literal 17184 zcmeHOe{dYteSeZM2xD0?*ugPOymc^R6Lgkr*)et%5X>c6|!GRs@WN1dvOiEiP z*U$I8_dV?`cS$FIr2XT*(%$!dKkxhfzPI1qeQ)2s_x?ECv$wvkPB1MI9}*;;T&WOK zXBfM50?ZUUL?eC;u})kK`6`L2d{Z&xDtfKHoHuBE2{_rUp+p6Kvw{V4t|4)_J%lRc87oqLhj$pEz z*LL&Tj`;#r2*jM@Nim^ghxQlb2J(mu`71=w?p|#dIO{2O)pdd-`_m*cn=$9r(_eMNRuUphB+-5y3tVZ>i?zBfX=8XZRlm*Ll; z`=SzlstW!#a05q>W&u?4v%d;HT?JoX1*dCJ$v?%T5>D-0CHzxW@Xb~5W)xr`FGybo zP|5$FSHbsI!RcPBBa&Wf*cAiuWK0ZusboU_y24FG|IqP7#)-s)ZKIKh+O8MLc=kvno)n3=>p4jg zPdc6r2N5ykcw~``j5tt_jz#RjcrucRA9sYS%S)u9k%SkALL?e>(w>O8Q7J|fDVMC` z@NmZ+w(CYC$w4vVj6~Dp;#el`!H1VgMn}>pcOXh_({{11r@M2Hy(RR)QmU=Jl-##q*& z$kG6+^eE>!*m664V?2(gWvMu?u}}Z$<7hUn60d6cn^ImPeyHWqwQ)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sVX=qlcnZ7li*1|16i zn)?!c*oa25x&nvitX3=FNzMC{FgsMJAzl~U`GSX@H_M7zWoUJLaAY7Pla@^ahCd7WSHg$=sFbK`{A03Jt+8E zMhT1Vr2BwHUDme%Jqklv7VkvI(;L@P8`h>ICQTZ*{URB{8-8hXnNW#C^kixg zG%mnj3hl-@vm)6PhW*?i+YgI=PDyBp#Q#~1b&@=;wrlmJ&X&}P@&;sVR@EnyF^*Ii zlB=aLxFy?7E;Se(WEx$G@KCPOxDsKvbE{@m51)5_M>Agumo=HMxCW0YM!0SsWwyVz zcDEz{*q3`ddU_r1V!23m6&4lua=B!uiZE5*a-zB883%4$cY9}t!(A@BVq*6}n;a#1@_5dv%%*F;i!bah(+~yQf zcL;6L(MBwZusnyjNt4dR858(aoodIaYFA;6K=Zr%;nb-wN0x1`X@Yr zIN5vDJH{^}+MndP0-T=X^b)66iDv&1y{Pi_(cVX#Kb!6W&T{D~Z5eozOd4#EyfwrN zWj459YJvX8Cvt1N`}~b{hmX}AIqLV-dH1m+b&a2?YxLvqNd2Lw*`WjQWZ4t&(=tC~ zly8G4%Y$&Qd~)*DieE`TY1$*<_h!OlAID;yn34~1w*{wmL_-g^_U75d%@#agbxQ<8 zWu8&=0l`zjTj{i|s%=4V`p}`FhoQP(mvltSXkWV4$j6a==WL(?G8X8Xowhs>~$zSnyy1)KtsyhA0kgDhyOtOA{CX zKgg@CMsbw{F96BoG|uNJp#{fH_c#sWe~Ad3_LLb!Q=Nk=o-&)bs`3A2)Y5Swy{Dvc z81Om`;_wf`6>phA9G5Zp#9M6`b15000B=p1d0v(B)kd6+N;8CNb{Uc$SL_O4rl!nL MQlUtjabxWN16^L51ONa4 diff --git a/src/server.c b/src/server.c index 85713d6..b3948c5 100644 --- a/src/server.c +++ b/src/server.c @@ -10,10 +10,6 @@ #include "server.h" -/* - -TODO: CREATE SENDING RESPONSE FUNCTION - int send_response(int fd, char *header, char *content_type, void *body, int content_length) { const int max_response_size = 65536; char response[max_response_size]; @@ -25,17 +21,26 @@ int send_response(int fd, char *header, char *content_type, void *body, int cont int response_length = sprintf(response, "%s\n" - "Date: %s" + "Server: %s\n" + "Date: %s\n" "Connection: close\n" "Content-Length: %d\n" "Content-Type: %s\n" "\n", - header, asctime(info), content_length, content_type); + header, SERVER_VERSION, asctime(info), content_length, content_type); memcpy(response + response_length, body, content_length); -} + printf("%s\n", response); -*/ + write(fd, response, response_length); + + //if (write < 0) { + // perror("webserver (write)"); + // return write; + //} + + return 0; +} int main() { char buffer[BUFFER_SIZE]; @@ -126,20 +131,24 @@ int main() { continue; } } else { - char resp[100]; - int resp_size = snprintf(resp, 100, - "%s\r\n" - "Server: %s\r\n" - "Content-Type: %s\r\n" - "\r\n", - OK_HEAD, SERVER_VERSION, "text/html"); - - int valwrite = write(newsockfd, resp, resp_size); - printf("%s\n", OK_HEAD); - if (valwrite < 0) { - perror("webserver (write)"); - continue; - } + // char resp[100]; + // int resp_size = snprintf(resp, 100, + // "%s\r\n" + // "Server: %s\r\n" + // "Content-Type: %s\r\n" + // "\r\n", + // OK_HEAD, SERVER_VERSION, "text/html"); + // + // int valwrite = write(newsockfd, resp, resp_size); + // printf("%s\n", OK_HEAD); + // if (valwrite < 0) { + // perror("webserver (write)"); + // continue; + // } + + char body[100]; + int body_size = snprintf(body, 100, "%s\r\n", "hello"); + send_response(newsockfd, "HTTP/1.1 200 OK", "text/html", "deeznuts", sizeof(body_size)); } // write to the socket diff --git a/src/server.h b/src/server.h index 72ed635..7e9951b 100644 --- a/src/server.h +++ b/src/server.h @@ -1,7 +1,7 @@ #define PORT 8080 #define BUFFER_SIZE 1024 -static const char SERVER_VERSION[] = "winnie-http-server/0.0.1"; +static const char SERVER_VERSION[] = "winnie-http-server"; static const char BAD_REQUEST_HEAD[] = "HTTP/1.1 400 Bad Request"; static const char NOT_FOUND_HEAD[] = "HTTP/1.1 404 Not Found";