Skip to content

Commit 9b05371

Browse files
committed
PUT remote parameter fix
1 parent 80ba5d5 commit 9b05371

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

src/NetCoreStack.Proxy/DefaultProxyContentStreamProvider.cs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@ protected virtual HttpContent CreateHttpContent(object value)
4747
return content;
4848
}
4949

50+
protected virtual void EnsureTemplate(ProxyMethodDescriptor descriptor,
51+
ProxyUriDefinition proxyUriDefinition,
52+
RequestContext requestContext,
53+
IDictionary<string, object> argsDic,
54+
List<string> keys)
55+
{
56+
if (descriptor.Template.HasValue())
57+
{
58+
if (proxyUriDefinition.HasParameter)
59+
{
60+
for (int i = 0; i < proxyUriDefinition.ParameterParts.Count; i++)
61+
{
62+
var key = keys[i];
63+
proxyUriDefinition.UriBuilder.Path += ($"/{WebUtility.UrlEncode(requestContext.Args[i]?.ToString())}");
64+
argsDic.Remove(key);
65+
}
66+
}
67+
}
68+
}
69+
5070
public async Task CreateRequestContentAsync(RequestContext requestContext,
5171
HttpRequestMessage request,
5272
ProxyMethodDescriptor descriptor,
@@ -69,6 +89,9 @@ public async Task CreateRequestContentAsync(RequestContext requestContext,
6989
}
7090
else if(descriptor.HttpMethod == HttpMethod.Put)
7191
{
92+
EnsureTemplate(descriptor, proxyUriDefinition, requestContext, argsDic, keys);
93+
argsCount = argsDic.Count;
94+
request.RequestUri = uriBuilder.Uri;
7295
if (argsCount == 1)
7396
{
7497
request.Content = SerializeToString(argsDic.First().Value);
@@ -90,19 +113,7 @@ public async Task CreateRequestContentAsync(RequestContext requestContext,
90113
}
91114
if (descriptor.HttpMethod == HttpMethod.Get || descriptor.HttpMethod == HttpMethod.Delete)
92115
{
93-
if (descriptor.Template.HasValue())
94-
{
95-
if (proxyUriDefinition.HasParameter)
96-
{
97-
for (int i = 0; i < proxyUriDefinition.ParameterParts.Count; i++)
98-
{
99-
var key = keys[i];
100-
uriBuilder.Path += ($"/{WebUtility.UrlEncode(requestContext.Args[i]?.ToString())}");
101-
argsDic.Remove(key);
102-
}
103-
}
104-
}
105-
116+
EnsureTemplate(descriptor, proxyUriDefinition, requestContext, argsDic, keys);
106117
request.RequestUri = QueryStringResolver.Parse(uriBuilder, argsDic);
107118
}
108119
}

test/NetCoreStack.Proxy.Test.Contracts/IConsulApi.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@ public interface IConsulApi : IApiContract
1919

2020
[HttpGetMarker(Template = "health/node/{id}")]
2121
Task<IEnumerable<AgentCheck>> CheckNode(string node);
22+
23+
[HttpPutMarker(Template = "kv/{key}")]
24+
Task<bool> CreateOrUpdateKey(string key, string body);
2225
}
2326
}

test/NetCoreStack.Proxy.WebClient/Controllers/TestController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,11 @@ public async Task<IActionResult> CheckAgent()
8585

8686
return Json(agentMembers);
8787
}
88+
89+
public async Task<IActionResult> CreateOrUpdateKey()
90+
{
91+
var flag = await _consuleApi.CreateOrUpdateKey("foo", "{foo: 'bar'}");
92+
return Json(new { someFlag = flag });
93+
}
8894
}
8995
}

0 commit comments

Comments
 (0)