Handler::getConf() 의 std::string file 변수 삭제
// std::string file; // 사용하지 않아서 주석처리 해둠
.
.
.
// 사용하지 않아서 일단 주석처리 해둠
// file = req.uri.substr(req.uri.find_last_of('/') + 1, req.uri.find('?')); // req.uri의 마지막 슬래쉬부터 ?까지의 문자열을 file에 넣어준다
Handler::parseRequest() if문 client.status를 Client::CODE로 설정하는 부분이 중복되어 수정
if (request.valid) // checksyntax를 넘어오면
{
if (client.conf["root"][0] != '\\0') // 경로가 있으면
chdir(client.conf["root"].c_str()); // 경로로 이동
if (request.method == "POST" || request.method == "PUT") // POST나 PUT이면 -> 자원을 생성 혹은 수정하기 위해.
client.status = Client::BODYPARSING; // BODY를 PARSING해야한다. POST 나 PUT인경우 요청메시지(rBuf)에 body부분이 들어가게 되어있음
else
client.status = Client::CODE; // CODE로 넘어간다.
}
else // valid하지 않으면
{
request.method = "BAD";
client.status = Client::CODE; // CODE로 넘어간다.
}
client.status = Client::CODE; // CODE로 넘어간다.
if (request.valid) // checksyntax를 넘어오면
{
if (client.conf["root"][0] != '\\0') // 경로가 있으면
chdir(client.conf["root"].c_str()); // 경로로 이동
if (request.method == "POST" || request.method == "PUT") // POST나 PUT이면 -> 자원을 생성 혹은 수정하기 위해.
client.status = Client::BODYPARSING; // BODY를 PARSING해야한다. POST 나 PUT인경우 요청메시지(rBuf)에 body부분이 들어가게 되어있음
}
else // valid하지 않으면
request.method = "BAD";
readRequest()에서 다음 코드를 수정
bytes = strlen(client->rBuf);
ret = read(client->fd, client->rBuf + bytes, BUFFER_SIZE - bytes); // 클라이언트가 보낸 request 메시지 읽기
bytes += ret;
char *tmp;
bytes = strlen(client->rBuf);
if (bytes > 0)
{
tmp = (char *)malloc(sizeof(char) * (bytes + BUFFER_SIZE + 1));
strcpy(tmp, client->rBuf);
free(client->rBuf);
client->rBuf = tmp;
}
ret = read(client->fd, client->rBuf + bytes, BUFFER_SIZE); // 클라이언트가 보낸 request 메시지 읽기
bytes += ret;
!! 수정 해야함!! Handler::getConf()
if (elmt.find("root") != elmt.end())
client.conf["path"].replace(0, tmp.size(), elmt["root"]);
if (elmt.find("root") != elmt.end()) // 그런데 이때 elmt에 'root'키가 들어있다면
client.conf["path"] = elmt["root"];
Helper::findLen()
if (to_convert.size() == 0)
len = 0;
else
len = fromHexa(to_convert.c_str()); //16진수 문자열 -> 10진수화
len = fromHexa(to_convert.c_str()); //???
*len = fromHexa(to_convert.c_str()); //지우기*
Handler::parseBody()
if (client.req.headers.find("Content-Length") != client.req.headers.end()) // client.req.headers에 "Content-Lenght"라는 key가 있으면
getBody(client); // getBody 실행
else if (client.req.headers["Transfer-Encoding"] == "chunked") // client.req.headers에 "Transfer-Encoding"의 value가 chunked이면. 즉, 분할전송방식을 채택한다면(sebaek)
dechunkBody(client); // dechunkBody 실행. Chunked방식은 전체데이터를 나눠서 보내기 때문에 HTTP헤더엔 Content-Length헤더가 존재하지 않음.
else // 길이를 구해올 수 없으면 error
{
client.req.method = "BAD";
client.status = Client::CODE;
}
if (client.status == Client::CODE) // Bad request인경우 로그 찍어줌. 디버깅용
g_logger.log("body size parsed from " + client.ip + ":" + std::to_string(client.port) + ": " + std::to_string(client.req.body.size()), MED);
if (client.req.headers.find("Content-Length") != client.req.headers.end()) // client.req.headers에 "Content-Lenght"라는 key가 있으면
getBody(client); // getBody 실행
else if (client.req.headers["Transfer-Encoding"] == "chunked") // client.req.headers에 "Transfer-Encoding"의 value가 chunked이면. 즉, 분할전송방식을 채택한다면(sebaek)
dechunkBody(client); // dechunkBody 실행. Chunked방식은 전체데이터를 나눠서 보내기 때문에 HTTP헤더엔 Content-Length헤더가 존재하지 않음.
else // 길이를 구해올 수 없으면 error
{
client.req.method = "BAD";
client.status = Client::CODE;
g_logger.log("body size parsed from " + client.ip + ":" + std::to_string(client.port) + ": " + std::to_string(client.req.body.size()), MED);
}
0427//
main.cpp
select(config.getMaxFd(g_servers) + 1, &readSet, &writeSet, NULL, &timeout);
select(ft::getMaxFd(g_servers) + 1, &readSet, &writeSet, NULL, &timeout);
0503
void Client::readFile()
{
...
else if (ret < 0)
g_logger.log("read() error", MED);
}
void Client::writeFile()
{
int ret = 0;
ret = write(1000, req.body.c_str(), req.body.size());
if (ret < 0)
{
close(write_fd);
setFileToWrite(false);
write_fd = -1;
g_logger.log("write() error", LOW);
return ;
}
void Server::send503(int fd)
{
...
if (ret < 0)
g_logger.log("write() error", LOW);
...