corvvs / webserv

simple and light http-server like NGINX in C++
4 stars 2 forks source link

[bug]server_nameの指定ができていない #254

Closed ryo-manba closed 2 years ago

ryo-manba commented 2 years ago
http {
    server {
        listen 8080;
        server_name "hoge";
        return 200 "hoge";
    }
    server {
        listen 8080;
        server_name "fuga";
        return 200 "fuga";
    }
}
curl localhost:8080 -H "Host: hoge" -v
curl localhost:8080 -H "Host: fuga" -v
ryo-manba commented 2 years ago

Hostにhogeを指定した場合、 server_name hoge が使われる。

> curl localhost:8080 -H "Host: hoge" -v
*   Trying ::1:8080...
* connect to ::1 port 8080 failed: Connection refused
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host:hoge
> User-Agent: curl/7.77.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Length: 4
< Date: Thu, 01 Sep 2022 18:06:19 GMT
< 
* Connection #0 to host localhost left intact
hoge%  
ryo-manba commented 2 years ago

Hostにfugaを指定した場合、server_name fuga が使われる。

> curl localhost:8080 -H "Host: fuga" -v
*   Trying ::1:8080...
* connect to ::1 port 8080 failed: Connection refused
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host:fuga
> User-Agent: curl/7.77.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Length: 4
< Date: Thu, 01 Sep 2022 18:06:30 GMT
< 
* Connection #0 to host localhost left intact
fuga%