https://roka88.dev/105

RFC7230 - 3. Message Format

Server::readRequest()

All HTTP/1.1 messages consist of a start-line followed by a sequence of octets in a format similar to the Internet Message Format [RFC5322]: zero or more header fields (collectively referred to as the "headers" or the "header section"), an empty line indicating the end of the header section, and an optional message body.

모든 HTTP/1.1 메시지는 인터넷 메시지 형식 [RFC5232]과 유사한 형식의 일련의 octets 시퀸스 뒤에 start-line으로 구성한다: 0 또는 여러 헤더 필드(집합적으로 "헤더"또는"헤더 부문"이라고 함), 헤더 부문의 끝을 나타내는 빈 줄 및 선택적 메시지 본문으로 구성된다.

<aside> 📖 HTTP-message = start-line *( header-field CRLF ) CRLF [ message-body ]

</aside>

/* Server.cpp */

int		Server::readRequest(std::vector<Client*>::iterator it)
{
	ret = read(client->fd, client->rBuf + bytes, BUFFER_SIZE);
		bytes += ret;
		if (ret > 0)
		{
			client->rBuf[bytes] = '\\0';
			if (strstr(client->rBuf, "\\r\\n\\r\\n") != NULL
				&& client->status != Client::BODYPARSING)
			{
				...
...
}

RFC7230 - 3.1.1 Request Line

Parser::parseRequest()

A request-line begins with a method token, followed by a single space (SP), the request-target, another single space (SP), the protocol version, and ends with CRLF.

request-line은 method 토큰을 시작으로, 공백 (SP), request-target, 공백 (SP), 프로토콜 버전, 그리고 CRLF를 끝으로 한다.

ft::getline(buffer, request.method, ' ');
ft::getline(buffer, request.uri, ' ');
ft::getline(buffer, request.version);

Parser::checkSyntax()

The method token indicates the request method to be performed on the target resource. The request method is case-sensitive.

method 토큰은 대상 리소스를 실행하기 위한 요청 메서드를 표시한다. 요청 메서드는 대 소문자를 구분한다.