Skip to content
Permalink
Browse files
feat(cookie): support domain directive
  • Loading branch information
h13i32maru committed Jul 6, 2020
1 parent 65703e3 commit cf7014094e75908c6a6cd08135320f5638d2b89d
Showing 3 changed files with 9 additions and 6 deletions.
@@ -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
@@ -73,6 +73,7 @@

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

textarea {
@@ -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>

@@ -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;

0 comments on commit cf70140

Please sign in to comment.