Skip to content

Commit a19912d

Browse files
authored
Merge pull request #1 from ilsanchez/leaflet073
Add request headers
2 parents 3e3d151 + c8b7884 commit a19912d

4 files changed

Lines changed: 576 additions & 354 deletions

File tree

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,40 @@ Name | Description
177177
`showWaiting()` | Start AJAX wait animation (spinner, etc.)
178178
`hideWaiting()` | Stop AJAX wait animation
179179

180+
181+
### Set Request Headers
182+
183+
You can set headers for each layer image request when use L.WMS.Source and L.WMS.Layer. This is usefull when you need to send Authorization headers to the server. Works though 2 new optional properties:
184+
185+
`headers` : `Array<{name: string, value: string}>` An array with static headers.
186+
187+
`getAjaxHeaders` : `() => Array<{name: string, value: string}>` A function used to provide dynamic headers, this function its called on each image request, so, avoid heavy calculations or I/O operations without memoization.
188+
189+
#### getAjaxHeaders:
190+
```javascript
191+
wms.source('http://url.png', {
192+
format: 'image/jpeg',
193+
transparent: false,
194+
opacity: 0.5,
195+
getAjaxHeaders: () => { // This will be called in all image request
196+
const auth = localStorage.get('authToken');
197+
return [{name: 'Authorization', value: auth ? `Bearer ${auth.token}` : ''}]
198+
}
199+
}).getLayer('overlay').addTo(this.map);
200+
```
201+
#### headers:
202+
```javascript
203+
const authToken = 'qrjnvf....';
204+
wms.source('http://url.png', {
205+
format: 'image/jpeg',
206+
transparent: false,
207+
opacity: 0.5,
208+
headers: [{ // This wont never change
209+
name: 'Authorization', value: `Bearer ${authToken}`
210+
}]
211+
}).getLayer('overlay').addTo(this.map);
212+
```
213+
180214
[Leaflet]: http://leafletjs.com
181215
[esri-leaflet]: https://github.com/Esri/esri-leaflet
182216
[L.TileLayer.WMS]: http://leafletjs.com/reference.html#tilelayer-wms

dist/leaflet.wms.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)