-
Notifications
You must be signed in to change notification settings - Fork 803
/
HttpContextFeaturesExtensions.cs
53 lines (47 loc) · 1.8 KB
/
HttpContextFeaturesExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Net.Http;
using Microsoft.AspNetCore.Http;
using Xunit;
using Yarp.ReverseProxy.Configuration;
using Yarp.ReverseProxy.Forwarder;
namespace Yarp.ReverseProxy.Model.Tests;
public class HttpContextFeaturesExtensions
{
[Fact]
public void ReassignProxyRequest_Success()
{
var client = new HttpMessageInvoker(new SocketsHttpHandler());
var context = new DefaultHttpContext();
var d1 = new DestinationState("d1");
var d2 = new DestinationState("d2");
var cc1 = new ClusterConfig() { ClusterId = "c1" };
var cm1 = new ClusterModel(cc1, client);
var cs1 = new ClusterState("c1") { Model = cm1 };
var r1 = new RouteModel(new RouteConfig() { RouteId = "r1" }, cs1, HttpTransformer.Empty);
var feature = new ReverseProxyFeature()
{
AllDestinations = d1,
AvailableDestinations = d1,
Cluster = cm1,
Route = r1,
ProxiedDestination = d1,
};
context.Features.Set<IReverseProxyFeature>(feature);
var cc2 = new ClusterConfig() { ClusterId = "cc2" };
var cm2 = new ClusterModel(cc2, client);
var cs2 = new ClusterState("cs2")
{
DestinationsState = new ClusterDestinationsState(d2, d2),
Model = cm2,
};
context.ReassignProxyRequest(cs2);
var newFeature = context.GetReverseProxyFeature();
Assert.NotSame(feature, newFeature);
Assert.Same(d2, newFeature.AllDestinations);
Assert.Same(d2, newFeature.AvailableDestinations);
Assert.Same(d1, newFeature.ProxiedDestination); // Copied unmodified.
Assert.Same(cm2, newFeature.Cluster);
Assert.Same(r1, newFeature.Route);
}
}