File tree Expand file tree Collapse file tree 4 files changed +64
-2
lines changed
src/GeekLearning.RestKit.Core Expand file tree Collapse file tree 4 files changed +64
-2
lines changed Original file line number Diff line number Diff line change 8
8
namespace GeekLearning . RestKit . Core
9
9
{
10
10
public abstract class ClientBase < TOptions >
11
- where TOptions : class , new ( )
11
+ where TOptions : class , IProvideRequestFilters , new ( )
12
12
{
13
13
private IMediaFormatterProvider mediaFormatterProvider ;
14
14
15
- public ClientBase ( IOptions < TOptions > options , IMediaFormatterProvider mediaFormatterProvider )
15
+ public ClientBase ( IOptions < TOptions > options ,
16
+ IMediaFormatterProvider mediaFormatterProvider )
16
17
{
17
18
this . Options = options . Value ;
18
19
this . mediaFormatterProvider = mediaFormatterProvider ;
@@ -30,6 +31,17 @@ protected Task<TTarget> TransformResponseAsync<TTarget>(HttpResponseMessage mess
30
31
return mediaFormatter . TransformAsync < TTarget > ( message . Content ) ;
31
32
}
32
33
34
+ protected HttpRequestMessage ApplyFilters ( HttpRequestMessage requestMessage , params string [ ] securityDefinitions )
35
+ {
36
+ HttpRequestMessage finalMessage = requestMessage ;
37
+ foreach ( var filter in this . Options . RequestFilters )
38
+ {
39
+ finalMessage = filter . Apply ( requestMessage , securityDefinitions ) ?? finalMessage ;
40
+ }
41
+
42
+ return finalMessage ;
43
+ }
44
+
33
45
protected HttpContent TransformRequestBody ( object data , string mediaType )
34
46
{
35
47
IMediaFormatter mediaFormatter = this . mediaFormatterProvider . GetMediaFormatter ( mediaType ) ;
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Threading . Tasks ;
5
+
6
+ namespace GeekLearning . RestKit . Core
7
+ {
8
+ public abstract class ClientOptionsBase : IProvideRequestFilters
9
+ {
10
+ private List < IRequestFilter > requestfilters = new List < IRequestFilter > ( ) ;
11
+
12
+ public void AddFilter ( IRequestFilter filter )
13
+ {
14
+ this . requestfilters . Add ( filter ) ;
15
+ }
16
+
17
+ public IEnumerable < IRequestFilter > RequestFilters
18
+ {
19
+ get
20
+ {
21
+ return requestfilters ;
22
+ }
23
+ }
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Threading . Tasks ;
5
+
6
+ namespace GeekLearning . RestKit . Core
7
+ {
8
+ public interface IProvideRequestFilters
9
+ {
10
+ IEnumerable < IRequestFilter > RequestFilters { get ; }
11
+ }
12
+ }
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Net . Http ;
5
+ using System . Threading . Tasks ;
6
+
7
+ namespace GeekLearning . RestKit . Core
8
+ {
9
+ public interface IRequestFilter
10
+ {
11
+ HttpRequestMessage Apply ( HttpRequestMessage requestMessage , string [ ] securityDefinitions ) ;
12
+ }
13
+ }
You can’t perform that action at this time.
0 commit comments