u413-284-si / webserv

This project is about setting up a http web server, providing a static website.
MIT License
0 stars 0 forks source link

Read server directive first and then directives in location #54

Closed QCHR1581 closed 1 week ago

QCHR1581 commented 2 months ago

The values of the directives directly within a server should be read first. After those are stored in the class ConfigFile, the values of directives within the location will be read.

Why this is necessary

server {
  location / {
    index index.html;
  }
  location /images/ {
    root /home;
    index index.html;
  }
  root /var;
}

In this case the first block should receive the server block directive, and the second should retain its custom root.

With line by line reading you would set it to default in the first and custom in second. Later you find it the server directive so you would revisit the location blocks.

But then you need to know if it has default value and if so overwrite. You also need to know if the default wasn't set explicitly, in which case you also dont overwrite.

If you read in the whole file you can easily make two passthroughs: iterate over the server block, identify all server scope directives. Iterate another time, this time check for location blocks. - Gabriel