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

Can't call service that requires trailing slash #1503

Open
gatesn opened this issue Dec 7, 2021 · 2 comments
Open

Can't call service that requires trailing slash #1503

gatesn opened this issue Dec 7, 2021 · 2 comments

Comments

@gatesn
Copy link

gatesn commented Dec 7, 2021

What happened?

The readme suggests I can use Dialogue to call non-Conjure servers, but I've run into a bit of trouble: https://github.com/palantir/dialogue/tree/96ae91db83aa9ccdc5939a934ab84b33691ec240#dialogue-annotations-processor-generated-client-bindings

Internally, Dialogue passes paths around as a list of segments, throwing away information about whether or not a trailing slash exists:

This results in the server issuing a 301 redirect to the path ending in a slash. However, the Apache client is configured to ignore redirects:

I thought about implementing a channel to handle the 301 and resubmit the request with the slash, but I think the Channel API is too high-level since it also talks in terms of UrlBuilders, and therefore path segments.

It also seems there's a lot of logic wrapped up in ApacheHttpClientChannels.ClientBuilder that I don't (or can't, due to being package-private) want to replicate to enable redirects on the Apache client.

What did you want to happen?

I think I agree with the principle of no redirects, so it perhaps makes sense to support trailing slashes rather than 301s in this case?

My proposal might be to have HttpPath capture whether or not there exists a trailing slash (special-casing trailing slashes, vs any other duplicate slashes in the path). PathTemplate can then have a method to append a slash, templated in to the generated classes by the EndpointsEnumGenerator.

Unfortunately, I imagine this could be a breaking change for anyone relying on the current path template parsing behaviour...

@carterkozak
Copy link
Contributor

We should be able to support explicit trailing slashes with the annotation processor by providing a final empty-string path segment (much like an empty path parameter). There's some ambiguity when the endpoint is the root of the api path, because we tend to assume path=/ means no trailing slash, so that would be a little bit special and I'm not sure we should support that path directly. I imagine we may have some normalization that occurs in our parser which prevents this from occurring out of the box.

Supporting this sort of redirect can be dangerous in less obvious ways, for example a non-retryable binary upload may be burned on the first request attempt, while other types of requests would work just fine in this case, so you're correct that we'd prefer not to support that.

@gatesn
Copy link
Author

gatesn commented Jul 13, 2022

Can now workaround the trailing slashes using the annotation processor API, but it would still be useful to say "follow redirects", perhaps that could be a parameter to com.palantir.dialogue.annotations.Request ?

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

No branches or pull requests

2 participants