@@ -32,6 +32,9 @@ class Client
32
32
/** @var string Some user agent string to identify our client */
33
33
protected $ userAgent ;
34
34
35
+ /** @var array Custom headers */
36
+ protected $ headers ;
37
+
35
38
/**
36
39
* @var string|string[] Proxy configuration details.
37
40
*
@@ -73,9 +76,14 @@ public function __construct(
73
76
? $ options ['version ' ]
74
77
: '1.1 ' ;
75
78
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
+ }
79
87
80
88
if (isset ($ options ['credentials ' ])) {
81
89
$ authentication = new BasicAuth ($ options ['credentials ' ][0 ], $ options ['credentials ' ][1 ]);
@@ -122,23 +130,6 @@ public function urlTo($cql, $start = 1, $count = 10, $extraParams = array())
122
130
return $ this ->url . '? ' . http_build_query ($ qs );
123
131
}
124
132
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
-
142
133
/**
143
134
* Perform a searchRetrieve request
144
135
*
@@ -220,7 +211,7 @@ public function explain()
220
211
*/
221
212
public function request ($ method , $ url )
222
213
{
223
- $ request = $ this ->messageFactory ->createRequest ($ method , $ url , $ this ->getHttpHeaders () );
214
+ $ request = $ this ->messageFactory ->createRequest ($ method , $ url , $ this ->headers );
224
215
$ response = $ this ->httpClient ->sendRequest ($ request );
225
216
226
217
return (string ) $ response ->getBody ();
0 commit comments