Added HttpRequestMethodOverrideDecorator · bonesoul/uhttpsharp@7aa25b7 · GitHub
Skip to content

Commit 7aa25b7

Browse files
committed
Added HttpRequestMethodOverrideDecorator
Usage : Add X-HTTP-Method-Override header with the right method.
1 parent c1da5de commit 7aa25b7

4 files changed

Lines changed: 88 additions & 1 deletion

File tree

‎uhttpsharp.dll.nuspec‎

Lines changed: 1 addition & 1 deletion
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using uhttpsharp.Headers;
3+
4+
namespace uhttpsharp.RequestProviders
5+
{
6+
internal class HttpRequestMethodDecorator : IHttpRequest
7+
{
8+
private readonly IHttpRequest _child;
9+
private readonly HttpMethods _method;
10+
11+
public HttpRequestMethodDecorator(IHttpRequest child, HttpMethods method)
12+
{
13+
_child = child;
14+
_method = method;
15+
}
16+
17+
public IHttpHeaders Headers
18+
{
19+
get { return _child.Headers; }
20+
}
21+
22+
public HttpMethods Method
23+
{
24+
get { return _method; }
25+
}
26+
27+
public string Protocol
28+
{
29+
get { return _child.Protocol; }
30+
}
31+
32+
public Uri Uri
33+
{
34+
get { return _child.Uri; }
35+
}
36+
37+
public string[] RequestParameters
38+
{
39+
get { return _child.RequestParameters; }
40+
}
41+
42+
public IHttpPost Post
43+
{
44+
get { return _child.Post; }
45+
}
46+
47+
public IHttpHeaders QueryString
48+
{
49+
get { return _child.QueryString; }
50+
}
51+
}
52+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.IO;
2+
using System.Threading.Tasks;
3+
4+
namespace uhttpsharp.RequestProviders
5+
{
6+
public class HttpRequestProviderMethodOverrideDecorator : IHttpRequestProvider
7+
{
8+
private readonly IHttpRequestProvider _child;
9+
10+
public HttpRequestProviderMethodOverrideDecorator(IHttpRequestProvider child)
11+
{
12+
_child = child;
13+
}
14+
15+
public async Task<IHttpRequest> Provide(StreamReader streamReader)
16+
{
17+
var childValue = await _child.Provide(streamReader).ConfigureAwait(false);
18+
19+
if (childValue == null)
20+
{
21+
return null;
22+
}
23+
24+
string methodName;
25+
if (!childValue.Headers.TryGetByName("X-HTTP-Method-Override", out methodName))
26+
{
27+
return childValue;
28+
}
29+
30+
return new HttpRequestMethodDecorator(childValue, HttpMethodProvider.Default.Provide(methodName));
31+
}
32+
}
33+
}

‎uhttpsharp/uhttpsharp.csproj‎

Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)