diff --git a/srcs/sock/Client.cpp b/srcs/sock/Client.cpp index 116d062..b230fca 100644 --- a/srcs/sock/Client.cpp +++ b/srcs/sock/Client.cpp @@ -26,6 +26,8 @@ void Client::clean(void) { } bool Client::getHeader(Env *env, string paquet) { + if (paquet.length() < 1) + send_error(403); if (header_pick("Method:", 0) != "") return true; std::vector< string > lines = split(paquet, "\r\n"); @@ -212,7 +214,15 @@ void Client::send_cgi(string cgi, string path) { << ret; send_answer(ss.str()); } - +/* +void Client::send_redir(int redir_code, string opt) { + switch (redir_code) { + case 301: + return send_answer( + "HTTTP/1.1 301 Moved Permanently\r\nLocation: " + opt + "\r\n\r\n"); + } +} +*/ void Client::send_error(int error_code) { switch (error_code) { case 400: diff --git a/srcs/sock/Master.cpp b/srcs/sock/Master.cpp index 413906c..6ede9d2 100644 --- a/srcs/sock/Master.cpp +++ b/srcs/sock/Master.cpp @@ -25,19 +25,25 @@ Master::Master(ip_port_t list) : _listen(list) { throw std::runtime_error("socket() error" + string(strerror(errno))); int opt_ret = setsockopt(_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(opt)); - if (opt_ret < 0) + if (opt_ret < 0) { + close(_fd); throw std::runtime_error("setsockopt() error: " + string(strerror(errno))); + } _address.sin_family = AF_INET; _address.sin_addr.s_addr = inet_addr(ip.c_str()); _address.sin_port = htons(port); - if (bind(_fd, (struct sockaddr *)&_address, sizeof(_address)) < 0) + if (bind(_fd, (struct sockaddr *)&_address, sizeof(_address)) < 0) { + close(_fd); throw std::runtime_error("bind() error: " + string(strerror(errno))); + } - if (listen(_fd, 3) < 0) + if (listen(_fd, 3) < 0) { + close(_fd); throw std::runtime_error("listen() error: " + string(strerror(errno))); + } cout << "New master socket with fd " << _fd << " which listen " << ip << ":" << port << "\n"; if (_fd < _min_fd)