Skip to content

Commit ca4bbc4

Browse files
committed
PR feedback
1 parent aef4e98 commit ca4bbc4

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

src/Http/Http.Abstractions/src/Extensions/MapMiddleware.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ public Task Invoke(HttpContext context)
5555

5656
if (context.Request.Path.StartsWithSegments(_options.PathMatch, out var matchedPath, out var remainingPath))
5757
{
58-
return InvokeCore(context, matchedPath, remainingPath);
58+
if (!_options.PreserveMatchedPathSegment)
59+
{
60+
return InvokeCore(context, matchedPath, remainingPath);
61+
}
62+
return _options.Branch!(context);
5963
}
6064
return _next(context);
6165
}
@@ -65,24 +69,18 @@ private async Task InvokeCore(HttpContext context, string matchedPath, string re
6569
var path = context.Request.Path;
6670
var pathBase = context.Request.PathBase;
6771

68-
if (!_options.PreserveMatchedPathSegment)
69-
{
70-
// Update the path
71-
context.Request.PathBase = pathBase.Add(matchedPath);
72-
context.Request.Path = remainingPath;
73-
}
72+
// Update the path
73+
context.Request.PathBase = pathBase.Add(matchedPath);
74+
context.Request.Path = remainingPath;
7475

7576
try
7677
{
7778
await _options.Branch!(context);
7879
}
7980
finally
8081
{
81-
if (!_options.PreserveMatchedPathSegment)
82-
{
83-
context.Request.PathBase = pathBase;
84-
context.Request.Path = path;
85-
}
82+
context.Request.PathBase = pathBase;
83+
context.Request.Path = path;
8684
}
8785
}
8886
}

src/Middleware/HttpOverrides/src/HttpMethodOverrideMiddleware.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,32 @@ public Task Invoke(HttpContext context)
4545
{
4646
if (HttpMethods.IsPost(context.Request.Method))
4747
{
48-
return InvokeCore(context);
48+
if (_options.FormFieldName != null)
49+
{
50+
if (context.Request.HasFormContentType)
51+
{
52+
return InvokeCore(context);
53+
}
54+
}
55+
else
56+
{
57+
var xHttpMethodOverrideValue = context.Request.Headers[xHttpMethodOverride];
58+
if (!string.IsNullOrEmpty(xHttpMethodOverrideValue))
59+
{
60+
context.Request.Method = xHttpMethodOverrideValue;
61+
}
62+
}
4963
}
5064
return _next(context);
5165
}
5266

5367
private async Task InvokeCore(HttpContext context)
5468
{
55-
if (_options.FormFieldName != null)
69+
var form = await context.Request.ReadFormAsync();
70+
var methodType = form[_options.FormFieldName!];
71+
if (!string.IsNullOrEmpty(methodType))
5672
{
57-
if (context.Request.HasFormContentType)
58-
{
59-
var form = await context.Request.ReadFormAsync();
60-
var methodType = form[_options.FormFieldName];
61-
if (!string.IsNullOrEmpty(methodType))
62-
{
63-
context.Request.Method = methodType;
64-
}
65-
}
66-
}
67-
else
68-
{
69-
var xHttpMethodOverrideValue = context.Request.Headers[xHttpMethodOverride];
70-
if (!string.IsNullOrEmpty(xHttpMethodOverrideValue))
71-
{
72-
context.Request.Method = xHttpMethodOverrideValue;
73-
}
73+
context.Request.Method = methodType;
7474
}
7575
await _next(context);
7676
}

0 commit comments

Comments
 (0)