zalando/tailor

Handle Follow Redirect on Fragments

trickpeeraze opened this issue ยท 8 comments

As the title, how's about we make an option on fragment tag to whether follow redirection (3xx) or not.

Now, fragment request handler only handles on http-error case but not http-redirect. There might be a case that sometime fragment servers sit under the redirection rules of its infrastructure and network. For an example, redirects from http to https, etc.

I got the idea when I saw some options on request. There are options followRedirect, followAllRedirects, etc. So, it's nice to have these here.

Let me know what do you guys think.

Why I cannot set a label to feature? lol

Hi Trick, I am not sure it makes sense to follow redirects as it would make it slower if you had to follow a redirect on every request. It would make it twice as slow everytime. If you had to make a redirect, better would be to update the tailor template :) or use Quilt

@vigneshshanmugam Has Quilt been released? It doesn't look like it on https://www.mosaic9.org/

@trickpeeraze The reason why we don't it for every fragments is that, It will make the whole page composition slower as @kevinsimper pointed out.

The redirects are only handled by primary fragment since the fragment is the only one responsible for setting the status code of the page. so primary fragment can reply with 301 and the browser would take it from there.

@kevinsimper No, Its just a simple key value data store, So we thought of not doing it since its easier to do it. We do have a template cache internally, I will open source it with 4.0.0

@vigneshshanmugam My case is fragments is developed by other teams and they redirect their fragment from http://www.sample.com to https://www.sample.com.

So when we(Tailor) call them by http://www.sample.com, I need to support redirect to https by myself.

Work around is changing url to https://www.sample.com, but I think I still need to support redirect because I can't handle the fragment that developed by other team. In the future they might redirect the another url.

But the problem is as @kevinsimper mention, it will take longer time. Template cache is a good way to help. (Now I'm using ejs for template caching)

@WarisR Got it, You can pass in your own requestFragment function in tailor options and handle it it without touching tailor functionality and it still would work.

https://github.com/zalando/tailor#options

Yes yes, I got that point too so, what I am offering is an option that you can turn on and off on each fragment (via its attributes). If users want their fragments to follow redirection just turn it on and take your own risk (performance of cause). On @WarisR commented, that's such a case. I think there are other situations as well.

Btw, I just drop the idea. I'm glad that you guys come and discuss together. :)

@vigneshshanmugam I just notice that the primary fragment's already been handled redirection. However, you're saying that 301 will be forwarded to browser and it will take care the rest. In that case, there's an entire page redirection, isn't it? And this what primary is as the Tailor's concept, right?

@kevinsimper thank you for an advice but honestly, I'm quite not understand much about the concept of Quilt. Is it some kind of a registry like npm?

@trickpeeraze Yes you are right, it will result in a page redirection.

Is it some kind of a registry like npm?

No, its just like a key/value store for templates

Request -> https://www.zalando.de/home

Tailor -> Tries to fetch the template for /home from Quilt

Quilt

Key - /home

Value - <html> <head/><body/></html>

Hope this helps

Nice thanks!