forked from Working-From-Home/webserv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubject.html
201 lines (178 loc) · 12.5 KB
/
subject.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Webserv - subject</title>
<style>
body{margin: 4 8vw;}
section{margin: 10vh 4vw;}
.text-center{text-align: center;}
.text-justify{text-align: justify;}
.text-emphase{font-style: oblique;}
.hr-invisible{visibility: hidden; height: 20px;}
table{border: solid 1px;}
td{border: solid 1px; padding: 5px;}
.tdl{width: 20%;}
.tdr{width: 80%;}
.box{padding: 20px; margin: 20px; text-align: center; font-style: oblique;}
.box-advice{background-color:rgb(255, 240, 153);}
.box-warning{background-color:rgb(255, 146, 134);}
.box-info{background-color:rgb(144, 212, 254);}
</style>
</head>
<body>
<h1 class="text-center">Webserv</h1>
<h2 class="text-center">This is when you finally understand why a URL starts with HTTP</h2>
<hr class="hr-invisible">
<hr>
<p class="text-emphase text-center">Summary: This project is here to make you write your HTTP server.
You will be able to test it with a real browser. HTTP is one of the most used protocols on the internet.
Knowing its arcane will be useful, even if you won’t be working on a website.</p>
<hr>
<section>
<h2>Introduction</h2>
<hr class="hr-invisible">
<p class="text-justify">The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed,
collaborative, hypermedia information systems. HTTP is the foundation of data communication for the
World Wide Web, where hypertext documents include hyperlinks to other resources that the user can easily
access, for example by a mouse click or by tapping the screen in a web browser. HTTP was developed to
facilitate hypertext and the World Wide Web.</p>
<p class="text-justify">The primary function of a web server is to store, process, and deliver web pages to
clients. The communication between client and server takes place using the Hypertext Transfer Protocol
(HTTP). Pages delivered are most frequently HTML documents, which may include images, style sheets, and
scripts in addition to the text content. </p>
<p class="text-justify">Multiple web servers may be used for a high-traffic website.</p>
<p class="text-justify">A user agent, commonly a web browser or web crawler, initiates communication by
requesting a specific resource using HTTP and the server responds with the content of that resource or
an error message if unable to do so. The resource is typically a real file on the server’s secondary
storage, but this is not necessarily the case and depends on how the webserver is implemented.</p>
<p class="text-justify">While the primary function is to serve content, full implementation of HTTP also includes ways of receiving
content from clients. This feature is used for submitting web forms, including the uploading of files.</p>
</section>
<section>
<h2>Mandatory part</h2>
<hr class="hr-invisible">
<table>
<tr>
<td class="tdl">Program name</td>
<td class="tdr">webserv</td>
</tr>
<tr>
<td>Turn in files</td>
<td></td>
</tr>
<tr>
<td>Makefile</td>
<td>Yes</td>
</tr>
<tr>
<td>Arguments</td>
<td></td>
</tr>
<tr>
<td>External functs.</td>
<td>Everything in C++ 98. htons, htonl, ntohs, ntohl, select, poll, epoll (epoll_create, epoll_ctl,
epoll_wait), kqueue (kqueue, kevent), socket, accept, listen, send, recv, bind, connect,
inet_addr, setsockopt, getsockname, fcntl.
</td>
</tr>
<tr>
<td>Libft authorized</td>
<td>No</td>
</tr>
<tr>
<td>Description</td>
<td>Write an HTTP server in C++ 98</td>
</tr>
</table>
<hr class="hr-invisible">
<ul class="text-justify">
<li>You can use every macro and define like FD_SET, FD_CLR, FD_ISSET, FD_ZERO (understanding what they do and how they do it is very useful.)</li>
<li>You must write an HTTP server in C++ 98.</li>
<li>If you need more C functions, you can use them but always prefer C++.</li>
<li>The C++ standard must be C++ 98. Your project must compile with it.</li>
<li>No external library, no Boost, etc...</li>
<li>Try to always use the most "C++" code possible (for example use <cstring> over <string.h>).</li>
<li>Your server must be compatible with the web browser of your choice.</li>
<li>We will consider that Nginx is HTTP 1.1 compliant and may be used to compare headers and answer behaviors.</li>
<li>In the subject and the scale we will mention poll but you can use equivalent like select, kqueue, epoll.</li>
<li>It must be non-blocking and use only 1 poll (or equivalent) for all the IO between the client and the server (listens includes).</li>
<li>poll (or equivalent) should check read and write at the same time.</li>
<li>Your server should never block and the client should be bounce properly if necessary.</li>
<li>You should never do a read operation or a write operation without going through poll (or equivalent).</li>
<li>Checking the value of errno is strictly forbidden after a read or a write operation.</li>
<li>A request to your server should never hang forever.</li>
<li>You server should have default error pages if none are provided.</li>
<li>Your program should not leak and should never crash, (even when out of memory if all the initialization is done).</li>
<li>You can’t use fork for something else than CGI (like php or python etc...)</li>
<li>You can’t execve another webserver...</li>
<li>Your program should have a config file in argument or use a default path.</li>
<li>You don’t need to use poll (or equivalent) before reading your config file.</li>
<li>You should be able to serve a fully static website.</li>
<li>Client should be able to upload files.</li>
<li>Your HTTP response status codes must be accurate.</li>
<li>You need at least GET, POST, and DELETE methods.</li>
<li>Stress tests your server it must stay available at all cost.</li>
<li>Your server can listen on multiple ports (See config file).</li>
<div class="box box-info">We’ve let you use fcntl because mac os X doesn’t implement write the
same way as other Unix OS.<br>You must use non-blocking FD to have a result similar to other OS.</div>
<div class="box box-warning">Because you are using non-blocking FD, you could use read/recv or write/send
functions without polling (or equivalent) and your server would be not blocking. But we don’t want that.
Again trying to read/recv or write/send in any FD without going through a poll (or equivalent) will give
you a mark equal to 0 and the end of the evaluation.</div>
<div class="box box-warning">You can only use fcntl as follow: fcntl(fd, F_SETFL, O_NONBLOCK); Any other flags are forbidden</div>
<li>In the config file we should be able to:
<div class="box box-advice"> You can inspire yourself from the "server" part of Nginx sconfiguration file</div>
<ul>
<li>choose the port and host of each "server"</li>
<li>setup the server_names or not</li>
<li> The first server for a host:port will be the default for this host:port (meaning it will answer to all request that doesn’t belong to an other server)</li>
<li>setup default error pages</li>
<li>limit client body size</li>
<li>setup routes with one or multiple of the following rules/configuration (routes
wont be using regexp):
<ul style="list-style-type: circle;">
<li>define a list of accepted HTTP Methods for the route</li>
<li>define an HTTP redirection.</li>
<li>define a directory or a file from where the file should be search (for example
if url /kapouet is rooted to /tmp/www, url /kapouet/pouic/toto/pouet is
/tmp/www/pouic/toto/pouet)</li>
<li>turn on or off directory listing</li>
<li>default file to answer if the request is a directory</li>
<li>execute CGI based on certain file extension (for example .php)</li>
<ul style="list-style-type: circle;">
<li>You wonder what a <a href="https://en.wikipedia.org/wiki/Common_Gateway_Interface">CGI</a> is ?</li>
<li>Because you won’t call the CGI directly use the full path as PATH_INFO</li>
<li>Just remembers that for chunked request, your server needs to unchunked it and the CGI will expect EOF as end of the body</li>
<li>Same things for the output of the CGI. if no content_length is returned from the CGI, EOF will mean the end of the returned data.</li>
<li>Your program should call the cgi with the file requested as first argument</li>
<li>the cgi should be run in the correct directory for relativ path file access</li>
<li>your server should work with one CGI (php-cgi, python...)</li>
</ul>
<li>make the route able to accept uploaded files and configure where it should
be saved</li>
</ul>
</li>
</ul>
</li>
</ul>
<div class="box box-info">If you’ve got a question about one behavior, you should compare your program behavior
with Nginx. For example, check how server_name works... We’ve shared with you a small tester it’s not mandatory
to pass it if everything works fine with your browser and tests but it can help you hunt some bugs.</div>
<div class="box box-warning">Please read the RFC and do some tests with telnet and Nginx before starting this project.
Even if you don’t have to implement all the RFC reading it will help you make the required features.</div>
<div class="box box-warning">The important thing is resilience. Your server should never die.</div>
<div class="box box-warning">Do not test with only one program, write your test with a language quick to write/use,
like python or golang, etc... you can even do your test in c or c++</div>
</section>
<section>
<h2>Bonus part</h2>
<hr class="hr-invisible">
<ul class="text-justify">
<li>If the Mandatory part is not perfect don’t even think about bonuses.</li>
<li>Support cookies and Session management (prepare quick examples).</li>
<li>Handle multiple CGI.</li>
</ul>
</section>
</body>
</html>