Skip to content
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

fix/session-delegate #160

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

lhunath
Copy link
Contributor

@lhunath lhunath commented Jun 7, 2022

Fixed f84740e

SwiftLinkPreview destroys and recreates the URLSession, causing the user to lose control over the session he gave to SwiftLinkPreview (ie. his delegate will stop working & his session invalidation will be ignored).

LeonardoCardoso and others added 7 commits September 23, 2021 19:10
…RegexLimit

update Regex.swift. Upgrade regex limit length
When an image URL is not an absolute URL (ie. protocol://url), we want
to put the base URL in front of it, if it is known.

BUT, if neither the base URL ends in / or the image URL start with /,
the current formatImageURL mashes them together without a slash, leading
to something like https://base.comimages/image.jpg
SwiftLinkPreview's public API is one that asks the user for a
URLSession. This API gives the user the freedom to fully configure their
own URLSession (such as by setting a custom delegate) as well as giving
them control over invalidating the session through
finishTasksAndInvalidate() or invalidateAndCancel().

Internally, however, at some point SwiftLinkPreview re-creates the
URLSession in order to set its own delegate. This is bad form because it
belies the public API, resulting in behaviour that violates its own
contract: now the URLSession that was given to it no longer honours the
user's URLSessionDelegate and it ignores invalidation calls.

Either SwiftLinkPreview should have a public API that *only* asks for a
URLSessionConfiguration and then make its own URLSessions off that, or
it should ask for a URLSession and then honour that contract without
internally changing the actual session used.

This solution does the latter.

Note that SwiftLinkPreview's replacement delegate appears to be purely
to ensure redirects are happening, but this is already the automatic
behaviour for background-style URLSessions (which are probably the type
you want to use with SwiftLinkPreview anyway). If the user wants
redirects without a background-style URLSession, he should handle that
in his own URLSession. Note that the behaviour of URLSession is
100% out-of-scope for SwiftLinkPreview, especially when SwiftLinkPreview
is asking the user for what session to use.
@lhunath
Copy link
Contributor Author

lhunath commented Jun 7, 2022

this PR is based on #159. The only commit in this PR that is relevant is f84740e

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.

None yet

3 participants