#91 Add constructors to Form, Query, and Cookie features for testing.
This commit is contained in:
parent
de1017e010
commit
dc055f783a
|
|
@ -136,9 +136,7 @@ namespace Microsoft.AspNet.Http
|
|||
throw new ArgumentNullException("uri");
|
||||
}
|
||||
return new HostString(uri.GetComponents(
|
||||
#if !NET40
|
||||
UriComponents.NormalizedHost | // Always convert punycode to Unicode.
|
||||
#endif
|
||||
UriComponents.HostAndPort, UriFormat.Unescaped));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,13 +20,23 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
private Stream _bodyStream;
|
||||
private IReadableStringCollection _form;
|
||||
|
||||
public FormFeature(IFeatureCollection features)
|
||||
public FormFeature([NotNull] IReadableStringCollection form)
|
||||
{
|
||||
_form = form;
|
||||
}
|
||||
|
||||
public FormFeature([NotNull] IFeatureCollection features)
|
||||
{
|
||||
_features = features;
|
||||
}
|
||||
|
||||
public async Task<IReadableStringCollection> GetFormAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (_features == null)
|
||||
{
|
||||
return _form;
|
||||
}
|
||||
|
||||
var body = _request.Fetch(_features).Body;
|
||||
|
||||
if (_bodyStream == null || _bodyStream != body)
|
||||
|
|
|
|||
|
|
@ -818,7 +818,6 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
#if !NET40
|
||||
internal static IFormCollection GetForm(string text)
|
||||
{
|
||||
IDictionary<string, string[]> form = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
|
||||
|
|
@ -830,7 +829,6 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
}
|
||||
return new FormCollection(form);
|
||||
}
|
||||
#endif
|
||||
|
||||
internal static string GetJoinedValue(IDictionary<string, string[]> store, string key)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
<Compile Include="DefaultHttpResponseFeature.cs" />
|
||||
<Compile Include="FormFeature.cs" />
|
||||
<Compile Include="ItemsFeature.cs" />
|
||||
<Compile Include="NotNullAttribute.cs" />
|
||||
<Compile Include="QueryFeature.cs" />
|
||||
<Compile Include="RequestCookiesFeature.cs" />
|
||||
<Compile Include="ResponseCookiesFeature.cs" />
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
|
||||
internal sealed class NotNullAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Microsoft.AspNet.PipelineCore.Collections;
|
||||
using Microsoft.AspNet.PipelineCore.Infrastructure;
|
||||
|
|
@ -17,7 +16,12 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
private string _queryString;
|
||||
private IReadableStringCollection _query;
|
||||
|
||||
public QueryFeature(IFeatureCollection features)
|
||||
public QueryFeature([NotNull] IReadableStringCollection query)
|
||||
{
|
||||
_query = query;
|
||||
}
|
||||
|
||||
public QueryFeature([NotNull] IFeatureCollection features)
|
||||
{
|
||||
_features = features;
|
||||
}
|
||||
|
|
@ -26,6 +30,11 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
{
|
||||
get
|
||||
{
|
||||
if (_features == null)
|
||||
{
|
||||
return _query;
|
||||
}
|
||||
|
||||
var queryString = _request.Fetch(_features).QueryString;
|
||||
if (_query == null || _queryString != queryString)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,9 +17,14 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
private readonly FeatureReference<IHttpRequestFeature> _request = FeatureReference<IHttpRequestFeature>.Default;
|
||||
private string _cookiesHeader;
|
||||
private RequestCookiesCollection _cookiesCollection;
|
||||
private static readonly string[] ZeroHeaders = new string[0];
|
||||
private IReadableStringCollection _cookies;
|
||||
|
||||
public RequestCookiesFeature(IFeatureCollection features)
|
||||
public RequestCookiesFeature([NotNull] IReadableStringCollection cookies)
|
||||
{
|
||||
_cookies = cookies;
|
||||
}
|
||||
|
||||
public RequestCookiesFeature([NotNull] IFeatureCollection features)
|
||||
{
|
||||
_features = features;
|
||||
}
|
||||
|
|
@ -28,8 +33,13 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
{
|
||||
get
|
||||
{
|
||||
if (_features == null)
|
||||
{
|
||||
return _cookies;
|
||||
}
|
||||
|
||||
var headers = _request.Fetch(_features).Headers;
|
||||
string cookiesHeader = ParsingHelpers.GetHeader(headers, Constants.Headers.Cookie) ?? "";
|
||||
string cookiesHeader = ParsingHelpers.GetHeader(headers, Constants.Headers.Cookie) ?? string.Empty;
|
||||
|
||||
if (_cookiesCollection == null)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue