|
1 | | -using System.Collections.Generic; |
| 1 | +// Copyright (c) Code Impressions, LLC. All Rights Reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License") |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +using System.Collections.Generic; |
2 | 16 | using System.Collections.Specialized; |
3 | 17 | using System.Linq; |
4 | 18 | using Transmitly.Delivery; |
5 | 19 |
|
6 | 20 | namespace Transmitly.Microsoft.Aspnet.Mvc |
7 | 21 | { |
8 | | - /// <summary> |
9 | | - /// Wraps the provided value provider and request body into the expected adaptor context. |
10 | | - /// </summary> |
11 | | - /// <param name="valueProvider">Querystring parameters.</param> |
12 | | - /// <param name="requestBody">Request string body.</param> |
13 | | - internal sealed class DefaultRequestAdaptorContext(NameValueCollection valueProvider, string requestBody) : IRequestAdaptorContext |
14 | | - { |
15 | | - private readonly NameValueCollection _valueProvider = valueProvider; |
| 22 | + /// <summary> |
| 23 | + /// Wraps the provided value provider and request body into the expected adaptor context. |
| 24 | + /// </summary> |
| 25 | + /// <param name="valueProvider">Querystring parameters.</param> |
| 26 | + /// <param name="requestBody">Request string body.</param> |
| 27 | + internal sealed class DefaultRequestAdaptorContext(NameValueCollection valueProvider, string requestBody) : IRequestAdaptorContext |
| 28 | + { |
| 29 | + private readonly NameValueCollection _valueProvider = valueProvider; |
| 30 | + private readonly Dictionary<string, string> _queryString = valueProvider.AllKeys.ToDictionary(k => k, k => valueProvider[k]); |
| 31 | + |
| 32 | + public string GetValue(string key) |
| 33 | + { |
| 34 | + return _valueProvider.GetValues(key).FirstOrDefault(); |
| 35 | + } |
| 36 | + |
| 37 | + public string? GetQueryValue(string key) |
| 38 | + { |
| 39 | + return GetValue(key); |
| 40 | + } |
| 41 | + |
| 42 | + public string? GetFormValue(string key) |
| 43 | + { |
| 44 | + return GetValue(key); |
| 45 | + } |
16 | 46 |
|
17 | | - public string GetValue(string key) |
18 | | - { |
19 | | - return _valueProvider.GetValues(key).FirstOrDefault(); |
20 | | - } |
| 47 | + public string? GetHeaderValue(string key) |
| 48 | + { |
| 49 | + return GetValue(key); |
| 50 | + } |
21 | 51 |
|
22 | | - public string Content { get; } = requestBody; |
| 52 | + public string Content { get; } = requestBody; |
23 | 53 |
|
24 | | - public string PipelineName => GetValue(DeliveryUtil.PipelineNameKey); |
| 54 | + public string PipelineName => GetValue(DeliveryUtil.PipelineNameKey); |
25 | 55 |
|
26 | | - public string ResourceId => GetValue(DeliveryUtil.ResourceIdKey); |
| 56 | + public string ResourceId => GetValue(DeliveryUtil.ResourceIdKey); |
27 | 57 |
|
28 | | - public IDictionary<string, string> QueryString => _valueProvider.AllKeys.ToDictionary(k => k, k => _valueProvider[k]); |
29 | | - } |
| 58 | + public IDictionary<string, string> QueryString => _queryString; |
| 59 | + } |
30 | 60 | } |
0 commit comments