@@ -32,6 +32,9 @@ class Client
3232 /** @var string Some user agent string to identify our client */
3333 protected $ userAgent ;
3434
35+ /** @var array Custom headers */
36+ protected $ headers ;
37+
3538 /**
3639 * @var string|string[] Proxy configuration details.
3740 *
@@ -73,9 +76,14 @@ public function __construct(
7376 ? $ options ['version ' ]
7477 : '1.1 ' ;
7578
76- $ this ->userAgent = isset ($ options ['user-agent ' ])
77- ? $ options ['user-agent ' ]
78- : null ;
79+ $ this ->headers = isset ($ options ['headers ' ])
80+ ? $ options ['headers ' ]
81+ : ['Accept ' => 'application/xml ' ];
82+
83+ if (isset ($ options ['user-agent ' ])) {
84+ // legacy option
85+ $ this ->headers ['User-Agent ' ] = $ options ['user-agent ' ];
86+ }
7987
8088 if (isset ($ options ['credentials ' ])) {
8189 $ authentication = new BasicAuth ($ options ['credentials ' ][0 ], $ options ['credentials ' ][1 ]);
@@ -122,23 +130,6 @@ public function urlTo($cql, $start = 1, $count = 10, $extraParams = array())
122130 return $ this ->url . '? ' . http_build_query ($ qs );
123131 }
124132
125- /**
126- * Get HTTP client configuration options (authentication, proxy, headers)
127- *
128- * @return array
129- */
130- public function getHttpHeaders ()
131- {
132- $ headers = array (
133- 'Accept ' => 'application/xml '
134- );
135- if ($ this ->userAgent ) {
136- $ headers ['User-Agent ' ] = $ this ->userAgent ;
137- }
138-
139- return $ headers ;
140- }
141-
142133 /**
143134 * Perform a searchRetrieve request
144135 *
@@ -220,7 +211,7 @@ public function explain()
220211 */
221212 public function request ($ method , $ url )
222213 {
223- $ request = $ this ->messageFactory ->createRequest ($ method , $ url , $ this ->getHttpHeaders () );
214+ $ request = $ this ->messageFactory ->createRequest ($ method , $ url , $ this ->headers );
224215 $ response = $ this ->httpClient ->sendRequest ($ request );
225216
226217 return (string ) $ response ->getBody ();
0 commit comments