ftinx / webserv

http/1.1 multiplexing webserver
0 stars 0 forks source link

[Request] checkCGI() 수정/추가 필요 #90

Closed hochan222 closed 3 years ago

hochan222 commented 3 years ago
Response
Server::methodPOST(int clientfd)
{
    std::string path = this->m_requests[clientfd].get_m_uri().get_m_path();
    std::map<std::string, std::string> m_query = parseQuery(this->m_requests[clientfd].get_m_body());
    std::string username;
    std::string password;

    printf("::%s::\n", this->m_requests[clientfd].get_m_uri().get_m_uri().c_str());
    printf("::%s::\n", path.c_str());
    printf("::%d::\n", this->m_requests[clientfd].get_m_check_cgi());

    if (this->m_requests[clientfd].get_m_check_cgi())
        return (postCGI(clientfd));
    if (path == "/auth")
    {
        if(m_query.find("formType") != m_query.end()
        && m_query.find("formType")->second == "login")
        {
            username = m_query.find("username")->second;
            password = m_query.find("password")->second;

            printf("::%s:: ::%s::", username.c_str(), password.c_str());
            printf("::%d:: ::%d::", username == "42seoul", password == "42seoul");

            if (username == "42seoul" && password == "42seoul")
                return (post_200());
            else
                return (page200());
        }
    }
    return (page404());
}
    if (this->m_requests[clientfd].get_m_check_cgi())
        return (postCGI(clientfd));

서버에서 다음과 같이 cgi 인지아닌지를 체크해줘서 CGI 처리를 하려고합니다.

void
Request::checkCGI()
{
    int p;

    p = this->m_uri.get_m_path().find("cgi-bin/");
    if (p == 0)
        this->m_check_cgi = true;
    else
        this->m_check_cgi = false;
}

그러나 checkCGI()는 전체 path /auth.cgi 에서 .cgi 확장자로 cgi인지를 판단하는게아닌 웹서버 폴더내에 cgi 존재여부로 판단을 합니다. 이럴경우 .cgi로 요청이 왔음에도 서버 코드에서는 일반 post 처리가 될 수 있습니다. 따라서, .cgi 확장자인지 아닌지로 cgi를 판단하는 로직을 따로 짜야되는데 request에서 처리해야하므로 이슈를 달았습니다.

88 에 우선 추가. 먼저 Merge 필요

hochan222 commented 3 years ago

Path 전체에 대해 CGI 처리 혹은 일반 처리를 하기때문에 불필요!