CSC361 Tutorial 3

CSC361 Tutorial 3
Marking Breakdown Test Scenarios P1 Demo Design Check

Marking Breakdown
¡ñ 200ok 1pt
¡ñ Persistent connection 1pt
¡ñ Correct return large file 1pt
¡ñ 404 not found
¡ñ 400 bad request
¡ñ Multiple clients
¡ñ Timeout
¡ñ Back-to-back request 1pt
¡ñ Server output format 1pt

Test Scenario 1
¡ñ 200 ok test
¡ð Small file request
¡ð Test whether 200 ok responded correctly 1pt
¡ð Test the format of server output 1pt
¡ð Large file request, if return content correctly 1pt

Test Scenario 2
¡ñ 404 test
¡ð Non-existing file request
¡ð Test whether 404 responded correctly 1pt

Test Scenario 3
¡ñ 400 bad request test
¡ð Test whether 400 bad request responded correctly 2pt

Test Scenario 4
¡ñ Multi-client test
¡ð On h1 send a persistent connection, and on r send another 1pt

Test Scenario 5
¡ñ Persistent and timeout test
¡ð On h1 send a persistent connection, then send another request without connection header 1pt
¡ð On h1 send a persistent connection, then wait for timeout 1pt

Test Scenario 6
¡ñ Back-to-back test
¡ð On h1 send requests from a text file 1pt

¡ñ To test your server whether this feature is enabled, you can create a text file (call test.txt) as follows:
GET /notfound HTTP/1.0 Connection:keep-alive
GET /hello.html HTTP/1.0 Connection:keep-alive
get /hello.html http/1.0 Connection:keep-alive
GET /notfound HTTP/1.0 Connection:keep-alive
¡ñ nc ip_address port < test.txt

Demo 1: Line by line Requests
use nc connect to sws, and input requests and headers line by line

Demo 2: Back-to-back requests
Send multiple requests at the same time:

Common Problems
1. Serveroutputlogformat
2. Failtorespondtobadrequestimmediately(donotneedtowaitforthenew
3. Cannotsupportlinebylineandback-to-backrequestssimultaneously
4. HTTPHeaders
5. Closetheconnectionwhen
a. No keep-alive headers in the request
b. Bad requests
c. timeout
6. Extranewlinereturnedaftertheendofthefilecontent,whichisnotcorrect

server_address = (‘localhost’, 80)
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.setblocking(0)
server.bind(server_address)
You should not hardcode the ip address and port number

if not is_match:
response_messages[s] += “HTTP/1.0 400 Bad Request”
response_messages[s] += “HTTP/1.0 200 OK”
Be sure to consider the case of 404 not found Do not forget to add ¡°\r\n¡± for the response line

# keep-alive is false, close the connection if (connection_alive == None):
print(“closing connection…”)
close_socket(sock, inputs, outputs,message_queues)
Remember to remove any unnecessary prints before submission.