Application Layer (HTTP)

1️⃣ What is the Web?

الويب ببساطة عبارة عن صفحات (Web Pages).

Web page = مجموعة Objects

Object ممكن يكون: HTML file, Image (JPEG, PNG), Audio / Video, Java applet …etc

كل Object ليه URL

www.someschool.edu/someDept/pic.gif
Host name
Path name

2️⃣ What is HTTP?

HTTP (HyperText Transfer Protocol): Application Layer Protocol for the Web.

هو بروتوكول طبقة التطبيق (Application Layer Protocol) الخاص بالويب.

Client / Server Model:

  • Client: المتصفح (Browser) [يطلب البيانات -> يستقبلها -> يعرضها]
  • Server: Web Server [يرد على الطلبات ويبعت Objects]

أمثلة:

Client: Chrome, Firefox, Safari

Server: Apache Web Server

3️⃣ HTTP uses TCP & is Stateless

HTTP مش شغال لوحده، ده بيستخدم TCP.

  1. Client يعمل TCP connection مع Server على Port 80
  2. Server يقبل الاتصال
  3. HTTP request / response يتبادلوا
  4. TCP connection يتقفل

⚠️ HTTP Stateless

السيرفر مش بيفتكر أي طلبات قديمة.. كل request مستقل لوحده.

4️⃣ Types of HTTP Connections

🔴 Non-Persistent

TCP connection لكل Object.

1 Object -> 1 Connection

لو الصفحة فيها 10 صور -> 10 connections

عيبها: بطيئة و overhead عالي.

Persistent

TCP connection واحدة.

Multiple Objects -> 1 Connection

ميزتها: أسرع وأفضل.

6️⃣ HTTP Response Time

مصطلح مهم: RTT (Round Trip Time) = وقت الذهاب والعودة بين client و server.

Response Time (per object)

  • 1 RTT -> TCP connection
  • 1 RTT -> request + first response
  • file transmission time
القانون (Non-Persistent):
Response time = 2 RTT + transmission time

7️⃣ HTTP Cookies

Cookies are used because HTTP is stateless.

استخداماتها: Login, Shopping carts, Recommendations, User session tracking.

مكونات الـ Cookies:

  1. Cookie header في HTTP response
  2. Cookie header في HTTP request
  3. Cookie file عند العميل (Browser)
  4. Database عند السيرفر

أول مرة تزور موقع -> السيرفر يديك Cookie ID. بعد كده أي request -> تبعت الـ Cookie.. السيرفر يعرفك.

8️⃣ Web Caching (Proxy Server)

Web Cache = وسيط بين client و server.

شغله: Browser يبعت الطلب للـ cache. لو object موجود -> يرجعه فورًا. لو مش موجود -> cache يجيبه من server ويخزنه.

الهدف: تقليل response time، وتقليل الضغط على الإنترنت، وتحسين الأداء.

🔟 Performance Example

Without Cache: Access link ~97% busy -> Queuing Delay HUGE -> Slow

With Cache: 40% requests hit cache -> Link traffic drops -> FAST

الخلاصة السريعة

  • HTTP = Application layer protocol
  • HTTP uses TCP
  • HTTP is Stateless
  • Non-persistent → Connection لكل Object
  • Persistent → Connection واحدة لكل الصفحة
  • Response time = 2RTT + transmission time
  • Cookies تحافظ على state
  • Web cache يقلل delay و traffic

Practice Arena 🎯

1. HTTP is correctly described as a ________ protocol because it does not maintain info about past requests.
2. Which HTTP Status code means 'OK' and indicates that the request has succeeded?