@@ -114,7 +114,6 @@ def validate_outputs(self, outputs, error=None, modifiers=None):
114114 "attributes" : {
115115 "component" : "http" ,
116116 "http.method" : "GET" ,
117- "http.server_name" : "127.0.0.1" ,
118117 "http.scheme" : "http" ,
119118 "host.port" : 80 ,
120119 "http.host" : "127.0.0.1" ,
@@ -174,7 +173,6 @@ def test_behavior_with_scope_server_as_none(self):
174173 """Test that middleware is ok when server is none in scope."""
175174 def update_expected_server (expected ):
176175 expected [3 ]['attributes' ].update ({
177- 'http.server_name' : '0.0.0.0' ,
178176 'http.host' : '0.0.0.0' ,
179177 'host.port' : 80 ,
180178 'http.url' : 'http://0.0.0.0/'
@@ -187,6 +185,21 @@ def update_expected_server(expected):
187185 outputs = self .get_all_output ()
188186 self .validate_outputs (outputs , modifiers = [update_expected_server ])
189187
188+ def test_host_header (self ):
189+ """Test that middleware is ok when server is none in scope."""
190+ hostname = b"server_name_1"
191+ def update_expected_server (expected ):
192+ expected [3 ]['attributes' ].update ({
193+ 'http.server_name' : hostname .decode ('utf8' )
194+ })
195+ return expected
196+ self .scope ["headers" ].append ([b'host' , hostname ])
197+ app = otel_asgi .OpenTelemetryMiddleware (simple_asgi )
198+ self .seed_app (app )
199+ self .send_default_request ()
200+ outputs = self .get_all_output ()
201+ self .validate_outputs (outputs , modifiers = [update_expected_server ])
202+
190203
191204
192205class TestAsgiAttributes (unittest .TestCase ):
@@ -209,7 +222,6 @@ def test_request_attributes(self):
209222 "http.url" : "http://127.0.0.1/?foo=bar" ,
210223 "host.port" : 80 ,
211224 "http.scheme" : "http" ,
212- "http.server_name" : "127.0.0.1" ,
213225 "http.flavor" : "1.0" ,
214226 "net.peer.ip" : "127.0.0.1" ,
215227 "net.peer.port" : 32767 ,
0 commit comments