WebFund 2015W Lecture 20
Video
The video from the lecture given on Monday, March 23, 2015 is now available.
Notes
Socat
You may be familiar with netcat which is somewhat of a swiss-army knife for dealing with network traffic. Socat is a better netcat. Socat allows you to view all of the traffic going back and forth over a TCP/IP connection.
To use socat, you must:
- Download and install it.
- Run your web server.
- Run socat as a mirror of the web server on a different port.
- Use a web browser to connect to the socat mirrored server.
Using socat, we can see all of the contents of requests and responses going back and forth between the client and the server.
'>' indicates the beginning of a request going to the server and shows the timestamp and how many bytes are going in. Similarly, '<' indicates the beginning of a response and has the same information.
HTTP traffic uses a text format that comes from Windows machines (which uses text output with a carriage return and a line feed) by default. With the text output in a Unix box we see '\r' for the carriage return and then an actual line break for the line feed.
If a request or response has a body then then will be an extra line break in between the head and the body.
Requests show their method at the start. This will usually be GET or POST. The responses will start with 'HTTP/1.1 followed' by the response code (eg 200 OK).
Assignment 5
We want to make queryNotes.js from storeNotes.js and fileStats.js.
fileStats.js takes in a command line argument. We can copy the code for fileStats.js into queryNotes.js. We would then create variables in which to store our expected command line arguments. The arguments can be parsed using familiar functions such as length()
, slice()
, indexOf()
. By checking if a string such as "-output=" exists in an argument, we can determine whether or not it corresponds to the output argument. Because this process must be done for each argument, we would want to make it into a function.
As you write code, you may find that some parts are redundant and can be factored out into functions. The important part of working on these assignments is not the solution but how to reason your way towards the solution.
Assignment 6
To complete Question 1, you could go to views/notes.jade and change p!= userNotes[i].content
to p = userNotes[i].content
. However, by doing this, it will no longer be possible to include links in the notes. Instead you must write your own function to sanitize the user input.
The parsing of the links can be handled by once again using the string functions that you are familiar with. Using split("[")
separates each segment containing a link. You can then split these segments at the "]" and use indexOf(" ")
to find the division between the URL and the label. Once you have broken up all of the pieces, you can reassemble them into one string with HTML links included.
To update the username, you will need to create a new route to handle the changeusername request. Inside this route, you must verify that the new username is not already in use and then make the update. You must both update the owner of the notes in the MongoDB collection using the collection's update()
method and you must update the session using req.session.username = ...
.
Assignment 9
For Assignment 9, you need to capture a transcript of the HTTP request going out and the response returned by the ajax-notes server. You need to explain what was sent and why for both the requests and the responses. You must do this for the following routes:
- GET /
- GET /javascripts/notes.js
- GET /getNotes
- POST /updateNote
- POST /newNote