Skip to content

Account for server root #686

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 8 commits into from
Oct 8, 2019
Merged

Account for server root #686

merged 8 commits into from
Oct 8, 2019

Conversation

grouma
Copy link
Member

@grouma grouma commented Sep 26, 2019

No description provided.

@grouma grouma requested a review from alan-knight September 26, 2019 20:19
}
throw FormatException('Unsupported URI form', uri);
}

static String _dirForServerUri(String uri) => p.dirname(Uri.parse(uri).path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably needs a comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

var dir = p.dirname(path);
return DartUri._fromServerPath(p.normalize(p.join(dir, uri)));
return DartUri._fromServerPath(
p.normalize(p.join(_dirForServerUri(serverUri), uri)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the normalize here? If uri is coming from an http URI, and serverUri is the prefix path on the server, there should never be . or .., right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need to

@@ -98,7 +98,9 @@ class DartUri {
/// JS script. The dirname of that path should give us the missing prefix.
factory DartUri(String uri, [String serverUri]) {
// TODO(401): Remove serverUri after D24 is stable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this if we're using serverUri for something else.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -109,16 +111,22 @@ class DartUri {
}
// Work around short paths if we have been provided the context.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't apply any more.

@@ -109,16 +111,22 @@ class DartUri {
}
// Work around short paths if we have been provided the context.
if (serverUri != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think this should never happen now. This is the case where we get a raw path, not a URL with a scheme. I think that shouldn't be happening any more and this can be deleted

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not true. We still get URI's like main.dart that are not relative but have the corresponding context.

/// Construct from a package: URI
factory DartUri._fromPackageUri(String uri) {
return DartUri._('packages/${uri.substring("package:".length)}');
factory DartUri._fromPackageUri(String uri, String serverUri) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this apply to package: URIs, but not org-dartlang-app: URIs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed that we probably need to account for the serverUri to properly work with proxy servers. Updated the logic.

@grouma grouma requested a review from jakemac53 October 7, 2019 20:56
@@ -1,3 +1,6 @@
## 0.7.2
- Account for root directory path when using `package:` URIs with `DartUri`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: newline between for consistency

/// Construct from a package: URI
factory DartUri._fromPackageUri(String uri) {
return DartUri._('packages/${uri.substring("package:".length)}');
factory DartUri._fromPackageUri(String uri, String serverUri) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if serverUri is nullable I would make it an optional (named) arg (ditto below)

@@ -17,6 +17,12 @@ void main() {
expect(uri.serverPath, 'packages/path/path.dart');
});

test('parses package : paths with root', () {
var uri = DartUri(
'package:path/path.dart', 'http://localhost:8080/foo/bar/blah');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit concerned about how the hardcoded knowledge to walk up one directory here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. This may cause issues in the future, especially with proxy servers but this is what is expected today.

@grouma
Copy link
Member Author

grouma commented Oct 7, 2019

Discussed offline with @alan-knight. Made some changes to account for source maps URLs. This should be ready to review. PTAL.

@@ -169,7 +169,7 @@ class Debugger extends Domain {
}

Future<Null> _initialize() async {
sources = Sources(_assetHandler, _remoteDebugger, _logWriter);
sources = Sources(_assetHandler, _remoteDebugger, _logWriter, _root);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could have the root URI accessible somewhere instead of passing it around to different objects?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably a good clean up that should follow this PR.

@@ -77,7 +80,9 @@ class Sources {
for (var entry in lineEntry.entries) {
var index = entry.sourceUrlId;
if (index == null) continue;
var dartUri = DartUri(mapping.urls[index], script.url);
var path = p.join(
p.dirname(Uri.parse(script.url).path), mapping.urls[index]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like Uri.parse is expensive and it would be good if we could avoid doing it in this loop. But maybe file an optimization bug to cache it or otherwise optimize.

if (uri.startsWith('org-dartlang-app:')) return DartUri._fromAppUri(uri);
if (uri.startsWith('google3:')) return DartUri._fromGoogleUri(uri);
if (uri.startsWith('file:')) return DartUri._fromFileUri(uri);
if (uri.startsWith('/packages/')) return DartUri._fromServerPath(uri);
if (uri.startsWith('/packages/')) {
return DartUri._fromServerPath(uri, serverUri: serverUri);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be something like _fromRelativePath?

@@ -138,17 +146,22 @@ class DartUri {
factory DartUri._fromAppUri(String uri) {
// We ignore the first segment of the path, which is the root
// from which we're serving.
var path = Uri.parse(uri).pathSegments.skip(1).join('/').toString();
// TODO: To be able to convert to an org-dartlang-app: URI we will
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this comment is valid any more.

@@ -1,5 +1,5 @@
name: dwds
version: 0.7.1
version: 0.7.2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be -dev, or are you planning to publish right away?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intend to publish right away.

@grouma grouma merged commit 65fd8e1 into master Oct 8, 2019
@grouma grouma deleted the account-for-root branch October 8, 2019 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants