3 - Web Computing, Server Organization Flashcards
(21 cards)
How does HTTP connection work for client and server?
- Client opens connection, sends request to HTTP server
- Server sends response
- Server closes connection
What are the 3 parts of the HTTP request?
- message type (start line)
- header lines, followed by blank line
- body
What are the 3 parts of the message type?
- Request type (GET, POST, PUT, etc.)
- Absolute path
- HTTP version
What are some useful headers?
content-length - required if sending a body
Content-Type - what’s in body
User-Agent - browser type
Referer[sic] - where it came from
What are the status codes meanings? (Each 100 level)
100s - info
200s - success
300s - redirects
400s - client errors
500s - server error
What is a GET?
Basic web server sends files in response to a request
What is a POST?
Send data to server (login, forum post reply)
- Should make a NEW item
How to parse a GET?
Get the text
- fetch the file, make some headers, and reply
How to parse a POST?
something with JSONs - check notes
- encode content into key/value pairs
- put encoded data into body
- POST it
How do you create “state”? in HTTP?
Cookies!
- server sets cookies in browser
- browser sends those cookies with every response
What are some ways so that we don’t change pages all the time?
SPA - single page application
AJAX - async. Javascript and XML
- send a request “behind the scenes” update the HTML of the page (Domain Object Model)
How do we avoid keeping username/password in our cookie and remove them?
- we can set the “Set-Cookie” of the password to an expiry date in the past
For path /user/11, what would GET, POST, PUT, and DELETE do?
GET - fetch user info
POST - (doesnt make sense, we post a user to create one)
PUT - update user
DELETE - remove/disable user
What is a safe method?
GET, HEAD, OPTIONS, TRACE
- allows for optimization, usually read only and doesn’t change anything so we can cache this info
What does idempotent mean?
No matter how many times it’s done, the result is the same
- all safe methods are idempotent, but not vice versa
Think about adding a discussion post. Write the methods + data send to create these posts:
1) Go to UMLearn
2) Log into UMLearn
3) Move to 3010 via waffle menu
4) Add a discussion thread
5) update spelling mistake in thread
1) GET
2) POST
3) GET
4) POST
5) POST
6) POST -> why post for 6? Gives info of what you’re changing, no guarantee if its a new post or an update
Why aren’t Form POSTs not used as much anymore?
- we don’t want to see the browser completely refresh (complete changes take many resources
- replaced with XHR
Why shouldn’t we just set the full username and password as a cookie?
If your session is open, someone can just check the cookies
- serverside could see this but they shouldn’t
Why is API preferred?
- decouples frontend from backend
- can have multiple front-ends (app, web, watch, etc.)
- simple, lightweight, subdivide load
- better organization
What are the pros and cons of server pages (SSR)
pros:
- better SEO (scraper gets everything)
- doesn’t need JS to load everything
cons:
- lots of server load
- lots of time for client to receive data
Why is PHP good, and why is it bad?
Good:
- returns dynamic content precomputed by server
Bad:
- too many layers in one (scripts + front-end combined)
- adding plugins into wordpress is insecure (code you didn’t write is on your server, better trust it)