Skip to content

preserve trailing slash in uri path #107

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 9 commits into from
Sep 20, 2019
Merged

Conversation

artemredkin
Copy link
Collaborator

fixes #101 by preserving trailing slash in path return by the URL's path property

pathEndIndex = url.index(before: fragmentIndex)
}

return url[pathEndIndex] == "/"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Writing this against the absolute string seems to be making life quite hard: why not write it against self.path?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

self.path removes trailing slash

Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Can we step back for a minute: why is the current behaviour of URL problematic today?

@artemredkin
Copy link
Collaborator Author

If a server has a redirect like path -> path/, it is impossible to query it right now, we will be redirected to path/ on every request, but new request will still be path since we lose trailing slash.

@Lukasa
Copy link
Collaborator

Lukasa commented Sep 16, 2019

It's a shame that server is broken. ☹️

pathEndIndex = url.index(before: queryIndex)
} else if let fragmentIndex = url.suffix(from: url.firstIndex(of: "@") ?? url.startIndex).lastIndex(of: "#") {
pathEndIndex = url.index(before: fragmentIndex)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need the else branch? The minimum versions above were all released in 2015, making them 4 years old this year. Can we get away without it?

If the answer is really no, then can we also add a comment to this code branch to say that the code is not 100% correct, but is considered "good enough"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What do you mean by getting away without it? Adding supported platforms in Package.swift or a precondition? I would prefer not to have an alternative clause here as well...
@tomerd @tanner0101 @ianpartridge do you think we should limit the client to modern(er) platforms?

Copy link
Contributor

Choose a reason for hiding this comment

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

given our main use case is linux, restricting older non-linux platforms in Package.swift seems fine to me

@artemredkin
Copy link
Collaborator Author

@Lukasa fixed path check by using hasDirectoryPath instead of custom function

Package.swift Outdated
@@ -17,6 +17,7 @@ import PackageDescription

let package = Package(
name: "async-http-client",
platforms: [.macOS(.v10_11), .iOS(.v9), .tvOS(.v9), .watchOS(.v2)],
Copy link
Contributor

Choose a reason for hiding this comment

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

would this potentially confuse folks to think linux is not supported? maybe worth adding a comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added a comment!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to take this out. If we don't then every dependency needs to mirror this stanza.

Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

This LGTM

Copy link
Contributor

@weissi weissi left a comment

Choose a reason for hiding this comment

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

Sorry, the patch itself looks good but the platform restriction is probably too annoying.

Package.swift Outdated
@@ -17,6 +17,7 @@ import PackageDescription

let package = Package(
name: "async-http-client",
platforms: [.macOS(.v10_11), .iOS(.v9), .tvOS(.v9), .watchOS(.v2)],
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to take this out. If we don't then every dependency needs to mirror this stanza.

@artemredkin
Copy link
Collaborator Author

Agreed, reverted

Copy link
Contributor

@weissi weissi left a comment

Choose a reason for hiding this comment

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

lgtm

@artemredkin artemredkin merged commit 79cd718 into master Sep 20, 2019
@artemredkin artemredkin deleted the fix_trailing_slash_in_path branch September 20, 2019 14:32
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.

URL.uri removes trailing slash
4 participants