Skip to content

Commit 55941b0

Browse files
authored
[dwds] DRY up MD5/etag logic (#2625)
One path used utf8, the other used codeUnits Better to do it once, correctly
1 parent ab7c4d6 commit 55941b0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

dwds/lib/src/handlers/injector.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ class DwdsInjector {
8787
// The requestedUri contains the hostname and port which guarantees
8888
// uniqueness.
8989
final requestedUri = request.requestedUri;
90-
final appId = base64.encode(
91-
md5.convert(utf8.encode('$requestedUri')).bytes,
92-
);
90+
final appId = _base64Md5('$requestedUri');
9391
var scheme = request.requestedUri.scheme;
9492
if (!globalToolConfiguration.debugSettings.useSseForInjectedClient) {
9593
// Switch http->ws and https->wss.
@@ -128,7 +126,7 @@ class DwdsInjector {
128126
'Injected debugging metadata for '
129127
'entrypoint at $requestedUri',
130128
);
131-
etag = base64.encode(md5.convert(body.codeUnits).bytes);
129+
etag = _base64Md5(body);
132130
newHeaders[HttpHeaders.etagHeader] = etag;
133131
}
134132
if (ifNoneMatch == etag) {
@@ -237,3 +235,10 @@ Future<String> _injectedClientSnippet(
237235

238236
return injectedBody;
239237
}
238+
239+
final _utf8FusedConverter = utf8.encoder.fuse(md5);
240+
241+
String _base64Md5(String input) {
242+
final bytes = _utf8FusedConverter.convert(input).bytes;
243+
return base64.encode(bytes);
244+
}

0 commit comments

Comments
 (0)