[웹] HTTP Keep-Alive 헤더란 무엇인가?

프로그래밍/웹2020. 12. 8. 23:08

http header와 관련된 값으로 keep-alive가 있습니다.

관련 자료들을 찾아보니 자세하게 설명하려면 너무 길어져 간단하게 보고 넘어가겠습니다.

 

Response Header

HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Thu, 11 Aug 2016 15:23:13 GMT
Keep-Alive: timeout=5, max=1000
Last-Modified: Mon, 25 Jul 2016 04:32:39 GMT
Server: Apache

(body)

 

먼저 사용 예는 위와 같습니다. 

HTTP 는 TCP 위에서(기반으로) 동작을 합니다.  TCP가 전송이 끝나면 연결이 끊어지듯이 HTTP도 서로 전송이 끝나면 끊어집니다. 그런데 매번 이렇게 똑같은 주소로 요청을 할 때마다 새로운 연결을 설정하고 끊어야 한다면.. 자원이 낭비됩니다.

이런 문제를 막고자 Keep-Alive가 생겼습니다. 말 그대로.. '연결을 계속 유지해라'라는 의미를 가지고 있습니다.

최소 특정 시간동안(timeout) 최대 요청 request(max)의 수를 알려줄 수 있습니다.

 

위의 예시 코드를 본다면.. 최소 5초동안 최대 1000번의 요청을 할 경우에는 http connection이 끊어지지 않을 것으로 보입니다. 와이어 샤크로 패킷을 보면 정확하겠네요. 아래의 참고글에 자세한 설명이 있는 글이 있습니다.

 

역사가 좀 있네요. 아쉽게도? http 표준은 아닌 것 같은데 ㅎㅎ HTTP 1.1부터는 기본적으로 Keep-Alive로 동작한다고 합니다.

 

Keep-Alive가 DDOS의 아주 특별한 경우에.. 예방책으로 쓸 수는 있는 것 같으나 좋은 방법은 아닌가 봅니다.

참고

developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive

 

Keep-Alive

The Keep-Alive general header allows the sender to hint about how the connection may be used to set a timeout and a maximum amount of requests.

developer.mozilla.org

blog.naver.com/whdgml1996/222153047879

 

[Network 04] Persistent Connection을 위한 기술 01 - Keep Alive (TCP, HTTP)

0. 들어가며​ 최근, http의 persistent connection을 유지하는 기술들에 대해서 공부를 시작하면서 keep-a...

blog.naver.com

serverfault.com/questions/902143/can-tcp-keepalive-technique-be-used-to-prevent-ddos

 

Can TCP Keepalive technique be used to prevent DDOS?

I am learning about DDOS and the techniques to mitigate it. TCP Keepalive is used to check if the other host is still up and if the host does not acknowledge the tcp keep alive message, the connect...

serverfault.com

 

작성자

Posted by 드리머즈

관련 글

댓글 영역