> For the complete documentation index, see [llms.txt](https://42seoul.gitbook.io/webserv/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://42seoul.gitbook.io/webserv/or-mainary-method.md).

# 구현 | 주요 메소드

객체별 주요 메소드들에 대해 설명합니다.

### Request

```cpp
bool isOverTime() const;
```

CGI 프로그램의 실행시간이 길어지면 Gateway Timeout 에러로 판단합니다. 그러려면 CGI 프로그램 실행시 시간을 저장해놓고, CGI 프로그램과 입출력을 주고받으며 overtime을 체크하는 작업이 필요합니다.

### **Response**

```cpp
std::string getString() const;
```

getter와 setter를 제외하면 response의 핵심 메소드는 멤버 변수들을 응답 메시지로 취합하는 getString입니다. str로 네이밍하는 것도 직관적입니다.

### Connection

```cpp
void set_m_wbuf_for_execute();
void set_m_wbuf_for_send(std::string wbuf_string = "");
bool sendFromWbuf(int fd);

bool isOverTime() const;
void clear();
```

cgi program이나 client에게 보낼 data를 write 버프에 세팅합니다. 전자는 단순히 body를 세팅하면 되고, 후자는 response의 getString 함수를 호출하면 됩니다.

### Server

```cpp
int getUnuseConnectionFd();
bool parseStartLine(Connection& connection, Request& request);
bool parseHeader(Connection& connection, Request& request);
bool parseBody(Connection& connection, Request& request);

bool hasRequest(Connection& connection);
bool runRecvAndSolve(Connection& connection);
bool hasExecuteWork(Connection& connection);
bool runExecute(Connection& connection)
bool hasSendWork(Connection& connection);
bool runSend(Connection& connection);

void run();
void solveRequest(Connection& connection, const Request& request);
void executeAutoindex(Connection& connection, const Request& request);
void executeGet(Connection& connection, const Request& request);
void executeHead(Connection& connection, const Request& request);
void executePost(Connection& connection, const Request& request);
void executePut(Connection& connection, const Request& request);
void executeDelete(Connection& connection, const Request& request);
void executeOptions(Connection& connection, const Request& request);
void executeTrace(Connection& connection, const Request& request);
void executeCGI(Connection& connection, const Request& request);
void createResponse(Connection& connection, int status, headers_t headers = headers_t(), std::string body = "");
```

서버에는 위에 정리한 것 이외에도 매우 많은 함수들이 있습니다. 파싱 함수들, 새로운 커넥션을 받아들일 fd가 부족할 때 닫아도 괜찮은 커넥션 fd를 가져오는 함수, 각 operation이 가능한지 확인하고 실행하는 함수들 등이 있습니다.

### ServerManager

```cpp
void fdSet(int fd, SetType fdset);
void fdZero(SetType fdset);
void fdClear(int fd, SetType fdset);
bool fdIsset(int fd, SetType fdset);
void fdCopy(SetType fdset);

void createServer(const std::string& configuration_file_path, char **env);
void runServer();
void exitServer(const std::string& error_msg);
```

fd 유틸들은 libft에 구현합니다. 그러나 fd\_set이 서버매니저의 변수로 있기 때문에, 서버에서 서버매니저의 fd\_set을 getter로 호출하여 다시 넘기려면 코드가 길어집니다. 그래서 서버가 매크로를 인자로 서버매니저의 함수를 호출하고, 서버매니저로 하여금 자신의 멤버변수로 libft의 fd 함수들을 실행하도록 처리하면 편합니다.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://42seoul.gitbook.io/webserv/or-mainary-method.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
