HTTP (Hyper-Text Transfer Protocol) 개요

네트워크 2008. 10. 11. 13:03 posted by 무병장수권력자


작성자 : 김문규
최초 작성일 : 2008.10.11

1. HTTP
HTTP는 Hyper-Text Transfer Protocol의 약자로 WWW(World Wide Web)에서 사용되는 Protocol 입니다.


2. Specification
HTTP/1.0은 RFC1945, HTTP/1.1은 RFC2068, RFC2616에 명시되어 있습니다.
HTTP/1.0 RFC1945 : rfc1945.txt.pdf
HTTP/1.1 RFC2068 : rfc2068.txt.pdf
HTTP/1.1 RFC2616 : rfc2616.txt.pdf

3. URL(Universal Resource Locator), URI (Uniform Resource Identifier)
웹 상의 리소스를 나타내는 주소, 식별자 입니다. IE나 Firefox에서 주소창에 입력하는 값입니다. 익숙하시죠?

아래의 형식을 따릅니다.
(프로토콜)://(호스트)/(경로)
http://www.iamcorean.net/data/32
프로토콜 : http
호스트 : www.iamcorean.net
경로 : /data/32

4. Request (요청)
웹 브라우져에 주소를 입력하면 브라우져는 해당 URL을 파싱하여 서버에 request를 전달하게 됩니다. request는 '무엇을 어떻게 해주세요~' 라는 내용을 담고 있습니다. 이때 '무엇'은 대부분 URL의 경로에 나타나게 됩니다. 그리고 '어떻게'는 method에 나타나게 됩니다.

아래는 대표적인 HTTP method 입니다. 여기에 TRACE라는 것이 있지만 쓰는 걸 못봐서 패스!
GET : 리소스 요청 (실제로는 서버단 비지니스 로직을 통하여 다른 동작을 수행하는 경우도 많습니다.)
POST : 리소스 생성, 수정 (사용자 입력 값을 전송하기 위해 많이 사용됩니다.)
PUT : 리소스 생성
DELETE : 리소스 삭제
OPTION : 해당 서버의 지원 method 응답
HEAD : GET과 동일하지만 헤더값으로만 응답하고 메세지 본체가 없다는 차이점이 있음

5. Response (응답)
서버는 요청받은 request를 처리한 후 이에 대한 성공 여부 및 실패 이유등을 response에 담아서 브라우져에게 돌려주게 됩니다. 이는 status code라고 불립니다.

아래의 주소는 이에 대한 자세한 내용을 담고 있는 스펙문서 입니다.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

유명한 예는 다음과 같습니다.
200 OK
400 Bad Request
403 Forbbiden
404 Not Found
408 Request Timeout
500 Internal Server Error
501 Not Implemented
503 Service Unavailable

6. HTTP Request & Response more...
앞서 4, 5에서 요청과 응답을 매우 간단하게 설명 드렸지만 실제로는 매우 자세한 내용을 헤더에 담아서 보내게 됩니다. 그 내용이 너무 많아서 구조만 설명하고 그 자세한 내용은 생략하겠습니다.

먼저 Request 헤더 입니다.
Request        = Request-Line              
                        *(( general-header        

                         | request-header         
                         | entity-header ) CRLF)  
                        CRLF
                        [ message-body ]         

Request-Line   = Method SP Request-URI SP HTTP-Version CRLF
               예:) GET /webmatter/235026_1.jpg HTTP/1.1[13][10]

Method         =    
                        "OPTIONS"                

                      | "GET"                    

                      | "HEAD"                   
                      | "POST"                   
                      | "PUT"                    
                      | "DELETE"                 
                      | "TRACE"                  
                      | "CONNECT"               


general-header =
                        Cache-Control            

                      | Connection               

                      | Date                     
                      | Pragma                   
                      | Trailer                  
                      | Transfer-Encoding        
                      | Upgrade                  
                      | Via                      
                      | Warning                 


request-header = 
                        Accept                   

                      | Accept-Charset           

                      | Accept-Encoding          
                      | Accept-Language          
                      | Authorization            
                      | Expect                   
                      | From                     
                      | Host                     
                      | If-Match                 
                      | If-Modified-Since        
                      | If-None-Match            

                      | If-Range                 
                      | If-Unmodified-Since      
                      | Max-Forwards             
                      | Proxy-Authorization      
                      | Range                    
                      | Referer                  
                      | TE                       
                      | User-Agent               
 

entity-header =
                         Allow                    
                      | Content-Encoding         

                      | Content-Language        
                      | Content-Length           
                      | Content-Location         
                      | Content-MD5              
                      | Content-Range           
                      | Content-Type             
                      | Expires                  
                      | Last-Modified         
                      | extension-header

extension-header = message-header


예:)
GET
/webmatter/235026_1.jpg HTTP/1.1CRLF 
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*CRLF
Accept-Language: koCRLF
Accept-Encoding: gzip, deflateCRLF
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)CRLF
Host: localhost
CRLF
Connection: Keep-AliveCRLFCRLF


그 다음은 Respose Header 입니다.

Response     = Status-Line               
                       *(( general-header        

                        | response-header        
                        | entity-header ) CRLF)  
                       CRLF
                       [ message-body ]         


Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF

response-header =       
                         Accept-Ranges           

                       | Age                     

                       | ETag                    
                       | Location                
                       | Proxy-Authenticate      

                       | Retry-After             
                       | Server                  

                       | Vary                    
                       | WWW-Authenticate       


예:)
HTTP/1.1 200 OK <-Status-Line
Date: Wed, 08 Oct 1997 11:40:24 GMT <-general-header
Server: Apache/1.3a1 <-response-header
Last-Modified: Wed, 08 Oct 1997 11:40:06 GMT <-entity-header
ETag: "0-1e4-343b7116" <-entity-header
Content-Length: 484 <-entity-header
Accept-Ranges: bytes <-entity-header
Content-Type: text/html <-entity-header


7. 참조
1. http://sungdh86.egloos.com/3403444
2. High Performance Web Site, Oreilly, Steve Soulder
3. http://byhou.sshel.com/tc/byhou/14

'네트워크' 카테고리의 다른 글

base64 인코딩 ,디코딩의 원리  (1) 2009.01.14
LDAP (Lightweight Directory Access Protocol)  (0) 2008.07.16
IPv6  (0) 2008.07.07
SNMP (Simple Netwok Management Protocol)  (0) 2008.07.07