Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / Networking 3: DNS, HTTP and HTTPS

    URLs

    A full postal instruction: "By courier, to Sunrise Apartments, Gate 2, Flat 304, attention: the blue folder,

    Chapter 1 of 134 min read

    Start With the Problem#

    You type studybuddy.app/notes/priya into your browser and press Enter. Half a second later, Priya's notes appear.

    From the last two files, you know how to get bytes to 13.235.10.20:443 reliably. But:

    1. You typed a name, studybuddy.app. Where did the number 13.235.10.20 come from? Nobody told your laptop.

    2. The browser and the server are written by different companies, in different languages. What language do they use so the server understands "I want Priya's notes" and the browser understands the answer?

    3. The server answers thousands of people. How does it know it's you on your second click, not a stranger?

    4. Your packets pass through the café Wi-Fi, your ISP and a dozen routers. Why can't any of them read your password or change the page?

    These four answers are DNS, HTTP, cookies, and HTTPS. At the end of the file (Chapter 12) you'll trace the entire journey of that Enter key using everything from all five Foundations files.

    The Plain Picture#

    A full postal instruction: "By courier, to Sunrise Apartments, Gate 2, Flat 304, attention: the blue folder, page 3." It says how to deliver, which building, which entrance, which flat, what exactly, and where to look inside.

    The Real Name#

    A URL (Uniform Resource Locator) is the full address of something on the web.

      https://studybuddy.app:443/notes/priya?format=pdf&page=2#summary
      └─┬─┘   └─────┬──────┘└┬┘└────┬─────┘└───────┬────────┘└──┬───┘
      scheme       host     port   path          query        fragment
    PartMeaningExample
    schemewhich protocol to usehttps (or http, ws, ftp…)
    hostwhich machine, by name (Ch 2) or IP addressstudybuddy.app
    portwhich program (Networking 2: TCP, UDP and Ports Ch 1). Usually omitted: https means 443, http means 80443
    pathwhich thing on that server/notes/priya
    queryextra options, as key=value pairs joined with &format=pdf&page=2
    fragmenta position inside the page. Never sent to the server — only the browser uses it#summary

    Under the Hood — percent-encoding#

    URLs may only contain a limited set of ASCII characters. Anything else — spaces, & inside a value, Hindi text, emoji — is written as % plus the hex of each UTF-8 byte (How Computers Work Ch 4.3):

    Output
      space      →  %20
      &          →  %26        (so "&" inside a value isn't confused with the separator)
      é (C3 A9)  →  %C3%A9
      search "chai & code"   →   ?q=chai%20%26%20code

    This is percent-encoding (or URL encoding). Your browser does it automatically; in code you must use your language's URL-encoding function rather than gluing strings together.

    Check yourself

    4 questions
    1

    Name the six parts of a URL.

    Show answer

    Scheme, host, port, path, query, fragment.

    2

    Which part is never sent to the server?

    Show answer

    The fragment (after #).

    3

    What port does https://studybuddy.app/ use?

    Show answer

    443 (the default for https).

    4

    How is a space written inside a URL?

    Show answer

    %20 (in query strings, forms sometimes use +).