Is it possible to provide an authnetication token to HttpDatasetReader?

I’m looking for something like

reader= vtkXMLImageDataReader.newInstance({ fetchGzip: true });
this.reader.setUrl(url,headers: { Authorization: `Token ${token}` }.then( () => loadDataCallBack());

Is there an example or syntax somewhere?

Thanks

You can pass a second object containing headers to setUrl:

reader.setUrl(url, {
  headers: {
    Authorization: '...'
  }
})

Thanks, if I use something like


reader= vtkXMLImageDataReader.newInstance({ fetchGzip: true });
reader.onModified(readerModified);

reader.setUrl(url,{headers: { Authorization: `Token ${token}` }}
		          ).then( () => reader.loadData());

readerModified = (obj) => {

		if(obj.shouldUpdate()==true){
			obj.update();

			if(obj.getOutputData()){
				var dta = obj.getOutputData();
                                ....
                                Do stuff
                                .....
			}
		}		
	}




Then I get an authentication error.

Looking at the network traffic in a bit more detail suggests it makes 2 requests to the url. The first authenticates and returns the correct response as it includes the header, the second does not. Looking at the call stacks the first uses setUrl → loadData → fetchData → fetchBinary whilst the second uses eval → loadData → fetchData → fetchBinary

Not sure why it is making two requests as the first request seems to return the data in the file. It could and it could be that my implementation is flawed. Has this been seen before?

I guess you should just skip the () => reader.loadData() part.

That solves the issue of it loading twice. Now it calls readerModified just the once, but there is no loaded data (i.e. obj.getOutputData()=null ) when it does so.

You still have to wait for the completion of the promise.

I see now. Thanks. Got it working by adding a call to reader.modified() on return from the promise

reader= vtkXMLImageDataReader.newInstance({ fetchGzip: true });
reader.onModified(readerModified);
reader.setUrl(url,{headers: { Authorization: `Token ${token}` }}
		          ).then( () => reader.modified());

readerModified = (obj) => {

		if(obj.shouldUpdate()==true){
			obj.update();

			if(obj.getOutputData()){
				var dta = obj.getOutputData();
                                ....
                                Do stuff
                                .....
			}
		}		
	}