Skip to content

Commit cf70140

Browse files
committed
feat(cookie): support domain directive
1 parent 65703e3 commit cf70140

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/Config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,13 @@ export class Config {
160160
const directives = rawCookie.split(';').map(v => v.trim());
161161
const [name, value] = directives[0].split('=');
162162
const [, expires] = directives.find(d => d.split('=')[0]?.toLowerCase() === 'expires')?.split('=') || [null, null];
163+
const [, domain] = directives.find(d => d.split('=')[0]?.toLowerCase() === 'domain')?.split('=') || [null, this.webHost];
163164
cookies.push({
164165
name,
165166
value,
166-
url: `http${this.https ? 's' : ''}://${this.webHost}`,
167+
domain,
168+
url: `http${this.https ? 's' : ''}://${domain}`,
167169
path: '/',
168-
domain: this.webHost,
169170
httpOnly: true,
170171
secure: true,
171172
expirationDate: expires ? new Date(expires).getTime() / 1000 : undefined

src/Electron/html/preferences/preferences.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373

7474
.config-cookie textarea {
7575
height: 160px;
76+
word-break: break-all;
7677
}
7778

7879
textarea {
@@ -253,13 +254,13 @@
253254
<table>
254255
<tbody>
255256
<tr>
256-
<td><textarea id="configExperimentalCookie" class="form-control" placeholder="NAME1=VALUE1...; expires=2020-01-01T00:00:00Z&#10;NAME2=VALUE2...; expires=2020-10-01T00:00:00Z"></textarea></td>
257+
<td><textarea id="configExperimentalCookie" class="form-control" placeholder="NAME1=VALUE1...&#10;NAME2=VALUE2...; domain=foo.example.com; expires=2020-10-01T00:00:00Z"></textarea></td>
257258
</tr>
258259
</tbody>
259260
</table>
260261
<div>
261262
[Experimental Feature] This cookie is used by GitHub API request and GitHub browsing.
262-
Support configurable directives are only `Expires`. `Domain` is `Web Host` of the preferences. `Path` is `/`. `Secure` and `HttpOnly` are automatically enabled. `SameSite` is `None`.
263+
Support configurable directives are `Domain` and `Expires`. `Domain` is default `Web Host` of the preferences. `Path` is `/`. `Secure` and `HttpOnly` are automatically enabled. `SameSite` is `None`.
263264
</div>
264265
</div>
265266

src/GitHub/GitHubClient.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ export default class GitHubClient {
7373
}
7474
};
7575

76-
const cookies = Config.cookieDetails;
76+
const allCookies = Config.cookieDetails;
77+
const cookies = allCookies.filter(cookie => cookie.domain === this._host);
7778
if (cookies.length) {
78-
options.headers['Cookie'] = cookies.map(cookie => `${cookie.name}=${cookie.value}`).join(';');
79+
options.headers['Cookie'] = cookies.map(cookie => `${cookie.name}=${cookie.value}`).join(';');
7980
}
8081

8182
const httpModule = this._https ? https : http;

0 commit comments

Comments
 (0)