diff --git a/README.md b/README.md
index 3f0b40e..9643f38 100644
--- a/README.md
+++ b/README.md
@@ -245,43 +245,55 @@ REDIRECT_STATUS : for exemple, 200
---
-## http errors
-
-#### HTTP Client Errors
-- 400 Bad Request This error code indicates that the request cannot be processed because of wrong syntax usage by the client.
-- 401 Unauthorized This error code indicates that the client is not authorized to receive the requested data, without authentication. A login name and password based authentication might be required to access the requested data.
-- 403 Forbidden There is no way you can access the requested data. A 403 error announces that the data is off limits.
-- 404 Not Found This error indicates that the resources requested by the client are currently unavailable.
-- 405 Method Not Allowed This error indicates wrong usage of request method. Depending on the kind of data requested, the appropriate request method must be chosen.
-- 406 Not Acceptable When the data provided by a web server does not match the specifications made in ‘Accept’ header of the client HTTP request, this error is the result.
-- 407 Proxy Authentication Required This error clearly indicates that an authentication from the proxy server is required to gain access to requested resources.
-- 408 Request Timeout This type of error indicates that the client was delayed in making a request, within the specified time allocated to it, by the server.
-- 409 Conflict This error code is displayed when the server perceives a conflict between two requests made simultaneously by different clients, for the same resource.
-- 410 Gone This error code indicates that the requested data is no longer hosted on the server and therefore further requests made for it, would be futile.
-- 411 Length Required If the request made by the client does not include information about the length of the requested data or resource, this error code is displayed.
-- 412 Precondition Failed Some requests made by clients come attached with conditions that need to be satisfied by the server, before data transaction may happen. If these conditions are not met, error 412 results.
-- 413 Request Entity Too Large When a client makes a request which is too overwhelming for the server’s resources to handle, it presents this error code.
-- 414 Requested URI Too Long A Uniform Resource Identifier (URI) is a character string used to describe a data stream or resource on a server. Error 414 occurs when the server is unable to process the URI, because of limited resources and long string length.
-- 415 Unsupported Media Type A server may be designed to allow only certain formats for media files. When error 415 is displayed, it indicates that the format of file being uploaded through a client request, does not match the requisite format.
-- 416 Request Range Not Satisfiable Sometimes, a client may request for only a small part of a file, instead of asking for the entire file. If this request is not specified properly and the part of the file requested does not exist, this error is displayed.
-- 417 Expectation Failed This error code is displayed when the server cannot meet the specifications provided in the request.
-- 422 Unprocessable Entity This error is displayed when the request made, cannot be processed due to an error in semantic structure.
-- 423 Locked This error is displayed when a requested piece of data or resource has been locked, making it inaccessible for a server.
-- 424 Failed Dependency A server may process a succession of requests from a client with the fulfillment of each, dependent on the one made before. This error is displayed when a request made before is not fulfilled, due to which the current request cannot be processed.
-- 426 Upgrade Required This error signifies that the client may need to switch over to a secure protocol like TLS to get the request processed.
-- 444 No Response This error signifies that the server has simply rejected the client request and terminated connection.
-- 449 Retry With This is a request made by the server to the client, to make the request again after executing certain actions or making specific changes in request. This is an error code introduced by Microsoft.
-- 499 Client Closed Request When client terminates a connection made with the server, while its processing the associated request, this error code is displayed.
-- 450 Blocked By Windows Parental Controls Another error code introduced by Microsoft, this one is displayed when a URL is blocked by parental control settings on the web browsers.
-
-#### HTTP Server Errors
-- 500 Internal Server Error A generic message displayed by the server, when the problem with the request cannot be specified by any other appropriate code.
-- 501 Not Implemented This error indicates the inability of the server to process a request, as it hasn’t been configured to respond to the request method used.
-- 502 Bad Gateway Sometimes, hosted pages on web servers are transmitted to client via proxy servers. If the proxy server (to which a client has sent a request), fails connecting with the web server (known as the upstream server), error 502 results.
-- 503 Service Unavailable When the server is already overloaded with multiple requests, it will temporarily stop entertaining new requests, by displaying a 503 error code.
-- 504 Gateway Timeout When the request made by a proxy server to the web server hosting a resource times out, error 504 is reported.
-- 505 HTTP Version Not Supported An error code seen rarely, it is displayed when the web server does not support the protocol version of the client request.
+## http status
+[rfc 2616](https://datatracker.ietf.org/doc/html/rfc2616#section-10)
+#### Informational
+- 100 Continue
+- 101 Switching Protocols
+#### Successful
+- 200 OK
+- 201 Created
+- 202 Accepted
+- 203 Non-Authoritative Information
+- 204 No Content
+- 205 Reset Content
+- 206 Partial Content
+#### Redirection
+- 300 Multiple Choices
+- 301 Moved Permanently
+- 302 Found
+- 303 See Other
+- 304 Not Modified
+- 305 Use Proxy
+- 306 (Unused)
+- 307 Temporary Redirect
+#### Client Error
+- 400 Bad Request
+- 401 Unauthorized
+- 402 Payment Required
+- 403 Forbidden
+- 404 Not Found
+- 405 Method Not Allowed
+- 406 Not Acceptable
+- 407 Proxy Authentication Required
+- 408 Request Timeout
+- 409 Conflict
+- 410 Gone
+- 411 Length Required
+- 412 Precondition Failed
+- 413 Request Entity Too Large
+- 414 Request-URI Too Long
+- 415 Unsupported Media Type
+- 416 Requested Range Not Satisfiable
+- 417 Expectation Failed
+#### Server Error
+- 500 Internal Server Error
+- 501 Not Implemented
+- 502 Bad Gateway
+- 503 Service Unavailable
+- 504 Gateway Timeout
+- 505 HTTP Version Not Supported
---
## ressources
diff --git a/srcs/cgi-bin/Makefile b/srcs/cgi-bin/Makefile
index 5f521ed..59f349c 100644
--- a/srcs/cgi-bin/Makefile
+++ b/srcs/cgi-bin/Makefile
@@ -32,6 +32,9 @@ RESET = "\e[0m"
NAME_1 = $(SRCS_1:.cpp=.out)
NAME_2 = $(SRCS_2:.cpp=.out)
+NAME_3 = $(SRCS_3:.cpp=.out)
+NAME_4 = $(SRCS_4:.cpp=.out)
+NAME_5 = $(SRCS_5:.cpp=.out)
CXX = c++
CXXFLAGS = -Wall -Wextra #-Werror
@@ -45,12 +48,18 @@ SRCS_D = .
SRCS = cgi_utils.cpp
SRCS_1 = cgi_cpp.cpp
-SRCS_2 = cgi_cpp_content_length.cpp
+SRCS_2 = cgi_cpp_len.cpp
+SRCS_3 = cgi_cpp_len_big.cpp
+SRCS_4 = cgi_cpp_len_small.cpp
+SRCS_5 = cgi_cpp_status.cpp
OBJS_D = builds
OBJS = $(SRCS:%.cpp=$(OBJS_D)/%.o)
OBJS_1 = $(SRCS_1:%.cpp=$(OBJS_D)/%.o)
OBJS_2 = $(SRCS_2:%.cpp=$(OBJS_D)/%.o)
+OBJS_3 = $(SRCS_3:%.cpp=$(OBJS_D)/%.o)
+OBJS_4 = $(SRCS_4:%.cpp=$(OBJS_D)/%.o)
+OBJS_5 = $(SRCS_5:%.cpp=$(OBJS_D)/%.o)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# . target: prerequisites . $@ : target #
@@ -58,9 +67,12 @@ OBJS_2 = $(SRCS_2:%.cpp=$(OBJS_D)/%.o)
# . recipe . $^ : all prerequisites #
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
-all: cgi_1 cgi_2
+all: cgi_1 cgi_2 cgi_3 cgi_4 cgi_5
cgi_1: $(NAME_1)
cgi_2: $(NAME_2)
+cgi_3: $(NAME_3)
+cgi_4: $(NAME_4)
+cgi_5: $(NAME_5)
$(OBJS_D)/%.o: %.cpp | $(OBJS_D)
$(CXX) $(CXXFLAGS) -c $< -o $@
@@ -70,7 +82,10 @@ $(OBJS_D):
$(NAME_1): $(OBJS) $(OBJS_1)
$(NAME_2): $(OBJS) $(OBJS_2)
-$(NAME_1) $(NAME_2):
+$(NAME_3): $(OBJS) $(OBJS_3)
+$(NAME_4): $(OBJS) $(OBJS_4)
+$(NAME_5): $(OBJS) $(OBJS_5)
+$(NAME_1) $(NAME_2) $(NAME_3) $(NAME_4) $(NAME_5):
$(CXX) $^ -o $@
clean:
@@ -79,6 +94,9 @@ clean:
fclean: clean
rm -f $(NAME_1)
rm -f $(NAME_2)
+ rm -f $(NAME_3)
+ rm -f $(NAME_4)
+ rm -f $(NAME_5)
re: fclean all
diff --git a/srcs/cgi-bin/cgi b/srcs/cgi-bin/cgi
deleted file mode 100755
index 14e0d29..0000000
--- a/srcs/cgi-bin/cgi
+++ /dev/null
@@ -1,4 +0,0 @@
-#! /bin/bash
-echo "status: 100\r\n"
-echo "\r\n\r\n"
-echo "hiii"
diff --git a/srcs/cgi-bin/cgi_cpp.cpp b/srcs/cgi-bin/cgi_cpp.cpp
index 10c475a..ea66df3 100644
--- a/srcs/cgi-bin/cgi_cpp.cpp
+++ b/srcs/cgi-bin/cgi_cpp.cpp
@@ -3,46 +3,13 @@
int main (int ac, char **av, char ** env)
{
- std::string rq_method = "not found";
- std::string rq_body = "";
- std::string rq_query = "";
- std::string form_infos = "";
- std::string http_header = "";
- std::string http_body = "";
+ std::string http_header;
+ std::string http_body;
(void)ac;
(void)av;
- rq_method = parse_env("REQUEST_METHOD");
- rq_body = parse_body();
- rq_query = parse_env("QUERY_STRING");
-
- if (rq_method == "POST")
- form_infos = rq_body;
- else if (rq_method == "GET")
- form_infos = rq_query;
-
- http_body = HTML_BODY_TOP;
-
- http_body += "
" + rq_method + "
"; - - http_body += "" + rq_body + "
"; - - http_body += "" + rq_query + "
"; - - http_body += "" - << sub_split_str[0] - << " : " - << sub_split_str[1] - << "
"; - } - - tmp = getenv("QUERY_STRING"); - if (tmp == NULL) - std::cout << "query not foud"; - - std::cout - << "" - << sub_split_str[1] - << "
"; - } - - - std::cout - << "" - << ""; - - return 0; -} - diff --git a/srcs/cgi-bin/cgi_cpp_len.cpp b/srcs/cgi-bin/cgi_cpp_len.cpp new file mode 100644 index 0000000..566ae7d --- /dev/null +++ b/srcs/cgi-bin/cgi_cpp_len.cpp @@ -0,0 +1,20 @@ + +# include "cgi_utils.hpp" + +int main (int ac, char **av, char ** env) +{ + std::string http_header; + std::string http_body; + + (void)ac; + (void)av; + + fill_response_basic(env, http_body, http_header); + + http_header += "Content-Length: " + itos(http_body.size()); + + std::cout << http_header << CRLF CRLF << http_body; + + return 0; +} + diff --git a/srcs/cgi-bin/cgi_cpp_len_big.cpp b/srcs/cgi-bin/cgi_cpp_len_big.cpp new file mode 100644 index 0000000..4d8025e --- /dev/null +++ b/srcs/cgi-bin/cgi_cpp_len_big.cpp @@ -0,0 +1,20 @@ + +# include "cgi_utils.hpp" + +int main (int ac, char **av, char ** env) +{ + std::string http_header; + std::string http_body; + + (void)ac; + (void)av; + + fill_response_basic(env, http_body, http_header); + + http_header += "Content-Length: " + itos(http_body.size() + 100); + + std::cout << http_header << CRLF CRLF << http_body; + + return 0; +} + diff --git a/srcs/cgi-bin/cgi_cpp_len_small.cpp b/srcs/cgi-bin/cgi_cpp_len_small.cpp new file mode 100644 index 0000000..4c58df9 --- /dev/null +++ b/srcs/cgi-bin/cgi_cpp_len_small.cpp @@ -0,0 +1,20 @@ + +# include "cgi_utils.hpp" + +int main (int ac, char **av, char ** env) +{ + std::string http_header; + std::string http_body; + + (void)ac; + (void)av; + + fill_response_basic(env, http_body, http_header); + + http_header += "Content-Length: " + itos(http_body.size() - 100); + + std::cout << http_header << CRLF CRLF << http_body; + + return 0; +} + diff --git a/srcs/cgi-bin/cgi_cpp_status.cpp b/srcs/cgi-bin/cgi_cpp_status.cpp new file mode 100644 index 0000000..7fc2715 --- /dev/null +++ b/srcs/cgi-bin/cgi_cpp_status.cpp @@ -0,0 +1,22 @@ + +# include "cgi_utils.hpp" + +int main (int ac, char **av, char ** env) +{ + std::string http_header; + std::string http_body; + std::string http_status; + + (void)ac; + (void)av; + + fill_response_basic(env, http_body, http_header); + + http_status = get_value("Status"); + http_header += "Status: " + http_status; + + std::cout << http_header << CRLF CRLF << http_body; + + return 0; +} + diff --git a/srcs/cgi-bin/cgi_utils.cpp b/srcs/cgi-bin/cgi_utils.cpp index cea2ca9..3be41e3 100644 --- a/srcs/cgi-bin/cgi_utils.cpp +++ b/srcs/cgi-bin/cgi_utils.cpp @@ -1,5 +1,11 @@ #include "cgi_utils.hpp" +std::string str_tolower(std::string str) +{ + std::transform(str.begin(), str.end(), str.begin(), ::tolower); + return str; +} + std::string trim(std::string str, char del) { size_t pos; @@ -91,14 +97,99 @@ std::string std::vector" + rq_method + "
"; + + http_body += "" + rq_body + "
"; + + http_body += "" + rq_query + "
"; + + http_body += "