File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -161,11 +161,16 @@ private function sendRequests(array $requests)
161
161
$ allRequests = array ();
162
162
163
163
foreach ($ requests as $ request ) {
164
+ $ headers = $ request ->getHeaders ()->toArray ();
165
+ // Force to re-create Host header if empty, as Apache chokes on this. See #128 for discussion.
166
+ if (empty ($ headers ['Host ' ])) {
167
+ unset( $ headers ['Host ' ] );
168
+ }
164
169
foreach ($ this ->servers as $ server ) {
165
170
$ proxyRequest = $ this ->client ->createRequest (
166
171
$ request ->getMethod (),
167
172
$ server . $ request ->getResource (),
168
- $ request -> getHeaders ()
173
+ $ headers
169
174
);
170
175
$ allRequests [] = $ proxyRequest ;
171
176
}
Original file line number Diff line number Diff line change @@ -47,6 +47,23 @@ public function testBanEverything()
47
47
$ this ->assertEquals ('fos.lo ' , $ headers ->get ('Host ' ));
48
48
}
49
49
50
+ public function testBanEverythingNoBaseUrl ()
51
+ {
52
+ $ varnish = new Varnish (array ('http://127.0.0.1:123 ' ), null , $ this ->client );
53
+ $ varnish ->ban (array ())->flush ();
54
+
55
+ $ requests = $ this ->getRequests ();
56
+ $ this ->assertCount (1 , $ requests );
57
+ $ this ->assertEquals ('BAN ' , $ requests [0 ]->getMethod ());
58
+
59
+ $ headers = $ requests [0 ]->getHeaders ();
60
+ $ this ->assertEquals ('.* ' , $ headers ->get ('X-Host ' ));
61
+ $ this ->assertEquals ('.* ' , $ headers ->get ('X-Url ' ));
62
+ $ this ->assertEquals ('.* ' , $ headers ->get ('X-Content-Type ' ));
63
+ // Ensure host header matches the Varnish server one.
64
+ $ this ->assertEquals (array ('127.0.0.1:123 ' ), $ headers ->get ('Host ' )->toArray ());
65
+ }
66
+
50
67
public function testBanHeaders ()
51
68
{
52
69
$ varnish = new Varnish (array ('http://127.0.0.1:123 ' ), 'fos.lo ' , $ this ->client );
You can’t perform that action at this time.
0 commit comments