Skip to content

Commit

Permalink
feat(cookie): support domain directive
Browse files Browse the repository at this point in the history
  • Loading branch information
h13i32maru committed Jul 6, 2020
1 parent 65703e3 commit cf70140
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,13 @@ export class Config {
const directives = rawCookie.split(';').map(v => v.trim());
const [name, value] = directives[0].split('=');
const [, expires] = directives.find(d => d.split('=')[0]?.toLowerCase() === 'expires')?.split('=') || [null, null];
const [, domain] = directives.find(d => d.split('=')[0]?.toLowerCase() === 'domain')?.split('=') || [null, this.webHost];
cookies.push({
name,
value,
url: `http${this.https ? 's' : ''}://${this.webHost}`,
domain,
url: `http${this.https ? 's' : ''}://${domain}`,
path: '/',
domain: this.webHost,
httpOnly: true,
secure: true,
expirationDate: expires ? new Date(expires).getTime() / 1000 : undefined
Expand Down
5 changes: 3 additions & 2 deletions src/Electron/html/preferences/preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@

.config-cookie textarea {
height: 160px;
word-break: break-all;
}

textarea {
Expand Down Expand Up @@ -253,13 +254,13 @@
<table>
<tbody>
<tr>
<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>
<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>
</tr>
</tbody>
</table>
<div>
[Experimental Feature] This cookie is used by GitHub API request and GitHub browsing.
Support configurable directives are only `Expires`. `Domain` is `Web Host` of the preferences. `Path` is `/`. `Secure` and `HttpOnly` are automatically enabled. `SameSite` is `None`.
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`.
</div>
</div>

Expand Down
5 changes: 3 additions & 2 deletions src/GitHub/GitHubClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ export default class GitHubClient {
}
};

const cookies = Config.cookieDetails;
const allCookies = Config.cookieDetails;
const cookies = allCookies.filter(cookie => cookie.domain === this._host);
if (cookies.length) {
options.headers['Cookie'] = cookies.map(cookie => `${cookie.name}=${cookie.value}`).join(';');
options.headers['Cookie'] = cookies.map(cookie => `${cookie.name}=${cookie.value}`).join(';');
}

const httpModule = this._https ? https : http;
Expand Down

0 comments on commit cf70140

Please sign in to comment.