Skip to content

preserve trailing slash in uri path#107

Merged
artemredkin merged 9 commits into
masterfrom
fix_trailing_slash_in_path
Sep 20, 2019
Merged

preserve trailing slash in uri path#107
artemredkin merged 9 commits into
masterfrom
fix_trailing_slash_in_path

Conversation

@artemredkin

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@Lukasa Lukasa left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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

Lukasa commented Sep 16, 2019

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator Author

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

Comment thread Package.swift Outdated

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@Lukasa Lukasa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This LGTM

@weissi weissi left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread Package.swift Outdated

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

Copy link
Copy Markdown
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
Copy Markdown
Collaborator Author

Agreed, reverted

@weissi weissi left a comment

Copy link
Copy Markdown
Contributor

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