Merge branch 'hugo2'

+ changed the appropriate getters for client
+ moved the functions to parse the http message
  (first line, headers, and body)
  outside client, in parsing_http_message.cpp
+ resolved some of the throw problems
This commit is contained in:
hugogogo
2022-08-09 15:54:40 +02:00
24 changed files with 205391 additions and 214 deletions

View File

@@ -1,4 +1,30 @@
## work together
#### TODO hugo
- `_is_cgi()` and `_fill_cgi_path()`
- two cgi tests :
? - a basic form with "name" and "something", that return a html page with that
? - for GET and POST
? - a script called by a file extension in URI
#### questions
- in client, fd is in privat, so accesible by getter, is it ok ?
- in client.cpp i fill the port, is there a default one in case it's not in the request ?
- timeout server but still works ?
- path contains double "//" from `Webserv::_get()` in response.cpp
- cgi path ? defined in config ? and root path ? :
- `Client.cpp : fill_script_path()`
- `cgi.cpp : is_cgi()`
- `cgi.cpp : set_env()`
- what if the uri contains a php file, and the config said php must be handled by cgi, but the path to this php in the uri is wrong ?
- is it ok ? `http://my_site.com/cgi-bin/php-cgi` (real path)
- is it ok ? `http://my_site.com/php-cgi` (reconstruct path ?)
- is it ok ? `http://my_site.com/something/php-cgi` (what about 'something' ?)
- is it ok ? `http://my_site.com/something/cgi-bin/php-cgi` (real path with 'something' before ? )
- I don't save the STDIN and STDOUT before dup2 in child process, is it wrong ?
- the response page is received long after the cgi-script is done, why ?
---
## man
@@ -77,6 +103,37 @@
## cgi rfc
[rfc 3875](https://www.rfc-editor.org/rfc/rfc3875)
#### output cgi script :
! TODO : change all the '\n' by '\r\n'
! TODO : there is at least one header field followed by '\r\n\r\n' :
- "Content-Type"
- "Location"
- "Status"
! TODO : there is no space between filed name and ":"
! TODO?: handle Location field, either :
- local : start with '/' --> rerun the request with new uri
- client : start with '<scheme>:' --> send back status code 302
-> TODO : there is no field duplicate (resolve conflicts)
-> TODO : if status field, change server status for this one
-> TODO : if no Location field && no Status field -> status code = 200
#### summary :
- the cgi-script will send back at least one header field followed by an empty line
- this header field will be one of three :
- "Content-Type"
- "Location"
- "Status"
- the cgi-script may send back more header fields
- the server must check and modify few things :
- there is no duplicate in headers fields (if there is, resolve conflict)
- there is no space between the field name and the ":"
- the newlines are of form "\r\n", and not "\n" only
- if the location field is not present, then if the status field is not present either, then the status code is 200
- the cgi-script can return a location field, of two types :
- local redirection : start with a "/", the server must answer as if this was the request uri
- client redirection : start with <name-of-cheme>":", the server must send back a status 302 with this uri to the client
- to pass the body-message to the cgi-script, we write it into the temporary fd on which the script read it's standard input
[3.1: server responsabilities](https://www.rfc-editor.org/rfc/rfc3875#section-3.1)
- The server [...] receives the request from the client
@@ -124,10 +181,12 @@
- local redirect response :
- it must return only a Location field
- it contains a local path URI and query string ('local-pathquery')
- the local path URI must start with a "/"
- the server must generate the response for this local-pathquery
- client redirect response :
- it must return only a Location field
- it contains an absolute URI path, to indicate the client that it should reprocess the request with this URI
- the absolute URI always start with the name of scheme followed by ":"
- the http server must generate a 302 'Found' message
- client redirect response with document
- it must return a Location field with an absolute URI path
@@ -172,16 +231,6 @@
[7 and 8: usefull informations about implementation and security](https://www.rfc-editor.org/rfc/rfc3875#section-7)
#### questions :
- le cgi-script doit renvoyer au moins un header suivit d'une ligne vide
- il peut dans certains cas envoyer d'autres headers
- le serveur doit verifier qu'il n'y a pas de doublons dans les headers
- le serveur doit verifier le formatage des headers (typiquement l'encodage, par exemple pour les newlines)
- ? comment on passe le body-message au script ? section 4.2
- ? on doit gerer l'authentification ?
- ? pourquoi on doit construire un script-cgi ? section 3.3
- ? si l'uri correspond au script-cgi, ca appel le script donc ? section 3.3
---
## cgi env variables