@@ -54,6 +54,7 @@ class Varnish
5454 private $ host ;
5555 private $ port ;
5656 private $ purgeInstruction ;
57+ private $ headers ;
5758
5859 private $ lastRequestError ;
5960 private $ lastRequestInfo ;
@@ -68,17 +69,24 @@ class Varnish
6869 * port for all instances)
6970 * @param string $purgeInstruction the purge instruction (purge in Varnish
7071 * 2, ban possible since Varnish 3)
72+ * @param array $headers Extra HTTP headers sent to the varnish servers on
73+ * each request.
7174 */
72- public function __construct ($ host , array $ ips , $ port , $ purgeInstruction = self ::PURGE_INSTRUCTION_PURGE )
75+ public function __construct ($ host , array $ ips , $ port , $ purgeInstruction = self ::PURGE_INSTRUCTION_PURGE , array $ headers = array () )
7376 {
74- $ url = parse_url ($ host );
75- $ this ->host = $ url ['host ' ];
76- if (isset ($ url ['port ' ])) {
77- $ this ->host .= ': ' . $ url ['port ' ];
77+ if (substr ($ host ,0 ,7 ) == "http:// " ) {
78+ $ url = parse_url ($ host );
79+ $ this ->host = $ url ['host ' ];
80+ if (isset ($ url ['port ' ])) {
81+ $ this ->host .= ': ' . $ url ['port ' ];
82+ }
83+ } else {
84+ $ this ->host = $ host ;
7885 }
7986 $ this ->ips = $ ips ;
8087 $ this ->port = $ port ;
8188 $ this ->purgeInstruction = $ purgeInstruction ;
89+ $ this ->headers = $ headers ;
8290 }
8391
8492 /**
@@ -200,6 +208,8 @@ protected function sendRequestToAllVarnishes($path, array $headers = array(), ar
200208 $ options [CURLOPT_HTTPHEADER ] = $ headers ;
201209 }
202210
211+ $ options [CURLOPT_HTTPHEADER ] = array_merge ($ this ->headers , $ options [CURLOPT_HTTPHEADER ]);
212+
203213 foreach ($ options as $ option => $ value ) {
204214 curl_setopt ($ curlHandler , (int ) $ option , $ value );
205215 }
0 commit comments