#91 Add constructors to Form, Query, and Cookie features for testing.

This commit is contained in:
Chris Ross 2014-07-16 16:12:46 -07:00
parent de1017e010
commit dc055f783a
7 changed files with 49 additions and 11 deletions

View File

@ -136,9 +136,7 @@ namespace Microsoft.AspNet.Http
throw new ArgumentNullException("uri"); throw new ArgumentNullException("uri");
} }
return new HostString(uri.GetComponents( return new HostString(uri.GetComponents(
#if !NET40
UriComponents.NormalizedHost | // Always convert punycode to Unicode. UriComponents.NormalizedHost | // Always convert punycode to Unicode.
#endif
UriComponents.HostAndPort, UriFormat.Unescaped)); UriComponents.HostAndPort, UriFormat.Unescaped));
} }

View File

@ -20,13 +20,23 @@ namespace Microsoft.AspNet.PipelineCore
private Stream _bodyStream; private Stream _bodyStream;
private IReadableStringCollection _form; private IReadableStringCollection _form;
public FormFeature(IFeatureCollection features) public FormFeature([NotNull] IReadableStringCollection form)
{
_form = form;
}
public FormFeature([NotNull] IFeatureCollection features)
{ {
_features = features; _features = features;
} }
public async Task<IReadableStringCollection> GetFormAsync(CancellationToken cancellationToken) public async Task<IReadableStringCollection> GetFormAsync(CancellationToken cancellationToken)
{ {
if (_features == null)
{
return _form;
}
var body = _request.Fetch(_features).Body; var body = _request.Fetch(_features).Body;
if (_bodyStream == null || _bodyStream != body) if (_bodyStream == null || _bodyStream != body)

View File

@ -818,7 +818,6 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
StringComparer.OrdinalIgnoreCase); StringComparer.OrdinalIgnoreCase);
} }
#if !NET40
internal static IFormCollection GetForm(string text) internal static IFormCollection GetForm(string text)
{ {
IDictionary<string, string[]> form = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase); IDictionary<string, string[]> form = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
@ -830,7 +829,6 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
} }
return new FormCollection(form); return new FormCollection(form);
} }
#endif
internal static string GetJoinedValue(IDictionary<string, string[]> store, string key) internal static string GetJoinedValue(IDictionary<string, string[]> store, string key)
{ {

View File

@ -31,6 +31,7 @@
<Compile Include="DefaultHttpResponseFeature.cs" /> <Compile Include="DefaultHttpResponseFeature.cs" />
<Compile Include="FormFeature.cs" /> <Compile Include="FormFeature.cs" />
<Compile Include="ItemsFeature.cs" /> <Compile Include="ItemsFeature.cs" />
<Compile Include="NotNullAttribute.cs" />
<Compile Include="QueryFeature.cs" /> <Compile Include="QueryFeature.cs" />
<Compile Include="RequestCookiesFeature.cs" /> <Compile Include="RequestCookiesFeature.cs" />
<Compile Include="ResponseCookiesFeature.cs" /> <Compile Include="ResponseCookiesFeature.cs" />

View File

@ -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
{
}
}

View File

@ -1,9 +1,8 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // 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. // 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.FeatureModel;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.HttpFeature; using Microsoft.AspNet.HttpFeature;
using Microsoft.AspNet.PipelineCore.Collections; using Microsoft.AspNet.PipelineCore.Collections;
using Microsoft.AspNet.PipelineCore.Infrastructure; using Microsoft.AspNet.PipelineCore.Infrastructure;
@ -17,7 +16,12 @@ namespace Microsoft.AspNet.PipelineCore
private string _queryString; private string _queryString;
private IReadableStringCollection _query; private IReadableStringCollection _query;
public QueryFeature(IFeatureCollection features) public QueryFeature([NotNull] IReadableStringCollection query)
{
_query = query;
}
public QueryFeature([NotNull] IFeatureCollection features)
{ {
_features = features; _features = features;
} }
@ -26,6 +30,11 @@ namespace Microsoft.AspNet.PipelineCore
{ {
get get
{ {
if (_features == null)
{
return _query;
}
var queryString = _request.Fetch(_features).QueryString; var queryString = _request.Fetch(_features).QueryString;
if (_query == null || _queryString != queryString) if (_query == null || _queryString != queryString)
{ {

View File

@ -17,9 +17,14 @@ namespace Microsoft.AspNet.PipelineCore
private readonly FeatureReference<IHttpRequestFeature> _request = FeatureReference<IHttpRequestFeature>.Default; private readonly FeatureReference<IHttpRequestFeature> _request = FeatureReference<IHttpRequestFeature>.Default;
private string _cookiesHeader; private string _cookiesHeader;
private RequestCookiesCollection _cookiesCollection; 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; _features = features;
} }
@ -28,8 +33,13 @@ namespace Microsoft.AspNet.PipelineCore
{ {
get get
{ {
if (_features == null)
{
return _cookies;
}
var headers = _request.Fetch(_features).Headers; 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) if (_cookiesCollection == null)
{ {