Closed QCHR1581 closed 1 month ago
Did some tests:
listen directive behaves strange when on same line:
server {listen 127.0.0.1:8080;
gives 127.0.0.1:80 (standard values)
Other directives (tested with server_name) seem to work?
if one server block is added, any additional wrong blocks are ignored
server {listen 0.0.0.0:8080;} //<-- closed early
server_name scifi.com; // from here on everything is ignored (should error)
root /workspaces/webserv/scifi;
location / {
autoindex on;
}
server {listen 127.0.0.1:8080;} // this new server block is also ignored
if brace is on next line, and directive on same line (combination of the two fixes) it does not like:
server //<-- brace on next line
{listen 0.0.0.0:8080;} // error: Invalid server directive
Implemented Fixes
Created implementation for handling following cases concerning curly brackets:
For details see #58.
Approach for curly brackets on the next line & whitespaces between server and bracket
Both cases are now getting handled by extracting the directive of the current line (in this case
server
) and checking if the the directive equalsserver
Approach for a directive on the same line as a bracket
To handle this case, a rewrite of the read server config line loop and the read location config line loop was necessary. Furthermore the way how to process a remaining line also had to be changed.
Read server config line loop
Read location config line loop
Process remaining line
Reason to change the read loops
The reason to change the approach in this way is to stop the read loops if the current line equals
}
, even though a directive is on the same line as the}
.When a line like this appears:
The directive is read, and the remaining line is processed. This results in the line being reduced to only a
}
character. Then the m_currentLine is updated, causing the loop to terminate.Closes #58
Tests
There are tests for all of the mentioned cases to make sure that each of them is handled correctly