= Week 7 :author: Anna Whitney :v: GUtPQIDSwrA [t=0m0s] == Introduction * In Problem Set 4, you were challenged to find as many of the staff from the photos you recovered and take selfies with them. Ken, a photographer on the CS50 staff, got selfies with 24 staff members! Of actual students, the winners were Lance, with 15 photos, and Bonnie, with 14 photos but some containing multiple staff. Their sections will get a catered lunch. * *CS50 Lunch* on Friday, as usual; RSVP at http://cs50.harvard.edu/rsvp[cs50.harvard.edu/rsvp]. * *CS50 Seminars* are coming up! ** We're getting to the point of the semester where you should start to think about final project ideas. ** To this end, *pre-proposals* are soon due, in which you'll give your TF some ideas of what you're thinking about for a final project. ** Many students end up doing web projects, and since we're just now getting into web programming, don't worry if you don't yet know exactly how you'd implement your ideas (your TF will help you figure out what's feasible). ** CS50 Seminars give you a chance to explore tools and languages that aren't covered in the course itself, many of which might be of use on a final project. ** To see the list of seminars and register for any of them, go to http://cs50.harvard.edu/register[cs50.harvard.edu/register]. [t=4m11s] == HTTP * We left off last time with `GET`, the messages that are actually passed in the "envelope", so to speak, from computer to computer. ** A `GET` request looks something like this: + [source] ---- GET / HTTP/1.1 Host: www.google.com ... ---- *** This first line, `GET / HTTP/1.1`, means that we're requesting the main page of the website - the index, or default webpage - using the `HTTP/1.1` protocol. ** The server would respond with something like the following: + [source] ---- HTTP/1.1 200 OK Content-Type: text/html ... ---- *** We rarely see the status code `200 OK` as humans, because it means everything went fine, so the browser just shows us the webpage content. *** The most common content type is `text/html`, which we'll discuss in more detail now. [t=5m35s] == HTML * In the coming weeks, you can use any browser, but we recommend Chrome because it has lots of useful tools for developers. * In Chrome, you can right-click/Ctrl-click on a webpage and select "inspect element" from the menu that appears to open Chrome's Inspector, a debugging tool that lets you see under the hood of what's happening on a webpage. ** The Inspector has lots of features, but let's look at the *Network* tab. *** We press the recording button so it's red, and check "preserve log", so that everything that happens with the network will be recorded. Then we go to www.facebook.com: + image::network.png[alt="Network tab in Chrome inspector", width=800] *** When you visit facebook.com, you don't just send one `GET` request, you actually send many `GET` requests to load different parts of the page. *** The one we care about, though, is the request for the main Facebook page itself. Let's look at the actual header that Chrome sent to www.facebook.com: + image::request.png[alt="Request header sent to Facebook"] *** Although this isn't formatted quite the way we wrote it before, we can see that it's the same kind of request, with the path `/` again representing the main page of the website, and `HTTP/1.1` being the protocol used. *** The inspector also lets us look at the response headers that Facebook returned to our browser. *** These headers are composed of many key-value pairs (including the one we're familiar with from before: `content type: text/html`. * We can also right-click on the page and select "View Page Source" to see the HTML source of the webpage (this is not limited to Chrome - Firefox, IE, etc. all let you do this as well, although the menu options might look a little different). ** The HTML that we see this way is sent in the response from Facebook, coming after those headers we saw in the inspector. * Recall our simple webpage from last lecture, with this HTML source: + [source, html, numbered] ----
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam in tincidunt augue. Duis imperdiet, justo ac iaculis rhoncus, erat elit dignissim mi, eu interdum velit sapien nec risus. Praesent ullamcorper nibh at volutpat aliquam. Nam sed aliquam risus. Nulla rutrum nunc augue, in varius lacus commodo in. Ut tincidunt nisi a convallis consequat. Fusce sed pulvinar nulla.
Ut tempus rutrum arcu eget condimentum. Morbi elit ipsum, gravida faucibus sodales quis, varius at mi. Suspendisse id viverra lectus. Etiam dignissim interdum felis quis faucibus. Integer et vestibulum eros, non malesuada felis. Pellentesque porttitor eleifend laoreet. Duis sit amet pellentesque nisi. Aenean ligula mauris, volutpat sed luctus in, consectetur id turpis. Phasellus mattis dui ac metus blandit volutpat. Donec lorem arcu, sollicitudin in risus a, imperdiet condimentum augue. Ut at facilisis mauris. Curabitur sagittis augue in dictum gravida. Integer sed sem sed justo tempus ultrices eu non magna. Phasellus semper eros erat, a posuere nisi auctor et. Praesent dignissim orci aliquam laoreet scelerisque.
Mauris eget erat arcu. Maecenas ac ante vel ipsum bibendum varius. Nunc tristique nulla eget tincidunt molestie. Morbi sed mauris eu lectus vehicula iaculis ac id lacus. Etiam sit amet magna massa. In pulvinar sapien ac mi ultrices, quis consequat nisl hendrerit. Aliquam pharetra nec sem non vehicula. In et risus leo. Ut tristique ornare nisl et lacinia.
---- ** First, notice in lines 3-12, we have a comment, just as we had in our C code, but the format is a little different: comments are opened with `]`, instead of being opened with `/pass:[*]` and closed with `pass:[*]/`. ** We've introduced a new tag - ``, or paragraph. * If we restart our web server using today's `src7m` directory as the root directory, we'll be able to see this and all the other source files: + [source] ---- jharvard@ide50:~/workspace $ apache50 stop * Stopping web server apache2 * jharvard@ide50:~/workspace $ apache50 start src7m/ Setting Apache's document root to /home/ubuntu/workspace/src7m ... * Starting web server apache2 * Apache started successfully! Your site is now available at https://ide50-jharvard.c9.io jharvard@ide50:~/workspace $ ---- * Now when we go to `ide50-jharvard.c9.io`, we see a much longer list of files (the files in the `src7m` directory), among them `paragraphs.html`. * If we click on `paragraphs.html`, we can see that those `
` tags make line breaks between our pseudo-Latin paragraphs. ** If we replace the `
` tags with actual line breaks in our HTML source, the paragraphs all run together, because the browser just ignores extra whitespace - it only does exactly what it's told to do. * HTML syntax seems to consist of opening a tag (e.g., `
` or ``) and then closing those tags (e.g., ``, `
`). Start tags just consist of a tag name in angle brackets, and end tags are similar, but the tag name is prefixed with a forward slash. * What if we want more than just plain, 12pt Times New Roman text? We can make our text bigger and bold, as in http://cdn.cs50.net/2015/fall/lectures/7/m/src7m/headings.html[`headings.html`]: + [source, html] ----