Http Request Life Cycle

前端 未结 4 1390
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 09:47

I have recently started my job as web application backend developer. I am bit stuck in understanding lifecycle of a Http request.

What I understood is

相关标签:
4条回答
  • 2020-12-07 10:05

    I think you are a bit wrong on your understanding of it.

    If you go to www.google.com (not using any forms, just wanting the site), this is what happens:

    1. First the browser needs to translate www.google.com to an IP address if it does not already know it. If it knows it, nothing happens at this point. If it does not know it, it contacts a DNS server to resolve the name.
    2. Then browser will open a TCP connection to the IP address of www.google.com and send a HTTP GET request over. In this example it will be
      GET / HTTP/1.1
      Host: www.google.com
    3. The server software will get this HTTP request. It will somehow generate a HTTP response and send that back trough the TCP connection. How the server does this is server software dependent. You can for example plug in application code in Apache, or just make Apache return a file from the filesystem. PHP is an application called by some software, which then generates the response sent to the browser. When the response is sent, in HTTP version 1.0 the connection is closed. HTTP 1.1 can have persistent connections though.
    4. When the browser gets the response, it typically renders it on screen. The HTTP request is now done. A click on "search" will send a new request to the server.

    GET, PUT, POST, DELETE and others are HTTP request methods. They have special meaning which you can see in the RFC.

    Cookies are commonly used to identify the same user across multiple HTTP requests, called sessions. Therefore these cookies are called session cookies

    You can debug the communication by using a network sniffer tool, for example Wireshark. Firefox has a third party plugin called Tamper Data that can change the request before they are sent to the server.

    The HTTP RFC is a good source of how it all works.

    Hope it helps.

    0 讨论(0)
  • 2020-12-07 10:10

    I found this resource very helpful in understanding the steps taken during the HTTP lifecycle : quite interesting actually though, wasn't aware of all the intermediate steps especially w/the cache checking when determining the IP Address of a URL.

    https://medium.com/@maneesha.wijesinghe1/what-happens-when-you-type-an-url-in-the-browser-and-press-enter-bb0aa2449c1a

    0 讨论(0)
  • 2020-12-07 10:12

    This is among the popular interview questions asked in various product based companies.

    HTTP Is a request-response protocol. For example, a user agent initiates a request to a server, typically by opening a TCP/IP connection to a particular port on a host (port 80 by default). The request itself comprises:

    a request line,

    a set of request headers, and an entity.

    An HTTP server listening on that port waits for the client to send a request message. Upon receiving the request, the server sends a response that comprises:

    a status line, a set of response headers, and an entity. The entity in the request or response can be thought of simply as the payload, which may be binary data. The other items are readable ASCII characters. When the response has been completed, either the browser or the server may terminate the TCP/IP connection, or the browser can send another request.

    0 讨论(0)
  • 2020-12-07 10:15

    while server receives the request from browser , the browser will be binded to some port on the host , ip address and port number of browser will be attached with the request that sends to server. server sends the responce to the ip address and port number

    0 讨论(0)
提交回复
热议问题