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

Commit 6f50c43

Browse files
committed
#573 Rename UriHelper.Encode
1 parent 8b3c308 commit 6f50c43

File tree

4 files changed

+38
-30
lines changed

4 files changed

+38
-30
lines changed

samples/SampleApp/Program.cs

+11-20
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
11
using System;
2-
using System.Diagnostics;
3-
using Microsoft.Extensions.Primitives;
2+
using Microsoft.AspNetCore.Http;
3+
using Microsoft.AspNetCore.Http.Extensions;
44

55
namespace SampleApp
66
{
7-
public class Program
7+
public static class Program
88
{
9-
public void Main(string[] args)
9+
public static void Main(string[] args)
1010
{
11-
for (int i = 0; i < 10; i++)
11+
var query = new QueryBuilder()
1212
{
13-
Stopwatch timer = new Stopwatch();
14-
timer.Start();
15-
string myString;
16-
string[] myArray;
17-
StringValues myValues;
18-
for (int j = 0; j < 100000000; j++)
19-
{
20-
myString = new string('a', 40);
21-
myArray = new[] { myString };
22-
// myValues = new StringValues(myString);
23-
myValues = new StringValues(myArray);
24-
}
25-
timer.Stop();
26-
Console.WriteLine(timer.Elapsed + ", " + Environment.WorkingSet);
27-
}
13+
{ "hello", "world" }
14+
}.ToQueryString();
15+
16+
var uri = UriHelper.BuildAbsolute("http", new HostString("contoso.com"), query: query);
17+
18+
Console.WriteLine(uri);
2819
}
2920
}
3021
}

samples/SampleApp/project.json

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
{
22
"version": "1.0.0-*",
33
"dependencies": {
4-
"Microsoft.AspNetCore.Http": "1.0.0-*"
4+
"Microsoft.NETCore.Platforms": "1.0.1-*",
5+
"Microsoft.AspNetCore.Http": "1.0.0-*",
6+
"Microsoft.AspNetCore.Http.Extensions": "1.0.0-*"
57
},
68
"commands": {
79
"SampleApp": "SampleApp"
810
},
911
"frameworks": {
10-
"net451": {}
12+
"net451": { },
13+
"netcoreapp1.0": {
14+
"imports": [
15+
"dnxcore50"
16+
],
17+
"dependencies": {
18+
"System.Console": "4.0.0-*",
19+
"Microsoft.NETCore.App": {
20+
"version": "1.0.0-*",
21+
"type": "platform"
22+
}
23+
}
24+
}
25+
},
26+
"buildOptions": {
27+
"emitEntryPoint": true
1128
}
1229
}

src/Microsoft.AspNetCore.Http.Extensions/UriHelper.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static class UriHelper
2121
/// <param name="query"></param>
2222
/// <param name="fragment"></param>
2323
/// <returns></returns>
24-
public static string Encode(
24+
public static string BuildRelative(
2525
PathString pathBase = new PathString(),
2626
PathString path = new PathString(),
2727
QueryString query = new QueryString(),
@@ -42,7 +42,7 @@ public static string Encode(
4242
/// <param name="query"></param>
4343
/// <param name="fragment"></param>
4444
/// <returns></returns>
45-
public static string Encode(
45+
public static string BuildAbsolute(
4646
string scheme,
4747
HostString host,
4848
PathString pathBase = new PathString(),
@@ -80,7 +80,7 @@ public static string Encode(Uri uri)
8080
{
8181
if (uri.IsAbsoluteUri)
8282
{
83-
return Encode(
83+
return BuildAbsolute(
8484
scheme: uri.Scheme,
8585
host: HostString.FromUriComponent(uri),
8686
pathBase: PathString.FromUriComponent(uri),
@@ -101,7 +101,7 @@ public static string Encode(Uri uri)
101101
/// <returns></returns>
102102
public static string GetEncodedUrl(this HttpRequest request)
103103
{
104-
return Encode(request.Scheme, request.Host, request.PathBase, request.Path, request.QueryString);
104+
return BuildAbsolute(request.Scheme, request.Host, request.PathBase, request.Path, request.QueryString);
105105
}
106106

107107
/// <summary>

test/Microsoft.AspNetCore.Http.Extensions.Tests/UriHelperTests.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ public class UriHelperTests
1010
[Fact]
1111
public void EncodeEmptyPartialUrl()
1212
{
13-
var result = UriHelper.Encode();
13+
var result = UriHelper.BuildRelative();
1414

1515
Assert.Equal("/", result);
1616
}
1717

1818
[Fact]
1919
public void EncodePartialUrl()
2020
{
21-
var result = UriHelper.Encode(new PathString("/un?escaped/base"), new PathString("/un?escaped"),
21+
var result = UriHelper.BuildRelative(new PathString("/un?escaped/base"), new PathString("/un?escaped"),
2222
new QueryString("?name=val%23ue"), new FragmentString("#my%20value"));
2323

2424
Assert.Equal("/un%3Fescaped/base/un%3Fescaped?name=val%23ue#my%20value", result);
@@ -27,15 +27,15 @@ public void EncodePartialUrl()
2727
[Fact]
2828
public void EncodeEmptyFullUrl()
2929
{
30-
var result = UriHelper.Encode("http", new HostString(string.Empty));
30+
var result = UriHelper.BuildAbsolute("http", new HostString(string.Empty));
3131

3232
Assert.Equal("http:///", result);
3333
}
3434

3535
[Fact]
3636
public void EncodeFullUrl()
3737
{
38-
var result = UriHelper.Encode("http", new HostString("my.HoΨst:80"), new PathString("/un?escaped/base"), new PathString("/un?escaped"),
38+
var result = UriHelper.BuildAbsolute("http", new HostString("my.HoΨst:80"), new PathString("/un?escaped/base"), new PathString("/un?escaped"),
3939
new QueryString("?name=val%23ue"), new FragmentString("#my%20value"));
4040

4141
Assert.Equal("http://my.xn--host-cpd:80/un%3Fescaped/base/un%3Fescaped?name=val%23ue#my%20value", result);

0 commit comments

Comments
 (0)