Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 给 WebSocket 也加上 UA #304

Merged
merged 2 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/

- 留言板中单击网址链接现在能正常转跳到对应网页
- 修复网页版登录界面无法自动填充的问题
- 给 WebSocket 也加上 UA

## [0.9.1] - 2022-10-22

Expand Down
11 changes: 7 additions & 4 deletions lib/core/repository/graphql_api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ DocumentNode opi(DocumentNode document) => transform(
);

class SocketCustomLink extends Link {
SocketCustomLink(this.url, this.settingsController);
SocketCustomLink(this.url, this.settingsController, this.defaultHeaders);
final String url;
final Map<String, String> defaultHeaders;
_Connection? _connection;
final SettingsController settingsController;

Expand All @@ -134,7 +135,9 @@ class SocketCustomLink extends Link {
config: SocketClientConfig(
autoReconnect: true,
inactivityTimeout: const Duration(hours: 1),
headers: kIsWeb || cookies == null ? null : {'cookie': cookies},
headers: kIsWeb || cookies == null
? null
: {'cookie': cookies, ...defaultHeaders},
),
),
cookies: cookies,
Expand Down Expand Up @@ -233,8 +236,8 @@ class GraphQLApiClient {
defaultHeaders: headers,
);
}
final websocketLink =
SocketCustomLink(url.replaceFirst('http', 'ws'), settingsController);
final websocketLink = SocketCustomLink(
url.replaceFirst('http', 'ws'), settingsController, headers);

link = Link.split((request) => request.isSubscription, websocketLink, link);

Expand Down