Practical 1: HTTP Web Proxy Server Programming Practical

Practical 1: HTTP Web Proxy Server Programming Practical
Due Mar 29 by 17:00 Points 24
Adapted from Kurose & Ross - Computer Networking: a top-down approach featuring the Internet
CBOK categories: Abstraction, Design, Data & Information, Networking, Programming
In this practical, you will learn how web proxy servers work and one of their basic functionalities - caching.
Task
Your task is to develop a small web proxy server which is able to cache web pages.
It is a very simple proxy server which only understands simple HTTP/1.1 GET-requests but is able to handle all
kinds of objects - not just HTML pages, but also images.
Introduc!on
In this practical, you will learn how web proxy servers work and one of their basic functionalities, caching
(https://en.wikipedia.org/wiki/Cache_(computing)) . Generally, when a client (e.g. your browser) makes a web request
the following occurs:
1. The client sends a request to the web server
2. The web server then processes the request
3. The web server sends back a response message to the requesting client
And let‘s say that the entire transaction takes 500 ms.
In order to improve the performance, we create a proxy server between the client and the web server. The proxy
server will act as a middle-man for the web transactions. Requesting a web request will now occur in the following
steps:
1. The client sends a request to the proxy server
2. Skip to step 7 If the proxy server has cached the response
3. Forward the request to the web server
4. The web server processes the request
5. The web server sends a response back to the proxy server
6. The proxy server caches the response
7. The proxy server returns the cached response to the client
On the first request, the transaction may be a fraction longer than the previous example. However, subsequent
requests will be significantly faster due to reduced network latency and server load (sometimes less than 10 ms).
The mechanism for caching can be as simple as storing a copy of a resource on the proxy servers file system.
Steps for approaching the prac!cal
Step 1
Understand the HTTP/1.1 requests/responses of the proxy. Your proxy MUST be able to handle GET requests from
a client. Your proxy may handle other request types (such as POST) but this is not required.
You need to know the following:
1. What HTTP request will the browser send to the proxy?
2. What will HTTP response look like?
3. In what ways will the response look different if it comes from the proxy than if it comes from the origin server
(i.e. the server where the original page is stored?). You will not be able to test this yet, but what do you think
would happen?
Step 2
Understand the socket connections:
1. How will the client know to talk to the proxy?
2. What host and port number will the proxy be on?
3. The proxy may need to connect to the origin server (if the web object is not in the cache), what host and port
number will the proxy connect to?
4. Where will the proxy get the web object information?
Step 3: Checkpoint
Make sure you have the answers to steps 1 & 2 before you go any further.
You can‘t code it if you don‘t know what should happen.
Ask questions on the discussions forum if you are unsure above the above.
Step 4: Python Code
Now that you know what should be happening, have a look at the code here.
Look at the interactions you identified in steps 1 & 2 and see where they would occur in the code.
Review the python code presented in the sockets lecture. You‘ll find details of the socket calls in the Python Socket
library documentation https://docs.python.org/2.7/library/socket.html
(https://docs.python.org/2.7/library/socket.html)
(https://docs.python.org/2.7/library/socket.html) You won‘t just be able to copy the lecture code, but it shows
you the key steps; creating sockets, connecting sockets, sending data on sockets and receiving data on sockets.
Your task is to make the correct socket calls and supply the correct arguments for those calls.
You will only need to fill in the code between the comment lines.
The comments above the comments lines give you hints to the code to insert.
Step 5: Differences in Python and C
If you are new to python, look at the code structure. Most of the code is given to you with your focus just on adding
the networking code. A couple of things that are different in Python than in the C derived languages:
1. Python uses whitespace to indicate code blocks and end of lines. Note there are no brackets or braces { }
around code blocks and no semi-colons ; at the end of lines. The indentation isn‘t just important for readability
in Python, it affects how your code runs. Make sure you indent code blocks correctly.
2. Python has a tuple data structure. So functions can return more than one value, or more precisely return one
tuple with multiple values, but the syntax allows the parenthesis to be left off. Tuples appear in the lecture slides
in the line:
(serverName, serverPort) is a tuple of two values that are passed as the argument to the connect() function.
The accept() call returns a tuple of two values, the first value is the new socket and the second is the address
information. This is the same as:
The use of the ( ) around the tuple is optional.
Step 6
Start with getting the proxy working when a cached file is requested. Where it will return the response itself and
does not have to contact the origin server
Step 7
# ~~~~ INSERT CODE ~~~~
...
# ~~~~ END CODE INSERT ~~~~
1
2
3
1 clientSocket.connect((serverName,serverPort))
1 connectionSocket, addr= serverSocket.accept()
1 (connectionSocket, addr)= serverSocket.accept()
Once that is working, add the code to handle the case where the file is not cached by the proxy and the proxy must
request it from the origin server.
Step 8
In both steps 6 & 7, make use of both telnet utility and a browser to test your proxy server. You can also use
Wireshark to capture what is being sent/received from the origin server.
Running your proxy in the labs and Websub
The labs and test machines are running Python 2.7. Make sure that your submission is compatible with Python 2
and does not use Python 3 features that are not backward compatible with Python 2.7.
The University proxy will intercept any attempt to connect to a host outside of the University and require
authentication (which is outside the scope of this practical), thus, your proxy will not be able to connect to origin
servers outside of the University when running on computers inside the University. When testing inside the
University, use URLs within the University infrastructure. This should not affect you when running your proxy
outside the University.
Running the Proxy Server
Download the template file and save it as Proxy.py .
Run the following command in terminal to run the proxy server
You can change localhost to listen on another IP address for requests, localhost is the address for your machine.
You can change 8888 as the port to listen to.
When you run the proxy server for the first time, it will loop forever failing to connect to a server. That‘s ok for now.
Press Ctrl+C to terminal the program.
When you are ready to test your proxy server, open a Web browser and navigate to
http://localhost:8888/https://ecms.adelaide.edu.au
Note that when typing the proxy into the browser request in this way, the browser may only display the main page
and may fail to download associated files such as images and style sheets. This is due to a difference in URI
requirements when sending requests to a proxy vs sending to an origin Web server (we‘ll look at this in the
tutorials).
Configuring your Browser (op!onal)
You can also directly configure your web browser to use your proxy if you want without using the URI. This depends
on your browser.
In Internet Explorer, you can set the proxy in Tools > Internet Options > Connections tab > LAN Settings.
In Netscape (and derived browsers such as Mozilla), you can set the proxy in Tools > Options > Advanced tab >
Network tab > Connection Settings.
In both cases, you need to give the address of the proxy and the port number that you set when you ran the proxy
1 $ python Proxy.py localhost 8888
Prac 1: Web Proxy
server. You should be able to run the proxy and the browser on the same computer without any problem. With this
approach, to get a web page using the proxy server, you simply provide the URL of the page you want.
For example, running https://ecms.adelaide.edu.au would be the same as running
http://localhost:8888/https://ecms.adelaide.edu.au
Set up like this, the browser should successfully load both the main web page and all associated files due to
reasons we‘ll discuss in tutorials.
Tes!ng your code
When it comes time to test your code, cUrl is a useful tool to use.
Let‘s have a look at these two tests:
Obtained remote file
The above command requests https://ecms.adelaide.edu.au https://ecms.adelaide.edu.au (https://ecms.adelaide.edu.au) (https://ecms.adelaide.edu.au) via the Web
proxy. -I prints out response headers and -s removes additional output and head -n 1 extracts the first line
from the cUrl command.
The result is the first line in the response from the proxy. This response should match if you were talking directly to
the origin server, like so
Handle page that does not exist
The response for a path that doesn‘t exist shows the above status code. Your proxy to work correctly will also need
to handle this case too.
Submission
Your proxy server will be inside the Proxy.py file only.
Your work will need to be submitted to Websub (https://cs.adelaide.edu.au/services/websubmission/) with the
assignment path /2019/s1/cna/webproxy
The Web submission system will perform a static analysis of your code. Your code will be run by one of the
teachers.
$ curl -sI localhost:8080/https://ecms.adelaide.edu.au | head -n 1
HTTP/1.1 200 OK
1
2
$ curl -sI https://ecms.adelaide.edu.au | head -n 1
HTTP/1.1 200 OK
1
2
$ curl -sI localhost:8080/https://ecms.adelaide.edu.au/fakefile.html | head -n 1
HTTP/1.1 404 Not Found
1
2
Total Points: 24.0
Criteria Ratings Pts
0.0 pts
10.0 pts
2.0 pts
2.0 pts
2.0 pts
2.0 pts
1.0 pts
1.0 pts
4.0 pts
Proxy server started 0.0 pts
Full Marks
0.0 pts
No Marks
Connected to Proxy server 10.0 pts
Full Marks
0.0 pts
No Marks
Obtained remote homepage 2.0 pts
Full Marks
0.0 pts
No Marks
Obtained remote file 2.0 pts
Full Marks
0.0 pts
No Marks
Handle page that does not exist 2.0 pts
Full Marks
0.0 pts
No Marks
Cache requested webpages 2.0 pts
Full Marks
0.0 pts
No Marks
Read from a cached file 1.0 pts
Full Marks
0.0 pts
No Marks
Redownloaded the file from server after file was removed 1.0 pts
Full Marks
0.0 pts
No Marks
Handles internal server error 4.0 pts
Full Marks
0.0 pts
No Marks

因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com

微信:codinghelp

原文地址:https://www.cnblogs.com/whltay/p/10548233.html

时间: 2024-09-30 19:20:41

Practical 1: HTTP Web Proxy Server Programming Practical的相关文章

Office Web Apps Server 打造手机移动办公系统

前几天Ms专家来推销他们的产品,我倒学会怎么搞个移动办公系统让网络上设备不需要安装Office软件查看Office文档. 大概需要: 主机一台,系统: Windows Server 2008 R2 Service Pack 1 或者Windows Server 2012 本文使用Windows Server 2012 软件需要: Office Web Apps Server :下载地址:http://download.microsoft.com/download/E/7/F/E7F39294-9

javascript使用web proxy来实现ajax cross-domain通信

在现代浏览器中,都强加了对javacript代码的访问限制,比如一个页面的js无法向非同源的url实现ajax请求,获得数据.在这时,是浏览器端会报错: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status co

JavaScript: Use a Web Proxy for Cross-Domain XMLHttpRequest Calls

The XMLHttpRequest object (also known as the XMLHTTP object in Internet Explorer) is at the core of today's most exciting AJAX web applications. But actually writing client web applications that use this object can be tricky given restrictions impose

利用tinyproxy在Linux上搭建HTTP Proxy Server

之所以需要用到HTTP Proxy Server并不是为了要翻墙,而是为了让没有公网IP地址的内网主机通过有公网IP地址的外网主机访问Internet.举个例子,阿里云ECS在购买时可以不购买公网IP地址,但这种没有公网IP地址的ECS云主机(实例)是没有访问Internet的能力的,也就是说无法在这台实例上下载文件,这在部署应用如部署MySQL时可能遇到无法完成安装问题.解决的办法有两种,一种是在另一台具有公网访问能力的ECS实例上搭建VPN服务,另一种是在另一台具有公网访问能力的ECS实例上

Java Drp项目实战——Web应用server

引言 Web应用server如今非常多人都在用,但是究竟什么是Web应用server呢,它与Webserver有什么关系,它与应用server又是什么关系,它是他们两种中的当中一种,还是简单的两种server的组合呢? 要搞明确这个问题,我们得先知道什么是Webserver以及什么是应用server,如今我们就来看下这两个server. Webserver Webserver(WebServer)能够解析(handles)HTTP协议.当Webserver接收到一个HTTP请求(request)

Skype For Business 2015实战系列13:安装Office Web App Server

Skype For Business 2015实战系列13:安装Office Web App Server 今天要为大家介绍的是Office Web App Server(以下简称OWA),OWA在Skype For Business中的主要作用就是在用户使用Skype客户端开会的时候可以共享PPT,从而可以更好的进行演讲! 安装OWA: 我们登陆到OWA,服务器,坚持服务器的基本信息如下: 安装OWA所需的Windows组建: 以管理员身份打开Powershell,运行如下命令: Add-Wi

FTP Proxy Server

本文将在Linux环境下实现一个简单的FTP代理服务器,主要内容涉及FTP主动/被动模式和简单的Socket编程. 1. 主动模式和被动模式 FTP有两种模式,即主动模式(Active Mode)和被动模式(Passive Mode),主要区别在谁在监听数据端口. 1.1 主动模式 FTP服务器在开启后一直在监听21号端口等待客户端通过任意端口进行连接,客户端通过任意端口port1连接服务器21号端口成功后,服务器通过该命令套接字发送各种FTP命令(CD.DIR.QUIT...).当要发送的命令

设置Proxy Server和SQL Server实现互联网上的数据库安全

◆首先,我们需要了解一下SQL Server在WinSock上定义协议的步骤: 1. 在"启动"菜单上,指向"程序/Microsoft Proxy Server",然后点击"Microsoft Management Console". 2. 展开"Internet Information Service",再展开运行Proxy Server的服务器. 3. 右击WinSock Proxy service, 再点击属性. 4.

4.Office Web APPS Server

OWAS服务器准备部分: 1.修改服务器名称,IP地址,加入域,并用域管理员账户登录 2.安装Windows组件. Add-WindowsFeature Web-Server,Web-Mgmt-Tools,Web-Mgmt-Console,Web-WebServer,Web-Common-Http,Web-Default-Doc,Web-Static-Content,Web-Performance,Web-Stat-Compression,Web-Dyn-Compression,Web-Secu