Commit b7a3a4da authored by Laurent's avatar Laurent

improve Orpheemedia compatibility

parent b20ee88b
......@@ -4,10 +4,6 @@ import * as http from 'http';
export class NSHTTPClient implements HTTPClient {
public request(options: any): Promise<http.HttpResponse> {
if (options.headers && options.headers['Cookie']) {
java.net.CookieHandler.setDefault(new java.net.CookieManager());
(new Cookies()).clearCookies();
}
console.dir([ 'on request', (new Cookies()).getCookies(), options]);
return http.request(options).then( (response) => {
console.dir([ 'on response', (new Cookies()).getCookies(), response.headers]);
......
......@@ -145,20 +145,25 @@ export class OrpheeMedia extends PortalAdapter {
protected _requestWorkaroundCookies(account: Account, options: any): Promise<http.HttpResponse> {
options.dontFollowRedirects = true;
let cookies_header = (new Cookies()).getCookies().map( (cookie) => {
return cookie.toString();
});
if (cookies_header.length > 0)
options.headers['Cookie'] = cookies_header;
let cookies = account.getCookies();
if (cookies.length > 0) {
options.headers['Cookie'] = cookies.map( (cookie) => {
return cookie.toString();
});
account.setCookies([]);
}
return this
.request(account, options)
.then( (response) => {
if (response.statusCode == 301 || response.statusCode == 302 || response.statusCode == 303) {
if (account.getCookies().length == 0)
account.setCookies(cookies);
if (response.statusCode == 301 || response.statusCode == 302 || response.statusCode == 303)
return this.request( account,
{ url: account.getUrl() });
}
return response;
});
}
......
......@@ -50,7 +50,7 @@
"lazy": "1.0.11",
"mocha": "^3.2.0",
"nativescript-css-loader": "~0.26.0",
"nativescript-dev-typescript": "~0.4.0",
"nativescript-dev-typescript": "^0.4.6",
"nativescript-dev-webpack": "^0.7.3",
"raw-loader": "~0.5.1",
"resolve-url-loader": "~2.1.0",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment