Skip to content

Conversation

@cwaldren-ld
Copy link
Contributor

@cwaldren-ld cwaldren-ld commented May 23, 2023

This PR allows the SSE client to follow temporary/permanent redirects.

Going from http to https is not going to work because the initial client wouldn't have the ssl context, but this should cover the basic case.

I've also run this revision 164 times through contract tests and didn't observe a crash yet.

Follows redirects in limited situations. Cannot go from http to https or other way around.
@shortcut-integration
Copy link

This pull request has been linked to Shortcut Story #195297: Implement support for HTTP redirects in eventsource.

@cwaldren-ld cwaldren-ld changed the title Cw/sc 195297/sse redirects feat: follow redirects in SSE client May 23, 2023
Base automatically changed from cw/sc-195299/sse-retries to main May 23, 2023 00:34
}

return base;
}
Copy link
Contributor Author

@cwaldren-ld cwaldren-ld May 23, 2023

Choose a reason for hiding this comment

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

I see the AppendUrl function in common, but I'm not sure I need it here since these redirects are probably not human input.

I think it suffices to do:

  • If it has a scheme, it's absolute, so that's the new location
  • Otherwise, it's relative so try and resolve it against the base URL.

https://www.rfc-editor.org/rfc/rfc9110#field.location

Copy link
Member

Choose a reason for hiding this comment

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

So, it probably will not be a problem, but a relative URL is relative to the target URI, not the base URL. It is not uncommon for the redirect to have "../" and require dot resolution.

https://www.rfc-editor.org/rfc/rfc3986#section-5.2

"agent MUST process the redirection as if the value inherits the fragment component of the URI reference used to generate the target URI "

Copy link
Member

Choose a reason for hiding this comment

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

Not as easy to real-world test as by far the most common redirect is http to https.

Copy link
Member

Choose a reason for hiding this comment

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

(If you have a bunch of instances, and you change an endpoint name, and the endpoints are already segregated by a fragment, then you just use a relative fragment. Not just user input case. I would be comfortable for client SDKs I think. But for server SDKs I would want to solve this.)

@cwaldren-ld cwaldren-ld marked this pull request as ready for review May 23, 2023 16:58
@cwaldren-ld cwaldren-ld requested a review from kinyoklion May 23, 2023 17:05
@cwaldren-ld cwaldren-ld merged commit 54ce7f9 into main May 23, 2023
@cwaldren-ld cwaldren-ld deleted the cw/sc-195297/sse-redirects branch May 23, 2023 19:54
@github-actions github-actions bot mentioned this pull request May 23, 2023
This was referenced Oct 23, 2023
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