Ensure HttpResponse.Query is populated with query string values
This commit is contained in:
parent
ad5a77ca4c
commit
fe15f4a849
|
|
@ -27,8 +27,7 @@ namespace Microsoft.AspNet.PipelineCore
|
|||
if (_query == null || _queryString != queryString)
|
||||
{
|
||||
_queryString = queryString;
|
||||
// TODO
|
||||
_query = new ReadableStringCollection(new Dictionary<string, string[]>());
|
||||
_query = new ReadableStringCollection(ParsingHelpers.GetQuery(queryString));
|
||||
}
|
||||
return _query;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
using Microsoft.AspNet.Abstractions;
|
||||
using Microsoft.AspNet.PipelineCore.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNet.Abstractions;
|
||||
using Microsoft.AspNet.PipelineCore.Collections;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
||||
{
|
||||
|
|
@ -799,28 +799,14 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
|||
|
||||
private static readonly char[] AmpersandAndSemicolon = new[] { '&', ';' };
|
||||
|
||||
internal static IDictionary<string, string[]> GetQuery(HttpRequest request)
|
||||
internal static IDictionary<string, string[]> GetQuery(string queryString)
|
||||
{
|
||||
var query = GetItem<IDictionary<string, string[]>>(request, "Microsoft.Owin.Query#dictionary");
|
||||
if (query == null)
|
||||
{
|
||||
query = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
|
||||
SetItem(request, "Microsoft.Owin.Query#dictionary", query);
|
||||
}
|
||||
|
||||
string text = request.QueryString.Value;
|
||||
if (GetItem<string>(request, "Microsoft.Owin.Query#text") != text)
|
||||
{
|
||||
query.Clear();
|
||||
var accumulator = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
|
||||
ParseDelimited(text, AmpersandAndSemicolon, AppendItemCallback, accumulator);
|
||||
foreach (var kv in accumulator)
|
||||
{
|
||||
query.Add(kv.Key, kv.Value.ToArray());
|
||||
}
|
||||
SetItem(request, "Microsoft.Owin.Query#text", text);
|
||||
}
|
||||
return query;
|
||||
var accumulator = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
|
||||
ParseDelimited(queryString, AmpersandAndSemicolon, AppendItemCallback, accumulator);
|
||||
return accumulator.ToDictionary(
|
||||
item => item.Key,
|
||||
item => item.Value.ToArray(),
|
||||
StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
#if !NET40
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
using Microsoft.AspNet.FeatureModel;
|
||||
using Microsoft.AspNet.HttpFeature;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.PipelineCore.Tests
|
||||
{
|
||||
public class DefaultCanHasQueryTests
|
||||
{
|
||||
[Fact]
|
||||
public void QueryReturnsParsedQueryCollection()
|
||||
{
|
||||
// Arrange
|
||||
var features = new Mock<IFeatureCollection>();
|
||||
var request = new Mock<IHttpRequestInformation>();
|
||||
request.SetupGet(r => r.QueryString).Returns("foo=bar");
|
||||
|
||||
object value = request.Object;
|
||||
features.Setup(f => f.TryGetValue(typeof(IHttpRequestInformation), out value))
|
||||
.Returns(true);
|
||||
|
||||
var provider = new DefaultCanHasQuery(features.Object);
|
||||
|
||||
// Act
|
||||
var queryCollection = provider.Query;
|
||||
|
||||
// Assert
|
||||
Assert.Equal("bar", queryCollection["foo"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue