PDA

View Full Version : Get Header variables and set them



mathos
26 Aug 2009, 1:53 PM
Hello all,

I am desperately trying to first of all, get a parameter from the response header.

The header contains 'X-Transmission-Session-Id', so I have tried using response.getResponseHeader['X-Transmission-Session-Id']; inside Ext.Ajax, but I always get an undefined.

Now,I have a workaround using jQuery, but would naturally rather do it directly in Ext.

So, the next step, once I have the variable's value, I need to set it in every post/get I make to the RPC server. I have tried, setting the headers inside a proxy, without a proxy inside the JsonReader, etc, etc, but all it seems to accept is regular header settings like Content-Type, and not the custom one: 'X-Transmission-Session-Id'.

Am I missing something, is there a specific entry point in where I need to do this?

Kind regards, Mathos.

There is no php or other server side language available, otherwise I would have easily done this via that off course.

mathos
26 Aug 2009, 1:54 PM
Sorry, forgot to mention that I read in some post somewhere, that there was some sort of a fix inside the SVN repo. I do not have access to that, so I hope that I am simply doing something wrong :)

Jack9
26 Aug 2009, 3:04 PM
Whenever I can't do something in Ext, I immediately look to javascript itself. Headers are sent by the client browser normally, which is bad for you. XMLHttpRequest has a setRequestheader(), which is good for you.

Sorry for the MS link, but it's what came up in google first.

http://msdn.microsoft.com/en-us/library/ms536752%28VS.85%29.aspx

mathos
26 Aug 2009, 9:24 PM
Hi Jack, thanks for that.
For getting the part that is a fine workaround.
However, I need to set it, inside ExtJS, as I need to have the post/get results inside a JsonStore.

Is there anyway I can accomplish that?

Regards, Mathos.

hendricd
27 Aug 2009, 4:00 AM
@mathos -- You can pass any headers in the store's load method Config:



store.load({
params: {},
headers: {
'X-Transmission-Session-Id' : sessionId
}
});

mathos
27 Aug 2009, 2:07 PM
Thanks Hendricd,

I have some luck finally, also using some help from other posts.

So now the final part is to get that sessionId from the initial post using an Ext.Ajax, so I do not need jQuery anymore.

Here is the code that works, including using json to send, instead of params !:



// Data Proxy
var transmissionProxy = new Ext.data.HttpProxy(
{
method: 'POST',
url: 'http://10.0.0.2:9091/transmission/rpc',
jsonData: '{"arguments":{"fields":["id","name","totalSize","errorString","trackers","isPrivate","seedRatioLimit","seedRatioMode"]},"method":"torrent-get"}',
headers: { 'Content-Type': 'application/json;charset=utf-8',
'X-Transmission-Session-Id': 'hgnzCkcCp64jZyS3DYjTxTaZz8ehGgIdsNa6MRIb8n1dPxyT' }
});

// Data Store
var torrentStore = new Ext.data.JsonStore(
{
id: 'id',
root: 'rows',
proxy: transmissionProxy,
//url: url,
autoLoad: true,

/*baseParams:
{
method: 'torrent-get',
fields: 'name'
},*/
fields: [
{
id: 'id'
},{
ser: 'serial'
}
]
});


Kind regards, Mathos.