diff --git a/src/Microsoft.AspNet.Http/HostString.cs b/src/Microsoft.AspNet.Http/HostString.cs index 1786a7c338..7e4381f9f1 100644 --- a/src/Microsoft.AspNet.Http/HostString.cs +++ b/src/Microsoft.AspNet.Http/HostString.cs @@ -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)); } diff --git a/src/Microsoft.AspNet.PipelineCore/FormFeature.cs b/src/Microsoft.AspNet.PipelineCore/FormFeature.cs index 25472d4057..e695b460a3 100644 --- a/src/Microsoft.AspNet.PipelineCore/FormFeature.cs +++ b/src/Microsoft.AspNet.PipelineCore/FormFeature.cs @@ -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 GetFormAsync(CancellationToken cancellationToken) { + if (_features == null) + { + return _form; + } + var body = _request.Fetch(_features).Body; if (_bodyStream == null || _bodyStream != body) diff --git a/src/Microsoft.AspNet.PipelineCore/Infrastructure/ParsingHelpers.cs b/src/Microsoft.AspNet.PipelineCore/Infrastructure/ParsingHelpers.cs index 8dc89e6063..a545a1dac7 100644 --- a/src/Microsoft.AspNet.PipelineCore/Infrastructure/ParsingHelpers.cs +++ b/src/Microsoft.AspNet.PipelineCore/Infrastructure/ParsingHelpers.cs @@ -818,7 +818,6 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure StringComparer.OrdinalIgnoreCase); } -#if !NET40 internal static IFormCollection GetForm(string text) { IDictionary form = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -830,7 +829,6 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure } return new FormCollection(form); } -#endif internal static string GetJoinedValue(IDictionary store, string key) { diff --git a/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.kproj b/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.kproj index 358e55cca5..8caa5a4f61 100644 --- a/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.kproj +++ b/src/Microsoft.AspNet.PipelineCore/Microsoft.AspNet.PipelineCore.kproj @@ -31,6 +31,7 @@ + diff --git a/src/Microsoft.AspNet.PipelineCore/NotNullAttribute.cs b/src/Microsoft.AspNet.PipelineCore/NotNullAttribute.cs new file mode 100644 index 0000000000..33fc2e3070 --- /dev/null +++ b/src/Microsoft.AspNet.PipelineCore/NotNullAttribute.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 + { + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.PipelineCore/QueryFeature.cs b/src/Microsoft.AspNet.PipelineCore/QueryFeature.cs index 71e75e5031..a2c7df5fe3 100644 --- a/src/Microsoft.AspNet.PipelineCore/QueryFeature.cs +++ b/src/Microsoft.AspNet.PipelineCore/QueryFeature.cs @@ -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) { diff --git a/src/Microsoft.AspNet.PipelineCore/RequestCookiesFeature.cs b/src/Microsoft.AspNet.PipelineCore/RequestCookiesFeature.cs index 6af65fa206..5507708ea6 100644 --- a/src/Microsoft.AspNet.PipelineCore/RequestCookiesFeature.cs +++ b/src/Microsoft.AspNet.PipelineCore/RequestCookiesFeature.cs @@ -17,9 +17,14 @@ namespace Microsoft.AspNet.PipelineCore private readonly FeatureReference _request = FeatureReference.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) {