Skip to content

[dwds] DRY up MD5/etag logic #2625

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

Merged
merged 3 commits into from
Jun 5, 2025
Merged
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
13 changes: 9 additions & 4 deletions dwds/lib/src/handlers/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ class DwdsInjector {
// The requestedUri contains the hostname and port which guarantees
// uniqueness.
final requestedUri = request.requestedUri;
final appId = base64.encode(
md5.convert(utf8.encode('$requestedUri')).bytes,
);
final appId = _base64Md5('$requestedUri');
var scheme = request.requestedUri.scheme;
if (!globalToolConfiguration.debugSettings.useSseForInjectedClient) {
// Switch http->ws and https->wss.
Expand Down Expand Up @@ -128,7 +126,7 @@ class DwdsInjector {
'Injected debugging metadata for '
'entrypoint at $requestedUri',
);
etag = base64.encode(md5.convert(body.codeUnits).bytes);
etag = _base64Md5(body);
newHeaders[HttpHeaders.etagHeader] = etag;
}
if (ifNoneMatch == etag) {
Expand Down Expand Up @@ -237,3 +235,10 @@ Future<String> _injectedClientSnippet(

return injectedBody;
}

final _utf8FusedConverter = utf8.encoder.fuse(md5);

String _base64Md5(String input) {
final bytes = _utf8FusedConverter.convert(input).bytes;
return base64.encode(bytes);
}
Loading