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)
|
if (_query == null || _queryString != queryString)
|
||||||
{
|
{
|
||||||
_queryString = queryString;
|
_queryString = queryString;
|
||||||
// TODO
|
_query = new ReadableStringCollection(ParsingHelpers.GetQuery(queryString));
|
||||||
_query = new ReadableStringCollection(new Dictionary<string, string[]>());
|
|
||||||
}
|
}
|
||||||
return _query;
|
return _query;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
using Microsoft.AspNet.Abstractions;
|
|
||||||
using Microsoft.AspNet.PipelineCore.Collections;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Microsoft.AspNet.Abstractions;
|
||||||
|
using Microsoft.AspNet.PipelineCore.Collections;
|
||||||
|
|
||||||
namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
||||||
{
|
{
|
||||||
|
|
@ -799,28 +799,14 @@ namespace Microsoft.AspNet.PipelineCore.Infrastructure
|
||||||
|
|
||||||
private static readonly char[] AmpersandAndSemicolon = new[] { '&', ';' };
|
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");
|
var accumulator = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
|
||||||
if (query == null)
|
ParseDelimited(queryString, AmpersandAndSemicolon, AppendItemCallback, accumulator);
|
||||||
{
|
return accumulator.ToDictionary(
|
||||||
query = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase);
|
item => item.Key,
|
||||||
SetItem(request, "Microsoft.Owin.Query#dictionary", query);
|
item => item.Value.ToArray(),
|
||||||
}
|
StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !NET40
|
#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