diff --git a/samples/SampleApp/Program.cs b/samples/SampleApp/Program.cs
index 0bfe4fbd..28d24bef 100644
--- a/samples/SampleApp/Program.cs
+++ b/samples/SampleApp/Program.cs
@@ -1,30 +1,21 @@
using System;
-using System.Diagnostics;
-using Microsoft.Extensions.Primitives;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http.Extensions;
namespace SampleApp
{
public class Program
{
- public void Main(string[] args)
+ public static void Main(string[] args)
{
- for (int i = 0; i < 10; i++)
+ var query = new QueryBuilder()
{
- Stopwatch timer = new Stopwatch();
- timer.Start();
- string myString;
- string[] myArray;
- StringValues myValues;
- for (int j = 0; j < 100000000; j++)
- {
- myString = new string('a', 40);
- myArray = new[] { myString };
- // myValues = new StringValues(myString);
- myValues = new StringValues(myArray);
- }
- timer.Stop();
- Console.WriteLine(timer.Elapsed + ", " + Environment.WorkingSet);
- }
+ { "hello", "world" }
+ }.ToQueryString();
+
+ var uri = UriHelper.BuildAbsolute("http", new HostString("contoso.com"), query: query);
+
+ Console.WriteLine(uri);
}
}
}
diff --git a/samples/SampleApp/project.json b/samples/SampleApp/project.json
index 3d6d5e46..5bd99c71 100644
--- a/samples/SampleApp/project.json
+++ b/samples/SampleApp/project.json
@@ -1,12 +1,24 @@
{
"version": "1.0.0-*",
"dependencies": {
- "Microsoft.AspNetCore.Http": "1.0.0-*"
- },
- "commands": {
- "SampleApp": "SampleApp"
+ "Microsoft.AspNetCore.Http": "1.0.0-*",
+ "Microsoft.AspNetCore.Http.Extensions": "1.0.0-*"
},
"frameworks": {
- "net451": {}
+ "net451": { },
+ "netcoreapp1.0": {
+ "imports": [
+ "dnxcore50"
+ ],
+ "dependencies": {
+ "Microsoft.NETCore.App": {
+ "version": "1.0.0-*",
+ "type": "platform"
+ }
+ }
+ }
+ },
+ "buildOptions": {
+ "emitEntryPoint": true
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNetCore.Http.Extensions/UriHelper.cs b/src/Microsoft.AspNetCore.Http.Extensions/UriHelper.cs
index e7a7eb20..2c8c0f68 100644
--- a/src/Microsoft.AspNetCore.Http.Extensions/UriHelper.cs
+++ b/src/Microsoft.AspNetCore.Http.Extensions/UriHelper.cs
@@ -16,12 +16,12 @@ public static class UriHelper
///
/// Combines the given URI components into a string that is properly encoded for use in HTTP headers.
///
- ///
- ///
- ///
- ///
+ /// The first portion of the request path associated with application root.
+ /// The portion of the request path that identifies the requested resource.
+ /// The query, if any.
+ /// The fragment, if any.
///
- public static string Encode(
+ public static string BuildRelative(
PathString pathBase = new PathString(),
PathString path = new PathString(),
QueryString query = new QueryString(),
@@ -35,14 +35,14 @@ public static string Encode(
/// Combines the given URI components into a string that is properly encoded for use in HTTP headers.
/// Note that unicode in the HostString will be encoded as punycode.
///
- ///
- ///
- ///
- ///
- ///
- ///
+ /// http, https, etc.
+ /// The host portion of the uri normally included in the Host header. This may include the port.
+ /// The first portion of the request path associated with application root.
+ /// The portion of the request path that identifies the requested resource.
+ /// The query, if any.
+ /// The fragment, if any.
///
- public static string Encode(
+ public static string BuildAbsolute(
string scheme,
HostString host,
PathString pathBase = new PathString(),
@@ -74,13 +74,13 @@ public static string Encode(
/// Generates a string from the given absolute or relative Uri that is appropriately encoded for use in
/// HTTP headers. Note that a unicode host name will be encoded as punycode.
///
- ///
+ /// The Uri to encode.
///
public static string Encode(Uri uri)
{
if (uri.IsAbsoluteUri)
{
- return Encode(
+ return BuildAbsolute(
scheme: uri.Scheme,
host: HostString.FromUriComponent(uri),
pathBase: PathString.FromUriComponent(uri),
@@ -97,18 +97,18 @@ public static string Encode(Uri uri)
/// Returns the combined components of the request URL in a fully escaped form suitable for use in HTTP headers
/// and other HTTP operations.
///
- ///
+ /// The request to assemble the uri pieces from.
///
public static string GetEncodedUrl(this HttpRequest request)
{
- return Encode(request.Scheme, request.Host, request.PathBase, request.Path, request.QueryString);
+ return BuildAbsolute(request.Scheme, request.Host, request.PathBase, request.Path, request.QueryString);
}
///
/// Returns the combined components of the request URL in a fully un-escaped form (except for the QueryString)
/// suitable only for display. This format should not be used in HTTP headers or other HTTP operations.
///
- ///
+ /// The request to assemble the uri pieces from.
///
public static string GetDisplayUrl(this HttpRequest request)
{
diff --git a/test/Microsoft.AspNetCore.Http.Extensions.Tests/UriHelperTests.cs b/test/Microsoft.AspNetCore.Http.Extensions.Tests/UriHelperTests.cs
index 06c4f4a3..0b0aeda6 100644
--- a/test/Microsoft.AspNetCore.Http.Extensions.Tests/UriHelperTests.cs
+++ b/test/Microsoft.AspNetCore.Http.Extensions.Tests/UriHelperTests.cs
@@ -10,7 +10,7 @@ public class UriHelperTests
[Fact]
public void EncodeEmptyPartialUrl()
{
- var result = UriHelper.Encode();
+ var result = UriHelper.BuildRelative();
Assert.Equal("/", result);
}
@@ -18,7 +18,7 @@ public void EncodeEmptyPartialUrl()
[Fact]
public void EncodePartialUrl()
{
- var result = UriHelper.Encode(new PathString("/un?escaped/base"), new PathString("/un?escaped"),
+ var result = UriHelper.BuildRelative(new PathString("/un?escaped/base"), new PathString("/un?escaped"),
new QueryString("?name=val%23ue"), new FragmentString("#my%20value"));
Assert.Equal("/un%3Fescaped/base/un%3Fescaped?name=val%23ue#my%20value", result);
@@ -27,7 +27,7 @@ public void EncodePartialUrl()
[Fact]
public void EncodeEmptyFullUrl()
{
- var result = UriHelper.Encode("http", new HostString(string.Empty));
+ var result = UriHelper.BuildAbsolute("http", new HostString(string.Empty));
Assert.Equal("http:///", result);
}
@@ -35,7 +35,7 @@ public void EncodeEmptyFullUrl()
[Fact]
public void EncodeFullUrl()
{
- var result = UriHelper.Encode("http", new HostString("my.HoΨst:80"), new PathString("/un?escaped/base"), new PathString("/un?escaped"),
+ var result = UriHelper.BuildAbsolute("http", new HostString("my.HoΨst:80"), new PathString("/un?escaped/base"), new PathString("/un?escaped"),
new QueryString("?name=val%23ue"), new FragmentString("#my%20value"));
Assert.Equal("http://my.xn--host-cpd:80/un%3Fescaped/base/un%3Fescaped?name=val%23ue#my%20value", result);