5 Mart 2015 Perşembe

Örnek HTTP/1.1 request ve response mesajları


HTTP/1.1 de virtual hosts yani sanal hostlar kavramı gelmiştir. Bu kavrama göre aynı fiziksel server bünyesinde birden fazla sanal host, kendi root klasörleri ve hostname'leri ile barındırılabilir.

Örneğin tek bir serverda hem www.example.com hem de www.example1.com adlı iki farklı web sitesi kendi klasörlerinde aynı anda host edilebilir.

Bu durumda bir servera istek gönderirken client'ın hangi host'tan istediğini de belirtmesi zorunluluğu doğmuştur. İşte bu yüzden HTTP/1.1 standardında bir request mesajında request line'dan sonra bir de "Host" adlı header ilave edilmesi zorunludur. Server bu header'da verilen bilgiye göre bünyesinde barındırdığı sanal hostlar arasından istekte bulunulan hostu bulur.

Bir HTTP/1.1 GET request örneği verelim.
GET /index.html HTTP/1.1
Host: 127.0.0.1
Bu isteğe server başarıyla cevap veriyor. Ve cevap mesajının body kısmında (headerdan sonraki boş satırı takiben) istenilen html dosyasını gönderiyor.
HTTP/1.1 200 OK
Date: Sun, 18 Oct 2009 12:10:12 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Sat, 20 Nov 2004 07:16:26 GMT
ETag: "10000000565a5-2c-3e94b66c2e680"
Accept-Ranges: bytes
Content-Length: 44
Content-Type: text/html
   
<html><body><h1>It works!</h1></body></html>

Eğer "Host" headerı konmazsa:
GET /index.html HTTP/1.1

Server bu isteğe 400 Bad request yani hatalı istek cevabı veriyor.
HTTP/1.1 400 Bad Request
Date: Sun, 18 Oct 2009 12:13:46 GMT
Server: Apache/2.2.14 (Win32)
Content-Length: 226
Connection: close
Content-Type: text/html; charset=iso-8859-1
   
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>

Eğer bir klasöre erişmek ister fakat sondaki / karakterini unutursak:
GET /testdir HTTP/1.1
Host: 127.0.0.1
Server 301 Moved permanently yani taşınmıştır cevabı veriyor. Location headerında da adrese / karakterini ekleyerek klasörün doğru URLsini veriyor.
HTTP/1.1 301 Moved Permanently
Date: Sun, 18 Oct 2009 13:19:15 GMT
Server: Apache/2.2.14 (Win32)
Location: http://127.0.0.1:8000/testdir/
Content-Length: 238
Content-Type: text/html; charset=iso-8859-1
   
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://127.0.0.1:8000/testdir/">here</a>.</p>

</body></html>
Genelde browser'lar bu cevabı alınca bu sayfayı göstermek yerine cevaptaki doğru URLye gider. Kullanıcı da klasörün sonundaki / karakterinin browser tarafından eklenmiş olduğunu farkeder.
Fakat sondaki / karakterini unutmazsak fazladan bir GET isteği ile zaman kaybetmemiş oluruz.


Bir proxy serverden GET request yollarsak:
GET http://www.amazon.com/index.html HTTP/1.1
Host: www.amazon.com
Connection: Close

Server cevabı parça parça yolluyor (Transfer-encoding: chunked). Via headeri ile proxy bilgisi veriyor.

HTTP/1.1 302 Found
Transfer-Encoding: chunked
Date: Fri, 27 Feb 2004 09:27:35 GMT
Content-Type: text/html; charset=iso-8859-1
Connection: close
Server: Stronghold/2.4.2 Apache/1.3.6 C2NetEU/2412 (Unix)
Set-Cookie: skin=; domain=.amazon.com; path=/; expires=Wed, 01-Aug-01 12:00:00 GMT
Connection: close
Location: http://www.amazon.com:80/exec/obidos/subst/home/home.html
Via: 1.1 xproxy (NetCache NetApp/5.3.1R4D5)
   
ed
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>302 Found</TITLE>
</HEAD><BODY>
<H1>Found</H1>
The document has moved
<A HREF="http://www.amazon.com:80/exec/obidos/subst/home/home.html">
here</A>.<P>
</BODY></HTML>
   
0
   



Bir HEAD request yaparsak:
HEAD /index.html HTTP/1.0
Serverdan body kısmı olmayan bir cevap gelir. Yani sadece mesajın header kısmı gelir.

HTTP/1.1 200 OK
Date: Sun, 18 Oct 2009 14:09:16 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Sat, 20 Nov 2004 07:16:26 GMT
ETag: "10000000565a5-2c-3e94b66c2e680"
Accept-Ranges: bytes
Content-Length: 44
Connection: close
Content-Type: text/html
X-Pad: avoid browser bug



Serverın hangi istek metodlarını desteklediğini öğrenmek için bir OPTIONS isteği gönderebiliriz:
OPTIONS http://www.amazon.com/ HTTP/1.1
Host: www.amazon.com
Connection: Close
Serverdan Allow headerı ile desteklediği metodların isimleri gelir.

HTTP/1.1 200 OK
Date: Fri, 27 Feb 2004 09:42:46 GMT
Content-Length: 0
Connection: close
Server: Stronghold/2.4.2 Apache/1.3.6 C2NetEU/2412 (Unix)
Allow: GET, HEAD, POST, OPTIONS, TRACE
Connection: close
Via: 1.1 xproxy (NetCache NetApp/5.3.1R4D5)



Serverdan bilgi edinme amaçlı bir diagnostic trace isteyebiliriz:
TRACE http://www.amazon.com/ HTTP/1.1
Host: www.amazon.com
Connection: Close
Server TRACE bilgisi gönderecektir. Bu bilgiler trace request ile trace route karşılaştırması yapmakta kullanılabilir.
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Fri, 27 Feb 2004 09:44:21 GMT
Content-Type: message/http
Connection: close
Server: Stronghold/2.4.2 Apache/1.3.6 C2NetEU/2412 (Unix)
Connection: close
Via: 1.1 xproxy (NetCache NetApp/5.3.1R4D5)
   
9d
TRACE / HTTP/1.1
Connection: keep-alive
Host: www.amazon.com
Via: 1.1 xproxy (NetCache NetApp/5.3.1R4D5)
X-Forwarded-For: 155.69.185.59, 155.69.5.234
   
0
   






































Hiç yorum yok:

Yorum Gönder