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
Closed

Hope redirection can be routed #190

cqkisyouq opened this issue Jan 6, 2018 · 15 comments · Fixed by #204
Labels
feature A new feature help wanted Not actively being worked on. If you plan to contribute, please drop a note. medium effort Likely a few days of development effort

Comments

@cqkisyouq
Copy link

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

@TomPallister
Copy link
Member

@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
Copy link
Author

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

@cqkisyouq
Copy link
Author

Current redirection addresses are not controlled by routing

@TomPallister
Copy link
Member

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

@cqkisyouq
Copy link
Author

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

@cqkisyouq
Copy link
Author

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

@TomPallister
Copy link
Member

@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
Copy link

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

@cqkisyouq
Copy link
Author

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

@cqkisyouq
Copy link
Author

@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
Copy link
Member

@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.

@TomPallister TomPallister added feature A new feature medium effort Likely a few days of development effort help wanted Not actively being worked on. If you plan to contribute, please drop a note. labels Jan 9, 2018
@cqkisyouq
Copy link
Author

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

@cqkisyouq
Copy link
Author

@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
Copy link
Member

haha I will open another issue :)

@TomPallister
Copy link
Member

@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
Labels
feature A new feature help wanted Not actively being worked on. If you plan to contribute, please drop a note. medium effort Likely a few days of development effort
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants