Skip to content

Commit 2bee47d

Browse files
Merge pull request #45 from aspnet/sergkanz/removeSystemNet
remove system.net.http reference
2 parents 0ff7bdd + 50ea0da commit 2bee47d

22 files changed

+663
-32
lines changed

Microsoft.AspNet.TelemetryCorrelation.sln

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{CE6B50B2-34A
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{258D5057-81B9-40EC-A872-D21E27452749}"
99
EndProject
10-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.TelemetryCorrelation", "src\Microsoft.AspNet.TelemetryCorrelation\Microsoft.AspNet.TelemetryCorrelation.csproj", "{4C8E592C-C532-4CF2-80EF-3BDD0D788D12}"
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNet.TelemetryCorrelation", "src\Microsoft.AspNet.TelemetryCorrelation\Microsoft.AspNet.TelemetryCorrelation.csproj", "{4C8E592C-C532-4CF2-80EF-3BDD0D788D12}"
1111
EndProject
12-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNet.TelemetryCorrelation.Tests", "test\Microsoft.AspNet.TelemetryCorrelation.Tests\Microsoft.AspNet.TelemetryCorrelation.Tests.csproj", "{9FAE5C43-F56C-4D87-A23C-6D2D57B4ABED}"
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNet.TelemetryCorrelation.Tests", "test\Microsoft.AspNet.TelemetryCorrelation.Tests\Microsoft.AspNet.TelemetryCorrelation.Tests.csproj", "{9FAE5C43-F56C-4D87-A23C-6D2D57B4ABED}"
1313
EndProject
1414
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{504D7010-38CC-4B07-BC57-D7030209D631}"
1515
ProjectSection(SolutionItems) = preProject
16+
tools\Common.props = tools\Common.props
1617
README.md = README.md
1718
EndProjectSection
1819
EndProject

src/Microsoft.AspNet.TelemetryCorrelation/ActivityExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Collections.Specialized;
66
using System.ComponentModel;
77
using System.Diagnostics;
8-
using System.Net.Http.Headers;
98

109
namespace Microsoft.AspNet.TelemetryCorrelation
1110
{
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace Microsoft.AspNet.TelemetryCorrelation
5+
{
6+
// Adoptation of code from https://github.com/aspnet/HttpAbstractions/blob/07d115400e4f8c7a66ba239f230805f03a14ee3d/src/Microsoft.Net.Http.Headers/BaseHeaderParser.cs
7+
internal abstract class BaseHeaderParser<T> : HttpHeaderParser<T>
8+
{
9+
protected BaseHeaderParser(bool supportsMultipleValues)
10+
: base(supportsMultipleValues)
11+
{
12+
}
13+
14+
public sealed override bool TryParseValue(string value, ref int index, out T parsedValue)
15+
{
16+
parsedValue = default(T);
17+
18+
// If multiple values are supported (i.e. list of values), then accept an empty string: The header may
19+
// be added multiple times to the request/response message. E.g.
20+
// Accept: text/xml; q=1
21+
// Accept:
22+
// Accept: text/plain; q=0.2
23+
if (string.IsNullOrEmpty(value) || (index == value.Length))
24+
{
25+
return SupportsMultipleValues;
26+
}
27+
28+
var separatorFound = false;
29+
var current = HeaderUtilities.GetNextNonEmptyOrWhitespaceIndex(value, index, SupportsMultipleValues, out separatorFound);
30+
31+
if (separatorFound && !SupportsMultipleValues)
32+
{
33+
return false; // leading separators not allowed if we don't support multiple values.
34+
}
35+
36+
if (current == value.Length)
37+
{
38+
if (SupportsMultipleValues)
39+
{
40+
index = current;
41+
}
42+
43+
return SupportsMultipleValues;
44+
}
45+
46+
T result;
47+
var length = GetParsedValueLength(value, current, out result);
48+
49+
if (length == 0)
50+
{
51+
return false;
52+
}
53+
54+
current = current + length;
55+
current = HeaderUtilities.GetNextNonEmptyOrWhitespaceIndex(value, current, SupportsMultipleValues, out separatorFound);
56+
57+
// If we support multiple values and we've not reached the end of the string, then we must have a separator.
58+
if ((separatorFound && !SupportsMultipleValues) || (!separatorFound && (current < value.Length)))
59+
{
60+
return false;
61+
}
62+
63+
index = current;
64+
parsedValue = result;
65+
return true;
66+
}
67+
68+
protected abstract int GetParsedValueLength(string value, int startIndex, out T parsedValue);
69+
}
70+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
6+
namespace Microsoft.AspNet.TelemetryCorrelation
7+
{
8+
// Adoptation of code from https://github.com/aspnet/HttpAbstractions/blob/07d115400e4f8c7a66ba239f230805f03a14ee3d/src/Microsoft.Net.Http.Headers/GenericHeaderParser.cs
9+
internal sealed class GenericHeaderParser<T> : BaseHeaderParser<T>
10+
{
11+
private GetParsedValueLengthDelegate getParsedValueLength;
12+
13+
internal GenericHeaderParser(bool supportsMultipleValues, GetParsedValueLengthDelegate getParsedValueLength)
14+
: base(supportsMultipleValues)
15+
{
16+
if (getParsedValueLength == null)
17+
{
18+
throw new ArgumentNullException(nameof(getParsedValueLength));
19+
}
20+
21+
this.getParsedValueLength = getParsedValueLength;
22+
}
23+
24+
internal delegate int GetParsedValueLengthDelegate(string value, int startIndex, out T parsedValue);
25+
26+
protected override int GetParsedValueLength(string value, int startIndex, out T parsedValue)
27+
{
28+
return getParsedValueLength(value, startIndex, out parsedValue);
29+
}
30+
}
31+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Diagnostics.Contracts;
5+
6+
namespace Microsoft.AspNet.TelemetryCorrelation
7+
{
8+
// Adoption of the code from https://github.com/aspnet/HttpAbstractions/blob/07d115400e4f8c7a66ba239f230805f03a14ee3d/src/Microsoft.Net.Http.Headers/HeaderUtilities.cs
9+
internal static class HeaderUtilities
10+
{
11+
internal static int GetNextNonEmptyOrWhitespaceIndex(
12+
string input,
13+
int startIndex,
14+
bool skipEmptyValues,
15+
out bool separatorFound)
16+
{
17+
Contract.Requires(input != null);
18+
Contract.Requires(startIndex <= input.Length); // it's OK if index == value.Length.
19+
20+
separatorFound = false;
21+
var current = startIndex + HttpRuleParser.GetWhitespaceLength(input, startIndex);
22+
23+
if ((current == input.Length) || (input[current] != ','))
24+
{
25+
return current;
26+
}
27+
28+
// If we have a separator, skip the separator and all following whitespaces. If we support
29+
// empty values, continue until the current character is neither a separator nor a whitespace.
30+
separatorFound = true;
31+
current++; // skip delimiter.
32+
current = current + HttpRuleParser.GetWhitespaceLength(input, current);
33+
34+
if (skipEmptyValues)
35+
{
36+
while ((current < input.Length) && (input[current] == ','))
37+
{
38+
current++; // skip delimiter.
39+
current = current + HttpRuleParser.GetWhitespaceLength(input, current);
40+
}
41+
}
42+
43+
return current;
44+
}
45+
}
46+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace Microsoft.AspNet.TelemetryCorrelation
5+
{
6+
// Adoptation of code from https://github.com/aspnet/HttpAbstractions/blob/07d115400e4f8c7a66ba239f230805f03a14ee3d/src/Microsoft.Net.Http.Headers/HttpHeaderParser.cs
7+
internal abstract class HttpHeaderParser<T>
8+
{
9+
private bool supportsMultipleValues;
10+
11+
protected HttpHeaderParser(bool supportsMultipleValues)
12+
{
13+
this.supportsMultipleValues = supportsMultipleValues;
14+
}
15+
16+
public bool SupportsMultipleValues
17+
{
18+
get { return supportsMultipleValues; }
19+
}
20+
21+
// If a parser supports multiple values, a call to ParseValue/TryParseValue should return a value for 'index'
22+
// pointing to the next non-whitespace character after a delimiter. E.g. if called with a start index of 0
23+
// for string "value , second_value", then after the call completes, 'index' must point to 's', i.e. the first
24+
// non-whitespace after the separator ','.
25+
public abstract bool TryParseValue(string value, ref int index, out T parsedValue);
26+
}
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
namespace Microsoft.AspNet.TelemetryCorrelation
5+
{
6+
// Adoptation of code from https://github.com/aspnet/HttpAbstractions/blob/07d115400e4f8c7a66ba239f230805f03a14ee3d/src/Microsoft.Net.Http.Headers/HttpParseResult.cs
7+
internal enum HttpParseResult
8+
{
9+
/// <summary>
10+
/// Parsed succesfully.
11+
/// </summary>
12+
Parsed,
13+
14+
/// <summary>
15+
/// Was not parsed.
16+
/// </summary>
17+
NotParsed,
18+
19+
/// <summary>
20+
/// Invalid format.
21+
/// </summary>
22+
InvalidFormat,
23+
}
24+
}

0 commit comments

Comments
 (0)