mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 16:10:50 +08:00 
			
		
		
		
	more tests and docs
This commit is contained in:
		@@ -85,6 +85,7 @@ Ocelot allows placeholders that can be used in header transformation.
 | 
				
			|||||||
{BaseUrl} - This will use Ocelot's base url e.g. http://localhost:5000 as its value.
 | 
					{BaseUrl} - This will use Ocelot's base url e.g. http://localhost:5000 as its value.
 | 
				
			||||||
{DownstreamBaseUrl} - This will use the downstream services base url e.g. http://localhost:5000 as its value. This only works for DownstreamHeaderTransform at the moment.
 | 
					{DownstreamBaseUrl} - This will use the downstream services base url e.g. http://localhost:5000 as its value. This only works for DownstreamHeaderTransform at the moment.
 | 
				
			||||||
{TraceId} - This will use the Butterfly APM Trace Id. This only works for DownstreamHeaderTransform at the moment.
 | 
					{TraceId} - This will use the Butterfly APM Trace Id. This only works for DownstreamHeaderTransform at the moment.
 | 
				
			||||||
 | 
					{UpstreamHost} - This will look for the incoming Host header.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Handling 302 Redirects
 | 
					Handling 302 Redirects
 | 
				
			||||||
^^^^^^^^^^^^^^^^^^^^^^
 | 
					^^^^^^^^^^^^^^^^^^^^^^
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,7 +32,7 @@ namespace Ocelot.Infrastructure
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            _requestPlaceholders = new Dictionary<string, Func<DownstreamRequest, string>>
 | 
					            _requestPlaceholders = new Dictionary<string, Func<DownstreamRequest, string>>
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                { "{DownstreamBaseUrl}", GetDownstreamBaseUrl() }
 | 
					                { "{DownstreamBaseUrl}", GetDownstreamBaseUrl() },
 | 
				
			||||||
            };
 | 
					            };
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -143,10 +143,8 @@ namespace Ocelot.Infrastructure
 | 
				
			|||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        return new OkResponse<string>(upstreamHost.First());
 | 
					                        return new OkResponse<string>(upstreamHost.First());
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    else
 | 
					
 | 
				
			||||||
                    {
 | 
					                    return new ErrorResponse<string>(new CouldNotFindPlaceholderError("{UpstreamHost}"));
 | 
				
			||||||
                        return new ErrorResponse<string>(new CouldNotFindPlaceholderError("{UpstreamHost}"));
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                catch
 | 
					                catch
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -134,5 +134,22 @@ namespace Ocelot.UnitTests.Infrastructure
 | 
				
			|||||||
            var result = _placeholders.Get("{UpstreamHost}");
 | 
					            var result = _placeholders.Get("{UpstreamHost}");
 | 
				
			||||||
            result.Data.ShouldBe(upstreamHost);
 | 
					            result.Data.ShouldBe(upstreamHost);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Fact]
 | 
				
			||||||
 | 
					        public void should_return_error_when_finding_upstbecause_Host_not_set()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var httpContext = new DefaultHttpContext();
 | 
				
			||||||
 | 
					            _accessor.Setup(x => x.HttpContext).Returns(httpContext);
 | 
				
			||||||
 | 
					            var result = _placeholders.Get("{UpstreamHost}");
 | 
				
			||||||
 | 
					            result.IsError.ShouldBeTrue();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        [Fact]
 | 
				
			||||||
 | 
					        public void should_return_error_when_finding_upstream_host_because_exception_thrown()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            _accessor.Setup(x => x.HttpContext).Throws(new Exception());
 | 
				
			||||||
 | 
					            var result = _placeholders.Get("{UpstreamHost}");
 | 
				
			||||||
 | 
					            result.IsError.ShouldBeTrue();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user