首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
辅导data留学生程序、讲解program语言编程、Java编程辅导 讲解R语言程序|辅导R语言程序
项目预算:
开发周期:
发布时间:
要求地区:
MinCGI
You are tasked with building a web server that will handle multiple connections and execute
applications that are compliant with a subset of the Common Gateway Interface specification. The
Common Gateway Interface is used by web-servers to allow compatible programs to be executed
on the server, to process HTTP requests and compute a HTTP response. The web-server uses
standard input and output as well as environment variables for communication between the CGI
program and the itself. HTTP requests that are received by the web-server can be passed to a CGI
program via shell environment variables and standard input.
What is a web-server?
A web-server is a common application which serves web pages and commonly executes queries
as part of a request. A web-server interacts with clients through the HTTP protocol, a client will
send a HTTP Request, the web server will process it and send a HTTP response to the client. A
client is typically a web-browser such as Mozilla Firefox, Google Chrome, Microsoft Edge and
Apple Safari.
What is CGI?
Common Gateway Interface is a specification for a web-server to allow programs and scripts to
process requests that are given to it via standard input and environment variables. A CGI Program
will process the data and output a HTTP request via standard output.
HTTP Request
The following are request headers that are sent by a web browser. You will need to retrieve each
one. Each header is optional, content-type and content-length are
Accept - Content type of the request
Host - Domain of the server
User-Agent - The browser used by the client
Accept-Encoding - Encoding of the stream
Remote-Address - The IP Address of the client
Content-Type - The content type of the request body
Content-Length - Size of the request body in bytes
Query Strings is data after a ? symbol that is placed at the end of the request URL. A query string
will list variables in a string, each variable and their value pair will be separated by a & character.
Below is an example of a query string where the variables are name and age .
A HTTP request will specify the method, resource name and the HTTP protocol version on the first
line, followed by the request headers on each line afterwards. The request body is separated by
an empty new line after the last request header.
http://localhost:9001/hello?name=James&age=25
Example - GET Request 1
URL Example:
Protocol Example:
Example - GET Request 2
URL Example:
Protocol Example, web browser can provide additional headers:
Example - GET Request 3
URL Example:
Protocol Example:
Example - GET Request 4 (Query String Example)
URL Example:
Protocol Example:
http://127.0.0.1/
GET / HTTP/1.1
http://127.0.0.1/
GET / HTTP/1.1
Host: 127.0.0.1
http://127.0.0.1/js/helper.js
GET /js/helper.js HTTP/1.1
Accept: application/javascript
http://127.0.0.1/cgibin/posts?id=20
GET /cgibin/posts?id=20 HTTP/1.1
Host: 127.0.0.1
CGI Environment Variables
The following are common gateway variables which you will retrieve from request headers,
configuration file and execution environment. You will need to set these variables (if found in the
above sources) as a shell environment variable for the CGI Program.
HTTP_ACCEPT - Content type of the request, this value is retrieved from the HTTP request,
omitted if it is not part of the request
HTTP_HOST - Domain of the server, this value is retrieved from the HTTP request, omitted if
it is not part of the request
HTTP_USER_AGENT - The browser used by the client, this value is retrieved from the HTTP
request, omitted if it is not part of the request
HTTP_ACCEPT_ENCODING - Encoding of the stream, this value is retrieved from the HTTP
request, omitted if it is not part of the request
REMOTE_ADDRESS - The IP Address of the client, this value is retrieved from the connection
REMOTE_PORT - The port the client is connected on, this value is retrieved from the
connection
REQUEST_METHOD - The HTTP method, this value is retrieved from the HTTP request
REQUEST_URI - The resource requested by the client, this value is retrieved from the HTTP
request
SERVER_ADDR - The server address, this value is retrieved from server socket.
SERVER_PORT - The port the server is listening on, this value is retrieved from configuration
or server socket
CONTENT_TYPE - Content type of the information supplied by the body of a POST request,
omitted if it is not part of the request (POST request only)
CONTENT_LENGTH - Length of the request body, this value is retrieved from HTTP request,
omitted if it is not part of the request (POST request only)
QUERY_STRING - Information after a '?' at the end of the request URL. Will map variables to a
value in a single string, separated by '&' characters, omitted if it is not part of the request
You will need to pass the HTTP request body via standard input to the CGI Program. The request
body is important when form data is sent to the server.
Content-Type Mapping and Processing
Your web-server will need to map each file extension to the following content-type. When a http
requests a file of one of the following type, the content-type should be mapped to the following.
Any file ending with .txt , is mapped to text/plain
Any file ending with .html , is mapped to text/html
Any file ending with .js , is mapped to application/javascript
Any file ending with .css , is mapped to text/css
Any file ending with .png , is mapped to image/png
Any file ending with .jpg or .jpeg , is mapped to image/jpeg
Any file ending with .xml , is mapped to text/xml
HTTP Response
Your server only needs to handle GET HTTP and be able to return statuses for both files and CGI
programs. Your data must return the HTTP Protocol Version, Status Code and Status Message,
However, your web-server does not need to handle all of the different return statuses and these
will typically be defined by the web application itself.
For files that will not involve the command gateway interface, your web-server should do the
following.
If the file exists, it should return 200 OK and the content of the file. Make sure the contenttype
is set to what the extension maps to.
If the file does not exist, it should return 404 File not found , your server should send the
following HTML to the client.
Command gateway interface programs may encounter a problem during execution. The web
server should check the exit code of the application executed to detect that the command
executed and if the program returned data. If the command is not found or the program crashes
(exits with non-zero status), the web-server must respond with 500 Internal Server Error .
Special case: HTTP request on / , your server must retrieve a file named index.html at the root
of your staticfiles path.
HTTP Responses follow the following form
Variation for Status Code
CGI programs are able to specify the status code of the HTTP response as well as the message. If
the status code is absent on the first line of the response, your web-server should assume it
returns status code 200 with the message OK ( HTTP/1.1 200 OK ).
However, a CGI Program can specify the status code on the first line in this format.
In the event, the CGI program specifies this format on the first line, your web-server should fix the
HTTP response from CGI Program to format the first line by extracting the Status Code and the
Message and using them as part of the standard response.
404 Not Found
404 Not Found
Status-Code:
Example - Status 200, 1
HTTP Request
Example Response
Example - Status 200, 2
HTTP Request
HTTP Response
Example - Status 404, 1
HTTP Request
HTTP Response
GET / HTTP/1.1
HTTP/1.1 200 OK
Content-Type: text/html
Hello World!
GET /goodmorning.html HTTP/1.1
Accept: text/html
HTTP/1.1 200 OK
Content-Type: text/html
Good Morning!
GET /missingfile.html HTTP/1.1
HTTP/1.1 404 Not Found
Content-Type: text/html
404 Not Found
404 Not Found
Example - Status 200, 3, Image Type
HTTP Request
HTTP Response
Configuration File
You will read in a configuration file that will specify the static file directory and the cgi-bin
directory for your application. As with most web servers, your configuration will need to know the
port it is listening on.
The configuration file is a simple text file where each property is assigned to a value. When
reading the configuration file, you will need to retrieve each of the following properties from the
file and their value.
staticfiles - string, path to the files that will be simply served by the web-server.
cgibin - string, path to the CGI executables.
port - integer, the port the server listens on.
exec - string, executable path or command that will be executed on inbound cgibin requests.
This is a simple file where each line will have a key and a value separated by = .
The configuration file will be supplied as a command line argument for your server. For example,
your server will be invoked like so python webserv.py config.cfg .
In the event the configuration is not passed to the program, the program should output Missing
Configuration Argument .
If the path does not exist for the configuration file, the program should output Unable To Load
Configuration File . If the configuration file does not contain the four fields specified, the
program should output Missing Field From Configuration File .
Static Files
Your web server must retrieve all static files within a specified directory, this will also need to
retrieve any file that exists within a folder in that directory. However, your web-server should
forbid accessing files that exist in the parent directory of staticfiles.
GET /image.png HTTP/1.1
Accept: image/png,*/*
HTTP/1.1 200 OK
Content-Type: image/png
staticfiles=./root
cgibin=./bin
port=8070
exec=/bin/python
Parse HTTP/1.1 - Supplementary
Your web server will need to parse HTTP/1.1, you can refer to HTTP/1.1 RFC located here: https://t
ools.ietf.org/html/rfc7230. This is a stateless protocol that will simply acknowledge a request and
serve a file or in the case of cgibin files, parse the request, set the environment variables, launch
the CGI Program and send the request body via standard input to the program.
Specifically, you can refer to section 2 which outlines the HTTP URI scheme.
You may refer to the following examples of HTTP requests that will be sent to a client. You can
also test using your web browser by visiting your web server. You do not need to implement the
full HTTP/1.1 specification such as cache-validation as this can be difficult to get right.
Common Gateway Interface - Supplementary
Common gateway interface for version 1.1 is outlined here: https://tools.ietf.org/html/rfc3875.
Common gateway interface is a web standard protocol for web-servers to communicate to
executables and pass data to and from to these executables. Specifically, cgibin has its own
executable folder and the configuration format outlines the executable to be used with the files
within this directory.
The CGI Request is outlined in section 4 of the Common Gateway Interface RFC. The interface is
quite simple and just involves using the standard input and standard output file descriptors as
described in previous sections.
Extension
Try to implement one of the following extensions for your web server.
Handling POST requests from browsers and accepting form data.
Compressed packets to send back to the browser. Use the gzip module in python.
Your own extension, please check with a staff member about the eligibility of your extension.
It must be relevant to the problem and demonstrate a similar amount of complexity to the
extensions above.
You must provide test cases to demonstrate how it works and provide a README with your
submission outlining your extension.
CGI-Web for everyone
Refer to below as a task list for your web server. Prioritise the configuration, accepting
connections and static files before getting CGI Programs working.
Load a configuration file
Accept connections
Parse HTTP/1.1 data
Set up all environment variables
Fork and execute the CGI Program or retrieve static file
If CGI Program, pipe the data from the application back to the web-server
After implementing your server, try to improve performance and make all requests
asynchronous by forking each connection that is accepted.
Marking - Due 22/11/20 11:59 PM
The assessment weight is 20%, it is divided into 3 parts. Your submission will be assessed on the
following.
Automatic Test Cases (10%) - Automatic test cases your submission will be submitted to. This
will check that your application is compliant with the MinCGI specification.
Test Cases (4%) - Your submission must include your own set of test cases, these test cases
should be shell scripts that make a request to your web-server using curl and check the
final result against an expected file using diff .
Manual Marking (4%) - Your submission will be marked against a style, please make sure you
have a consistent style and conform. You can supply a README file with your submission
that describes your programming. If you do not supply a README that discusses your
programming, we will assess your source against the PEP-8 specification.
Extension (2%) - After implementing your CGI web-server, extend your it by implementing
one of the extensions above.
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
urba6006代写、java/c++编程语...
2024-12-26
代做program、代写python编程语...
2024-12-26
代写dts207tc、sql编程语言代做
2024-12-25
cs209a代做、java程序设计代写
2024-12-25
cs305程序代做、代写python程序...
2024-12-25
代写csc1001、代做python设计程...
2024-12-24
代写practice test preparatio...
2024-12-24
代写bre2031 – environmental...
2024-12-24
代写ece5550: applied kalman ...
2024-12-24
代做conmgnt 7049 – measurem...
2024-12-24
代写ece3700j introduction to...
2024-12-24
代做adad9311 designing the e...
2024-12-24
代做comp5618 - applied cyber...
2024-12-24
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!