@@ -124,7 +124,7 @@ DocFilePath? parseRequestUri(Uri uri) {
124124 final relativeSegments =
125125 uri.pathSegments.skip (3 ).where ((s) => s.isNotEmpty).toList ();
126126 var pathSegments = relativeSegments;
127- if (relativeSegments.isEmpty || ! relativeSegments.last. contains ( '.' )) {
127+ if (_expandToIndexHtml (relativeSegments )) {
128128 pathSegments = [...relativeSegments, 'index.html' ];
129129 }
130130 final path = p.normalize (p.joinAll (pathSegments));
@@ -143,6 +143,32 @@ DocFilePath? parseRequestUri(Uri uri) {
143143 return DocFilePath (package, version, path);
144144}
145145
146+ const _nonExpandedExtensions = {
147+ '.html' ,
148+ '.json' ,
149+ '.gz' ,
150+ '.png' ,
151+ '.svg' ,
152+ };
153+ // NOTE: This is a best-effort detection on the segments.
154+ // Instead, we should rather check if the file (or the updated path)
155+ // is in the generated output, and base the decision on the file list.
156+ // However, with the current serving code it is costly, we need to refactor it.
157+ // TODO: Use blob index to decide how the relative path should be handled
158+ bool _expandToIndexHtml (List <String > segments) {
159+ if (segments.isEmpty) {
160+ return true ;
161+ }
162+ if (! segments.last.contains ('.' )) {
163+ return true ;
164+ }
165+ if (segments.first.contains ('static-assets' )) {
166+ return false ;
167+ }
168+ final ext = p.extension (segments.last);
169+ return ! _nonExpandedExtensions.contains (ext);
170+ }
171+
146172bool _isValidVersion (String version) {
147173 if (version.trim ().isEmpty) return false ;
148174 if (version == 'latest' ) return true ;
0 commit comments