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

Hope redirection can be routed #190

Closed
cqkisyouq opened this issue Jan 6, 2018 · 15 comments · Fixed by #204

Comments

@cqkisyouq
Copy link

@cqkisyouq cqkisyouq commented Jan 6, 2018

I want to have a routing configuration for a redirected address.

@TomPallister

This comment has been minimized.

Copy link
Member

@TomPallister TomPallister commented Jan 6, 2018

@cqkisyouq Do you mean you want your routing to follow redirects?

If so in configuration.json there is a property on the ReRoute called HttpHandlerOptions and that has a property called AllowAutoRedirect.

If you set this to true Ocelot should follow redirects.

@cqkisyouq

This comment has been minimized.

Copy link
Author

@cqkisyouq cqkisyouq commented Jan 7, 2018

@TomPallister No,I want to use the route to control the address for redirection

@cqkisyouq

This comment has been minimized.

Copy link
Author

@cqkisyouq cqkisyouq commented Jan 7, 2018

Current redirection addresses are not controlled by routing

@TomPallister

This comment has been minimized.

Copy link
Member

@TomPallister TomPallister commented Jan 7, 2018

Ahhh you want to return a 301 or 302 from Ocelot?

@cqkisyouq

This comment has been minimized.

Copy link
Author

@cqkisyouq cqkisyouq commented Jan 7, 2018

@TomPallister Both return and non return can be available, but the address of the jump needs to be replaced on the specified route.

@cqkisyouq

This comment has been minimized.

Copy link
Author

@cqkisyouq cqkisyouq commented Jan 7, 2018

headers->location: localhost:5000/a/b
(replace)->return replace a new url or find request to result for Reroutes

@TomPallister

This comment has been minimized.

Copy link
Member

@TomPallister TomPallister commented Jan 7, 2018

@cqkisyouq I'm sorry but I don't understand what you want Ocelot to do :(

Please could you try and explain with more detail?

Thank you :o

@dbarkwell

This comment has been minimized.

Copy link

@dbarkwell dbarkwell commented Jan 7, 2018

@cqkisyouq are you looking for the configuration to be updated for a 301?

@cqkisyouq

This comment has been minimized.

Copy link
Author

@cqkisyouq cqkisyouq commented Jan 8, 2018

@dbarkwell Yes, I want to configure the jump address because the present jump address is not controlled.

@cqkisyouq

This comment has been minimized.

Copy link
Author

@cqkisyouq cqkisyouq commented Jan 8, 2018

@TomPallister The absolute address is not controlled for ocelot, and the relative address is normal.
{
"DownstreamPathTemplate": "/pay/{url}",
"DownstreamScheme": "http",
"DownstreamHost": "localhost",
"DownstreamPort": "6773",
"UpstreamPathTemplate": "/pay/{url}",
"QosOptions": {
"ExceptionsAllowedBeforeBreasking": 3,
"DurationOfBreak": 10,
"TimeoutValue": 5000
}
}

response state 302
Date: Mon, 08 Jan 2018 02:25:05 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 145
Location: http://localhost:6773/pay/Recive

return Redirect("http://localhost:6773/pay/Recive");
Now redirection to http://localhost:6773/pay/Recive not controlled for ocelot

return RedirectToAction("Recive");
Location: /pay/Recive
Now redirection to http://localhost:5000/pay/Recive it's ok

@TomPallister

This comment has been minimized.

Copy link
Member

@TomPallister TomPallister commented Jan 9, 2018

@cqkisyouq I think I might understand now.

You have a service that is returning a redirect but the base url returned in the location header is for the service not Ocelot?

This is not a feature that Ocelot supports at the moment.

The easiest way for you to make this work is probably add a piece of middleware before ocelot that does a replace on your url.

redirectmiddleware.cs

public ReDirectMiddleware(RequestDelegate next         
{
      _next = next;        
}

public async Task Invoke(HttpContext context)
{
      await _next.Invoke(context);
      var locations = context.Response.Headers.FirstOrDefault(x => x.Key.ToLower() == "location");
      //do something with header
      //not sure exactly what but you should be able to transform the response header here.
}

startup.cs

app.RedirectMiddleware();
app.UseOcelot().Wait();

If I am correct this is a feature I will add soon.

@cqkisyouq

This comment has been minimized.

Copy link
Author

@cqkisyouq cqkisyouq commented Jan 10, 2018

@TomPallister Yes, you're right. That's the function I want.

@cqkisyouq

This comment has been minimized.

Copy link
Author

@cqkisyouq cqkisyouq commented Jan 23, 2018

@TomPallister It's so fast to see the realization of this function. Thank you very much for your efforts. Now is a one to one replacement, hoping to be optimized to be a multi - to - many replacement

"DownstreamHeaderTransform": {
"location": "http://localhost:5001,http://localhost:5000"
},

Hope to optimize the configuration:
"DownstreamHeaderTransform": {
"location": [{one,one},{two,two}....]
},
Now the function is already very good.

@TomPallister

This comment has been minimized.

Copy link
Member

@TomPallister TomPallister commented Jan 23, 2018

haha I will open another issue :)

@TomPallister

This comment has been minimized.

Copy link
Member

@TomPallister TomPallister commented Jan 27, 2018

@cqkisyouq #205

This should help with your location redirect use case but is not multi to many replacement yet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.