Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Less alloc/wrapping/boxing for Query, Forms, Cookies #411

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Microsoft.AspNet.Http.Abstractions/FragmentString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static FragmentString FromUriComponent(Uri uri)
string fragmentValue = uri.GetComponents(UriComponents.Fragment, UriFormat.UriEscaped);
if (!string.IsNullOrEmpty(fragmentValue))
{
fragmentValue = "#" + fragmentValue;
fragmentValue = $"#{fragmentValue}";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of a question, how is this more efficient?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is: #411 (comment)

}
return new FragmentString(fragmentValue);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Microsoft.AspNet.Http.Abstractions/HostString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ public string ToUriComponent()
&& _value.IndexOf(':', index + 1) >= 0)
{
// IPv6 without brackets ::1 is the only type of host with 2 or more colons
return "[" + _value + "]";
return $"[{_value}]";
}
else if (index >= 0)
{
// Has a port
string port = _value.Substring(index);
IdnMapping mapping = new IdnMapping();
var mapping = new IdnMapping();
return mapping.GetAscii(_value, 0, index) + port;
}
else
{
IdnMapping mapping = new IdnMapping();
var mapping = new IdnMapping();
return mapping.GetAscii(_value);
}
}
Expand Down Expand Up @@ -115,12 +115,12 @@ public static HostString FromUriComponent(string uriComponent)
{
// Has a port
string port = uriComponent.Substring(index);
IdnMapping mapping = new IdnMapping();
var mapping = new IdnMapping();
uriComponent = mapping.GetUnicode(uriComponent, 0, index) + port;
}
else
{
IdnMapping mapping = new IdnMapping();
var mapping = new IdnMapping();
uriComponent = mapping.GetUnicode(uriComponent);
}
}
Expand Down
34 changes: 17 additions & 17 deletions src/Microsoft.AspNet.Http.Abstractions/HttpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public abstract class HttpRequest
public abstract string Method { get; set; }

/// <summary>
/// Gets or set the HTTP request scheme from owin.RequestScheme.
/// Gets or set the HTTP request scheme.
/// </summary>
/// <returns>The HTTP request scheme from owin.RequestScheme.</returns>
/// <returns>The HTTP request scheme.</returns>
public abstract string Scheme { get; set; }

/// <summary>
/// Returns true if the owin.RequestScheme is https.
/// Returns true if the RequestScheme is https.
/// </summary>
/// <returns>true if this request is using https; otherwise, false.</returns>
public abstract bool IsHttps { get; set; }
Expand All @@ -42,33 +42,33 @@ public abstract class HttpRequest
public abstract HostString Host { get; set; }

/// <summary>
/// Gets or set the owin.RequestPathBase.
/// Gets or set the RequestPathBase.
/// </summary>
/// <returns>The owin.RequestPathBase.</returns>
/// <returns>The RequestPathBase.</returns>
public abstract PathString PathBase { get; set; }

/// <summary>
/// Gets or set the request path from owin.RequestPath.
/// Gets or set the request path from RequestPath.
/// </summary>
/// <returns>The request path from owin.RequestPath.</returns>
/// <returns>The request path from RequestPath.</returns>
public abstract PathString Path { get; set; }

/// <summary>
/// Gets or set the query string from owin.RequestQueryString.
/// Gets or set the query string.
/// </summary>
/// <returns>The query string from owin.RequestQueryString.</returns>
/// <returns>The query string.</returns>
public abstract QueryString QueryString { get; set; }

/// <summary>
/// Gets the query value collection parsed from owin.RequestQueryString.
/// Gets the query value collection parsed from RequestQueryString.
/// </summary>
/// <returns>The query value collection parsed from owin.RequestQueryString.</returns>
public abstract IReadableStringCollection Query { get; set; }
/// <returns>The query value collection parsed from RequestQueryString.</returns>
public abstract IQueryCollection Query { get; set; }

/// <summary>
/// Gets or set the owin.RequestProtocol.
/// Gets or set the RequestProtocol.
/// </summary>
/// <returns>The owin.RequestProtocol.</returns>
/// <returns>The RequestProtocol.</returns>
public abstract string Protocol { get; set; }

/// <summary>
Expand All @@ -81,7 +81,7 @@ public abstract class HttpRequest
/// Gets the collection of Cookies for this request.
/// </summary>
/// <returns>The collection of Cookies for this request.</returns>
public abstract IReadableStringCollection Cookies { get; set; }
public abstract IRequestCookieCollection Cookies { get; set; }

/// <summary>
/// Gets or sets the Content-Length header
Expand All @@ -95,9 +95,9 @@ public abstract class HttpRequest
public abstract string ContentType { get; set; }

/// <summary>
/// Gets or set the owin.RequestBody Stream.
/// Gets or set the RequestBody Stream.
/// </summary>
/// <returns>The owin.RequestBody Stream.</returns>
/// <returns>The RequestBody Stream.</returns>
public abstract Stream Body { get; set; }

/// <summary>
Expand Down
86 changes: 84 additions & 2 deletions src/Microsoft.AspNet.Http.Abstractions/IFormCollection.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,95 @@
// Copyright (c) .NET Foundation. 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.Extensions.Primitives;

namespace Microsoft.AspNet.Http
{
/// <summary>
/// Contains the parsed form values.
/// Represents the parsed form values sent with the HttpRequest.
/// </summary>
public interface IFormCollection : IReadableStringCollection
public interface IFormCollection : IEnumerable<KeyValuePair<string, StringValues>>
{
/// <summary>
/// Gets the number of elements contained in the <see cref="T:Microsoft.AspNet.Http.IFormCollection" />.
/// </summary>
/// <returns>
/// The number of elements contained in the <see cref="T:Microsoft.AspNet.Http.IFormCollection" />.
/// </returns>
int Count { get; }

/// <summary>
/// Gets an <see cref="T:System.Collections.Generic.ICollection`1" /> containing the keys of the
/// <see cref="T:Microsoft.AspNet.Http.IFormCollection" />.
/// </summary>
/// <returns>
/// An <see cref="T:System.Collections.Generic.ICollection`1" /> containing the keys of the object
/// that implements <see cref="T:Microsoft.AspNet.Http.IFormCollection" />.
/// </returns>
ICollection<string> Keys { get; }

/// <summary>
/// Determines whether the <see cref="T:Microsoft.AspNet.Http.IFormCollection" /> contains an element
/// with the specified key.
/// </summary>
/// <param name="key">
/// The key to locate in the <see cref="T:Microsoft.AspNet.Http.IFormCollection" />.
/// </param>
/// <returns>
/// true if the <see cref="T:Microsoft.AspNet.Http.IFormCollection" /> contains an element with
/// the key; otherwise, false.
/// </returns>
/// <exception cref="T:System.ArgumentNullException">
/// key is null.
/// </exception>
bool ContainsKey(string key);

/// <summary>
/// Gets the value associated with the specified key.
/// </summary>
/// <param name="key">
/// The key of the value to get.
/// </param>
/// <param name="value">
/// The key of the value to get.
/// When this method returns, the value associated with the specified key, if the
/// key is found; otherwise, the default value for the type of the value parameter.
/// This parameter is passed uninitialized.
/// </param>
/// <returns>
/// true if the object that implements <see cref="T:Microsoft.AspNet.Http.IFormCollection" /> contains
/// an element with the specified key; otherwise, false.
/// </returns>
/// <exception cref="T:System.ArgumentNullException">
/// key is null.
/// </exception>
bool TryGetValue(string key, out StringValues value);

/// <summary>
/// Gets the value with the specified key.
/// </summary>
/// <param name="key">
/// The key of the value to get.
/// </param>
/// <returns>
/// The element with the specified key, or <see cref="T:Microsoft.Extensions.Primitives.StringValues" />.Empty if the key is not present.
/// </returns>
/// <exception cref="T:System.ArgumentNullException">
/// key is null.
/// </exception>
/// <remarks>
/// <see cref="T:Microsoft.AspNet.Http.IFormCollection" /> has a different indexer contract than
/// <see cref="T:System.Collections.Generic.IDictionary`2" />, as it will return StringValues.Empty for missing entries
/// rather than throwing an Exception.
/// </remarks>
StringValues this[string key] { get; }

/// <summary>
/// The file collection sent with the request.
/// </summary>
/// <param name="key"></param>
/// <returns>The files included with the request.</returns>
IFormFileCollection Files { get; }
}
}
3 changes: 3 additions & 0 deletions src/Microsoft.AspNet.Http.Abstractions/IFormFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace Microsoft.AspNet.Http
{
/// <summary>
/// Represents a file sent with the HttpRequest.
/// </summary>
public interface IFormFile
{
string ContentType { get; }
Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.AspNet.Http.Abstractions/IFormFileCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

namespace Microsoft.AspNet.Http
{
/// <summary>
/// Represents the collection of files sent with the HttpRequest.
/// </summary>
public interface IFormFileCollection : IReadOnlyList<IFormFile>
{
IFormFile this[string name] { get; }
Expand Down
88 changes: 88 additions & 0 deletions src/Microsoft.AspNet.Http.Abstractions/IQueryCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright (c) .NET Foundation. 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.Extensions.Primitives;

namespace Microsoft.AspNet.Http
{
/// <summary>
/// Represents the HttpRequest query string collection
/// </summary>
public interface IQueryCollection : IEnumerable<KeyValuePair<string, StringValues>>
{
/// <summary>
/// Gets the number of elements contained in the <see cref="T:Microsoft.AspNet.Http.IQueryCollection" />.
/// </summary>
/// <returns>
/// The number of elements contained in the <see cref="T:Microsoft.AspNet.Http.IQueryCollection" />.
/// </returns>
int Count { get; }

/// <summary>
/// Gets an <see cref="T:System.Collections.Generic.ICollection`1" /> containing the keys of the
/// <see cref="T:Microsoft.AspNet.Http.IQueryCollection" />.
/// </summary>
/// <returns>
/// An <see cref="T:System.Collections.Generic.ICollection`1" /> containing the keys of the object
/// that implements <see cref="T:Microsoft.AspNet.Http.IQueryCollection" />.
/// </returns>
ICollection<string> Keys { get; }

/// <summary>
/// Determines whether the <see cref="T:Microsoft.AspNet.Http.IQueryCollection" /> contains an element
/// with the specified key.
/// </summary>
/// <param name="key">
/// The key to locate in the <see cref="T:Microsoft.AspNet.Http.IQueryCollection" />.
/// </param>
/// <returns>
/// true if the <see cref="T:Microsoft.AspNet.Http.IQueryCollection" /> contains an element with
/// the key; otherwise, false.
/// </returns>
/// <exception cref="T:System.ArgumentNullException">
/// key is null.
/// </exception>
bool ContainsKey(string key);

/// <summary>
/// Gets the value associated with the specified key.
/// </summary>
/// <param name="key">
/// The key of the value to get.
/// </param>
/// <param name="value">
/// The key of the value to get.
/// When this method returns, the value associated with the specified key, if the
/// key is found; otherwise, the default value for the type of the value parameter.
/// This parameter is passed uninitialized.
/// </param>
/// <returns>
/// true if the object that implements <see cref="T:Microsoft.AspNet.Http.IQueryCollection" /> contains
/// an element with the specified key; otherwise, false.
/// </returns>
/// <exception cref="T:System.ArgumentNullException">
/// key is null.
/// </exception>
bool TryGetValue(string key, out StringValues value);

/// <summary>
/// Gets the value with the specified key.
/// </summary>
/// <param name="key">
/// The key of the value to get.
/// </param>
/// <returns>
/// The element with the specified key, or <see cref="T:Microsoft.Extensions.Primitives.StringValues" />.Empty if the key is not present.
/// </returns>
/// <exception cref="T:System.ArgumentNullException">
/// key is null.
/// </exception>
/// <remarks>
/// <see cref="T:Microsoft.AspNet.Http.IQueryCollection" /> has a different indexer contract than
/// <see cref="T:System.Collections.Generic.IDictionary`2" />, as it will return StringValues.Empty for missing entries
/// rather than throwing an Exception.
/// </remarks>
StringValues this[string key] { get; }
}
}

This file was deleted.

Loading