purpose
I need to access a remote website through an Aurelia client. The solution should also work when packaging with Electron. The request is made through http.fetch (). This request must be executed several times with another client installed by the client.
Question
Various attempts to set cookies failed. This should be caused by some level of security within the client. Setting other headers with the same mechanisms works fine.
Without the cookie header specified in the request, the service returns the Set-Cookie header, which is processed correctly. Subsequent requests send the received cookie as expected until the Electron client is restarted. This behavior is intended for most clients, but it is not what I need for my specific problem.
Attempts to solve
As far as I could track it, the same problem occurs in at least three different environments:
- Electron
- Firefox / iceweasel
- Chrome (s
chromium --disable-web-security --user-data-dir)
I ran index.html directly as "file: //" as well as "http: //" via the Apache web server. The URL of an available service always points to the same service on the Internet.
Aurelia view-model (overview.js)
import {inject} from 'aurelia-framework';
import {HttpClient} from 'aurelia-fetch-client';
import 'fetch';
@inject(HttpClient)
export class Overview {
constructor(http) {
http.configure(config => {
config
.useStandardConfiguration()
.withBaseUrl(this.url)
.withDefaults({
credentials: 'include',
mode: 'cors',
headers: {
'X-fetch-default-header': 'fetch-default-header',
'Cookie': 'fetch-default-cookie=test'
}
});
});
this.http = http;
}
fetchRoot(nodeId){
var myHeaders = new Headers();
myHeaders.append('X-my-header', 'my-header');
myHeaders.append('Cookie', 'header-cookie=test');
this.http.fetch('',
{credentials: 'include', headers: {
cookie: 'fetch-inline-cookie=test',
'X-fetch-inline-header':'fetch-inline-header'
}
}).then(...);
this.http.fetch('',
{credentials: 'include', headers: myHeaders})
.then(...);
}
, ; path=/ key=value.
-
electron-cookies document.cookie. . :
- cookie
- require
- cookie, , ( , ).
fetchRoot(nodeId){} :
require('electron-cookies')
document.cookie = 'document-cookie=test';
(, electron-cookies - fetch-cookie), -, . - "cookie " cookie.