Skip to content

Commit 9694804

Browse files
authored
Merge pull request #88 from launchdarkly/eb/sc-154188/drop-old-platforms
drop .NET Framework 4.5.2/4.6.1 and don't test in EOL platforms
2 parents b90604c + 219307d commit 9694804

File tree

13 files changed

+137
-124
lines changed

13 files changed

+137
-124
lines changed

.circleci/config.yml

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,20 @@ workflows:
77
version: 2
88
test:
99
jobs:
10-
- test-netcore:
11-
name: .NET Core 2.1
12-
docker-image: mcr.microsoft.com/dotnet/core/sdk:2.1-focal
13-
test-target-framework: netcoreapp2.1
14-
- test-netcore:
10+
- test_linux:
1511
name: .NET Core 3.1
1612
docker-image: mcr.microsoft.com/dotnet/core/sdk:3.1-focal
1713
test-target-framework: netcoreapp3.1
18-
- test-netcore:
19-
name: .NET 5.0
20-
docker-image: mcr.microsoft.com/dotnet/sdk:5.0-focal
21-
test-target-framework: net5.0
22-
- test-windows-netframework:
23-
name: .NET Framework 4.5.2
24-
test-target-framework: net452
25-
- test-windows-netframework:
26-
name: .NET Framework 4.6.1
27-
test-target-framework: net461
14+
- test_linux:
15+
name: .NET 6.0
16+
docker-image: mcr.microsoft.com/dotnet/sdk:6.0-focal
17+
test-target-framework: net6.0
18+
- test_windows:
19+
name: .NET Framework 4.6.2
20+
test-target-framework: net462
2821

2922
jobs:
30-
test-netcore:
23+
test_linux:
3124
parameters:
3225
docker-image:
3326
type: string
@@ -43,10 +36,19 @@ jobs:
4336
name: install packages
4437
command: apt-get -q update && apt-get install -qy awscli
4538
- checkout
46-
- run: dotnet build src/LaunchDarkly.EventSource -f netstandard2.0
47-
- run: dotnet test test/LaunchDarkly.EventSource.Tests/LaunchDarkly.EventSource.Tests.csproj
39+
- run:
40+
name: build
41+
command: dotnet build src/LaunchDarkly.EventSource -f netstandard2.0
42+
- run:
43+
name: run tests
44+
command: |
45+
dotnet test \
46+
-l "junit;LogFilePath=/tmp/circle-reports/unit-tests-commonsdk.xml" \
47+
test/LaunchDarkly.EventSource.Tests/LaunchDarkly.EventSource.Tests.csproj
48+
- store_test_results:
49+
path: /tmp/circle-reports
4850

49-
test-windows-netframework:
51+
test_windows:
5052
parameters:
5153
test-target-framework:
5254
type: string
@@ -57,5 +59,14 @@ jobs:
5759
TESTFRAMEWORK: <<parameters.test-target-framework>>
5860
steps:
5961
- checkout
60-
- run: dotnet build src/LaunchDarkly.EventSource
61-
- run: dotnet test test/LaunchDarkly.EventSource.Tests/LaunchDarkly.EventSource.Tests.csproj
62+
- run:
63+
name: build
64+
command: dotnet build src/LaunchDarkly.EventSource
65+
- run:
66+
name: run tests
67+
command: |
68+
dotnet test \
69+
-l "junit;LogFilePath=/tmp/circle-reports/unit-tests-commonsdk.xml" \
70+
test/LaunchDarkly.EventSource.Tests/LaunchDarkly.EventSource.Tests.csproj
71+
- store_test_results:
72+
path: /tmp/circle-reports

.ldrelease/config.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ publications:
66

77
branches:
88
- name: main
9-
description: 4.x - for .NET SDK 6.0+ and Xamarin SDK 2.0+
9+
description: 5.x - for server-side .NET SDK 7.0+ and client-side .NET SDK 3.0+
10+
- name: 4.x
11+
description: for .NET SDK 6.0+ and Xamarin SDK 2.0+
1012
- name: 3.x
1113
description: for earlier .NET and Xamarin SDKs
1214

1315
jobs:
1416
- template:
15-
name: dotnet-linux
17+
name: dotnet6-linux
1618
env:
1719
LD_RELEASE_DOCS_TARGET_FRAMEWORK: netstandard2.0
18-
LD_RELEASE_TEST_TARGET_FRAMEWORK: net5.0
20+
LD_RELEASE_TEST_TARGET_FRAMEWORK: net6.0
1921

2022
documentation:
2123
gitHubPages: true

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ To run all unit tests, for all targets:
4444
dotnet test test/LaunchDarkly.EventSource.Tests
4545
```
4646

47-
Or, to run tests only for the .NET Standard 2.0 target (using the .NET Core 2.1 runtime):
47+
Or, to run tests only for the .NET Standard 2.0 target (using the .NET Core 3.1 runtime):
4848

4949
```
50-
dotnet test test/LaunchDarkly.EventSource.Tests -f netcoreapp2.1
50+
dotnet test test/LaunchDarkly.EventSource.Tests -f netcoreapp3.1
5151
```
5252

5353
Note that the unit tests can only be run in Debug configuration. There is an `InternalsVisibleTo` directive that allows the test code to access internal members of the library, and assembly strong-naming in the Release configuration interferes with this.

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ The `LaunchDarkly.EventSource` package allows .NET developers to consume Server-
1212

1313
This version of the library is built for the following targets:
1414

15-
* .NET Framework 4.5.2: runs on .NET Framework 4.5.x and above.
16-
* .NET Core 2.1: runs on .NET Core 2.x and 3.x, or .NET 5. This target provides an adapter to the standard .NET Core logging framework, `Logs.CoreLogging`, which is not available in .NET Framework.
17-
* .NET Standard 2.0: runs on .NET Core 2.x and 3.x or .NET 5, or within a library that is targeted to .NET Standard 2.x.
15+
* .NET Framework 4.6.2: runs on .NET Framework 4.6.2 and above.
16+
* .NET Standard 2.0: runs on .NET Core 3.x or .NET 6.0+, or within a library that is targeted to .NET Standard 2.x.
1817

1918
The .NET build tools should automatically load the most appropriate build of the library for whatever platform your application or library is targeted to.
2019

src/LaunchDarkly.EventSource/Configuration.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ public sealed class Configuration
7474
[Obsolete("Use ResponseStartTimeout")]
7575
public TimeSpan ConnectionTimeout => ResponseStartTimeout;
7676

77-
/// <summary>
78-
/// The character encoding to use when reading the stream if the server did not specify
79-
/// an encoding in a <c>Content-Type</c> header.
80-
/// </summary>
81-
/// <seealso cref="ConfigurationBuilder.DefaultEncoding(Encoding)"/>
82-
public Encoding DefaultEncoding { get; }
83-
8477
/// <summary>
8578
/// The HttpClient that will be used as the HTTP client, or null for a new HttpClient.
8679
/// </summary>
@@ -183,7 +176,6 @@ internal Configuration(ConfigurationBuilder builder)
183176
(builder._logAdapter is null ? null : builder._logAdapter.Logger(Configuration.DefaultLoggerName));
184177

185178
BackoffResetThreshold = builder._backoffResetThreshold;
186-
DefaultEncoding = builder._defaultEncoding ?? Encoding.UTF8;
187179
HttpClient = builder._httpClient;
188180
HttpMessageHandler = (builder._httpClient != null) ? null : builder._httpMessageHandler;
189181
InitialRetryDelay = builder._initialRetryDelay;

src/LaunchDarkly.EventSource/ConfigurationBuilder.cs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public class ConfigurationBuilder
2828
#region Private Fields
2929

3030
internal readonly Uri _uri;
31-
internal Encoding _defaultEncoding = Encoding.UTF8;
3231
internal TimeSpan _initialRetryDelay = Configuration.DefaultInitialRetryDelay;
3332
internal TimeSpan _backoffResetThreshold = Configuration.DefaultBackoffResetThreshold;
3433
internal string _lastEventId;
@@ -89,21 +88,6 @@ public ConfigurationBuilder HttpRequestModifier(Action<HttpRequestMessage> httpR
8988
return this;
9089
}
9190

92-
/// <summary>
93-
/// Sets the character encoding to use when reading the stream if the server did not specify
94-
/// an encoding in a <c>Content-Type</c> header.
95-
/// </summary>
96-
/// <param name="defaultEncoding">A <c>System.Text.Encoding</c>; if null, the default
97-
/// is <see cref="Encoding.UTF8"/></param>
98-
/// <returns>the builder</returns>
99-
/// <seealso cref="MessageEvent"/>
100-
/// <seealso cref="PreferDataAsUtf8Bytes"/>
101-
public ConfigurationBuilder DefaultEncoding(Encoding defaultEncoding)
102-
{
103-
_defaultEncoding = defaultEncoding ?? Encoding.UTF8;
104-
return this;
105-
}
106-
10791
/// <summary>
10892
/// Sets the initial amount of time to wait before attempting to reconnect to the EventSource API.
10993
/// </summary>
@@ -320,17 +304,14 @@ public ConfigurationBuilder Logger(Logger logger)
320304
/// preferable to store and process event data as UTF-8 byte arrays rather than
321305
/// strings. By default, <c>EventSource</c> will use the <c>string</c> type when
322306
/// processing the event stream; if you then use <see cref="MessageEvent.DataUtf8Bytes"/>
323-
/// to get the data, it will be converted to a byte array as needed. It will also
324-
/// always use the <c>string</c> type internally if the stream's encoding is not
325-
/// UTF-8. However, if the stream's encoding is UTF-8 <c>and</c> you have set
326-
/// <c>PreferDataAsUtf8Bytes</c> to <see langword="true"/>, the event data will
327-
/// be stored internally as a UTF-8 byte array so that if you read
307+
/// to get the data, it will be converted to a byte array as needed. However, if
308+
/// you set <c>PreferDataAsUtf8Bytes</c> to <see langword="true"/>, the event data
309+
/// will be stored internally as a UTF-8 byte array so that if you read
328310
/// <see cref="MessageEvent.DataUtf8Bytes"/>, you will get the same array with no
329311
/// extra copying or conversion. Therefore, for greatest efficiency you should set
330-
/// this to <see langword="true"/> if you intend to process the data as UTF-8 and
331-
/// if you expect that the server will provide it in that encoding. If the server
332-
/// turns out not to use that encoding, everything will still work the same except
333-
/// that there will be more overhead from string conversion.
312+
/// this to <see langword="true"/> if you intend to process the data as UTF-8. Note
313+
/// that Server-Sent Event streams always use UTF-8 encoding, as required by the
314+
/// SSE specification.
334315
/// </remarks>
335316
/// <param name="preferDataAsUtf8Bytes">true if you intend to request the event
336317
/// data as UTF-8 bytes</param>

src/LaunchDarkly.EventSource/EventSourceService.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,25 @@ CancellationToken cancellationToken
100100
_logger.Debug("Response status: {0}", (int)response.StatusCode);
101101
ValidateResponse(response);
102102

103-
OnConnectionOpened();
104-
105103
using (var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
106104
{
107105
var encoding = DetectEncoding(response);
108-
if (encoding == Encoding.UTF8 && _configuration.PreferDataAsUtf8Bytes)
106+
if (encoding != Encoding.UTF8)
107+
{
108+
throw new EventSourceServiceCancelledException(
109+
string.Format(Resources.ErrorWrongEncoding, encoding.HeaderName));
110+
}
111+
OnConnectionOpened();
112+
113+
if (_configuration.PreferDataAsUtf8Bytes)
109114
{
110115
_logger.Debug("Reading UTF-8 stream without string conversion");
111116
await ProcessResponseFromUtf8StreamAsync(processResponseLineUTF8, stream, cancellationToken);
112117
}
113118
else
114119
{
115-
_logger.Debug("Reading stream with {0} encoding and string conversion", encoding.EncodingName);
116-
using (var reader = new StreamReader(stream, encoding))
120+
_logger.Debug("Reading stream with string conversion");
121+
using (var reader = new StreamReader(stream, Encoding.UTF8))
117122
{
118123
await ProcessResponseFromReaderAsync(processResponseLineString, reader, cancellationToken);
119124
}
@@ -135,7 +140,7 @@ private Encoding DetectEncoding(HttpResponseMessage response)
135140
}
136141
catch (ArgumentException) { }
137142
}
138-
return _configuration.DefaultEncoding ?? Encoding.UTF8;
143+
return Encoding.UTF8;
139144
}
140145

141146
protected virtual async Task ProcessResponseFromReaderAsync(

src/LaunchDarkly.EventSource/LaunchDarkly.EventSource.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<Version>4.2.0</Version>
4-
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
55
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
66
<AssemblyName>LaunchDarkly.EventSource</AssemblyName>
77
<DebugType>portable</DebugType>
@@ -21,7 +21,7 @@
2121
<PackageReference Include="LaunchDarkly.Logging" Version="[1.0.1,2.0.0)" />
2222
</ItemGroup>
2323

24-
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
24+
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
2525
<Reference Include="System" />
2626
<Reference Include="Microsoft.CSharp" />
2727
<Reference Include="System.Net.Http" />

src/LaunchDarkly.EventSource/MessageEvent.cs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,12 @@ namespace LaunchDarkly.EventSource
1919
/// <para>
2020
/// Since strings in .NET use two-byte UTF-16 characters, if you have a large block of
2121
/// UTF-8 data it is considerably more efficient to process it in its original form
22-
/// rather than converting it to or from a string. <c>MessageEvent</c> converts
23-
/// transparently between these types depending on the original character encoding of
24-
/// the stream; the <see cref="Configuration"/> properties <see cref="Configuration.DefaultEncoding"/>
25-
/// and <see cref="Configuration.PreferDataAsUtf8Bytes"/>; and whether the caller reads
26-
/// from the property <see cref="MessageEvent.Data"/> or <see cref="MessageEvent.DataUtf8Bytes"/>.
27-
/// If you intend to process the data as UTF-8 bytes, and if you expect that the server
28-
/// will provide UTF-8, you should set
22+
/// rather than converting it to or from a string. <see cref="EventSource"/> stores
23+
/// data as strings by default, but you set <see cref="ConfigurationBuilder.PreferDataAsUtf8Bytes(bool)"/>
24+
/// it can store the raw UTF-8 data instead. In either case, <c>MessageEvent</c> will
25+
/// convert types transparently so that you can read either <see cref="MessageEvent.Data"/>
26+
/// or <see cref="MessageEvent.DataUtf8Bytes"/>.
2927
/// </para>
30-
/// <list type="bullet">
31-
/// <item> If the stream encoding is UTF-8, and you read the event data with the
32-
/// <see cref="MessageEvent.DataUtf8Bytes"/> property, the event data is stored as a
33-
/// UTF-8 byte array when it is first read from the stream and it returns the same
34-
/// array, without any further copying and without creating a <c>string</c>. </item>
35-
/// <item> If the stream encoding is UTF-8, but you read the event data with the
36-
/// <see cref="MessageEvent.Data"/> property, the event data is originally read from
37-
/// the stream as a UTF-8 byte array but is then converted to a <c>string</c>. </item>
38-
/// <item> If the stream encoding is not UTF-8, the event data is originally read from
39-
/// the stream as a <c>string</c>. <see cref="MessageEvent.Data"/> will return the
40-
/// same <c>string</c>; <see cref="MessageEvent.DataUtf8Bytes"/> will create a new
41-
/// UTF-8 byte array from it.</item>
42-
/// </list>
4328
/// </remarks>
4429
public struct MessageEvent
4530
{

0 commit comments

Comments
 (0)