Skip to content

Latest commit

 

History

History
373 lines (232 loc) · 12.3 KB

02-network-and-http.md

File metadata and controls

373 lines (232 loc) · 12.3 KB
title
Network & HTTP Протокол

Network & HTTP Протокол

Для чого це мені потрібно зараз (на позиції Junior/Intern)?

Варіанти?

Check-list запитань:

  • How internet layers works?
  • What is IP and differences between IPv4/IPv6?
  • When the TCP & UDP uses?
  • What is DNS responsible for?
  • What are differences between GET/POST methods?
  • How to authorize user through the HTTP?
  • How real-time applications works?
  • How to use "Network" tag in Google DevTools.

Всесвітня мережа (WWW)

^ Advanced Research Projects Agency

^ 2000, The Internet spreads like wildfire. Internet is using by 40% of the entire human population

Наша задача: зрозуміти, як контактують точка А із точкою Б, у різних кінцях світу.

^ Evolution of Internet of Things

Чому мені (frontend розробнику) це потрібно знати?

Що таке Server?

Сервером може бути любий пристрій, типу комп'ютера, ноутбука, телефона, тощо, який готовий приймати і виконувати запити ззовні.

Серверна:

Сервер Lenovo x3650:

Перший WWW сервер (прочитайте лейбл на ньому):

Як вони між собою спілкуються?

Client-Server Communication:

Request-Response model (request-reply):

Команда ping:

Що таке Протокол?

First thing you need to know and understand is that HTTP is a protocol. That would be the P character in the acronym. What is a protocol good for? Many, many years ago one teacher tried to explain a protocol this way and I cannot think of any better way.

If you are going to visit the Queen of England (or any other of those blue blooded people) you are confronted with a list of things you are allowed to do and things you should not do under any circumstances. This list is called the royal protocol. There are also protocols in diplomacy. Other terms in this regard are Etiquette, Manners or Conventions.

Protocols in the computer world are certainly nothing like etiquette but more or less like the manners how computer components interact with each other. Convention is probably the most fitting term other than protocol.

Прокол Нової Пошти:

Які протоколи існують?

TCP, UDP, SOAP, IP, DNS, HTTP, POP3, SMTP, FTP, NTP, IRC, etc.

https://en.wikipedia.org/wiki/Lists_of_network_protocols

https://www.w3.org/Protocols/

Telegram MTProto - https://core.telegram.org/mtproto.

Як передаються дані?

...або Багатошарова архітектура (Layered architecture).

pen:

The pen in box:

The pen in box with declaration:

The pen in box with declaration is delivering to receiver:

The pen in box with declaration is delivered to receiver:

The pen in box with declaration is delivered to receiver. He got it, confirmed that he is receiver and got the box:

The pen in box with declaration is delivered to receiver. He got it & confirmed personality, unboxed and got the pen:

Багатошарова архітектура у роботі WWW

Model OSI:

TCP/IP Model:

На кожному рівні – свій набір протоколів.

Яка різниця між TCP та UDP? TCP - гарантує доставку, UDP - ні.

Що таке IP?

IPv4 (Internet Protocol version 4).

4 294 967 296 (4 млд) унікальних адрес.

Формат – 4 десяткових числа від 0 до 255 (2^8), октети.

2011 року виділено останні п’ять блоків IP-адрес.

Зарезервовані діапазони:

  • 127.0.0.0 – Localhost/Loopback
  • 0.0.0.0 – Current network
  • 10.0.0.0 – Private network
  • 172.16.0.0 – Private network
  • 192.168.0.0 – Private network
  • ...

IPv6.

2001:0db8:11a3:09d7:1f34:8a2e:07a0:765d

http://[2001:0db8:11a3:09d7:1f34:8a2e:07a0:765d]:8080/

0000:0000:0000:0000:0000:0000:ae21:ad12 => ::ae21:ad12

2006 release.

протокол IPv6 виділяє на адресу 16 байтів (раніше на інтернет-адресу виділяли 4 байти).

340 трильйонам унікальних адрес.

Що таке Port?

Що таке DNS?

~ $ host cursor.education
cursor.education has address 195.64.154.194
cursor.education mail is handled by 10 mail.cursor.education.

DSN Recors types:

  • A (Host address)
  • ALIAS (Auto resolved alias)
  • CNAME (Canonical name for an alias)
  • MX (Mail eXchange)
  • TXT (Descriptive text)
~ $ host -a cursor.education
Trying "cursor.education"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43851
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 0

;; ANSWER SECTION:
cursor.education.	14399	IN	SOA	ns7.rehost.com.ua. hostmaster.redo.com.ua. 2016021502 10200 3600 1209600 86400
cursor.education.	14399	IN	NS	ns8.rehost.com.ua.
cursor.education.	14399	IN	NS	ns7.rehost.com.ua.
cursor.education.	14399	IN	A	91.194.250.152
cursor.education.	14399	IN	TXT	"v=spf1 a mx ip4:91.194.250.152 ~all"
cursor.education.	14399	IN	MX	10 mail.cursor.education.

Received 227 bytes from 8.8.8.8#53 in 128 ms

/etc/hosts

URL & URN

Relative vs Absolute URLs:

  • Absolute URLs: http://yourdomain.com/images/example.png
  • Relative URLs: //yourdomain.com/images/example.png
  • Relative URLs: /images/example.png
  • Relative URLs: images/example.png
  • Relative URLs: file.php
  • Relative URLs: ../.././../css/default.css

HTTP протокол

HTTP – HyperText Transfer Protocol.

Яка різниця між методами GET vs POST?

https://www.tutorialspoint.com/http/http_methods.htm

HTTP verbs (methods):

  • GET – to retreive whatever information
  • POST – used to send data to the server for updates, submit information to web server
  • HEAD – response does not include message body, useful for getting metadata without transfering the resource
  • PUT – creates the resource if it does not create
  • DELETE – removes the web object
  • TRACE, OPTIONS, ...

HTTP протокол через Telnet

$ telnet google.com 80

GET / HTTP/1.1
Host: google.com

HTTP Request

GET /wiki/HTTP HTTP/1.0
Host: ru.wikipedia.org
User-Agent: HTTPTool/1.0

HTTP Response

HTTP/1.0 200 OK
Data: 123
Server: Apache/1.3.12 (Unix)
Last-Modified: (data)
Content-Type: text/html
Content-Length: (message-payload)

(message body)

Result code and phrase:

  • 1xx: Informational - not done yet
  • 2xx: Success - you win (200 OK)
  • 3xx: Redirection - you lose but try again (i.e. 301 Moved Permanently, 302 Found, ...)
  • 4xx: Client Error - you lose, your fault (i.e. 401 Unauthorized, 403 Forbidden, 404 Not Found, ...)
  • 5xx: Server Error - you lose, my bad (i.e. 500 Internal Server Error, ...)

HTTP headers

Postman and DevTools

https://www.getpostman.com/

https://www.postman-echo.com/

HTTP in Depth (в деталях)

  • Cookies
  • Sessions
  • Idempotent and Safe methods

HTTP Cookies & Sessions

Cookies:

Sessions:

HTTP перенаправлення на іншу адресу (redirect)

HTTP/1.1 302 Found
Location: ...

HTTP Authentication

HTTPS протокол

Як завантажується сторінка?

  • parsing of URL (detected HTTP protocol, and "/" resource)
  • DNS request to get a IP
  • open Socket connection over TCP (ip + port)
  • create HTTP packet & send
  • wait & get the HTTP response
  • close the TCP connection
  • parse & render the response body in browser

Again, для чого це мені (програмісту) потрібно?

  • AJAX requests
  • RESTful API
  • Real-time apps (chat, etc)
  • Working with external APIs
  • "Why my images is not loading, AAA!"
  • etc

Використані матеріали: