-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
699 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/Grpc.AspNetCore.Server/Internal/NotNullWhenAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#region Copyright notice and license | ||
|
||
// Copyright 2019 The gRPC Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#endregion | ||
|
||
namespace System.Runtime.CompilerServices | ||
{ | ||
/// <summary>Specifies that when a method returns <see cref="ReturnValue"/>, the parameter will not be null even if the corresponding type allows it.</summary> | ||
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)] | ||
internal sealed class NotNullWhenAttribute : Attribute | ||
{ | ||
/// <summary>Initializes the attribute with the specified return value condition.</summary> | ||
/// <param name="returnValue"> | ||
/// The return value condition. If the method returns this value, the associated parameter will not be null. | ||
/// </param> | ||
public NotNullWhenAttribute(bool returnValue) => ReturnValue = returnValue; | ||
|
||
/// <summary>Gets the return value condition.</summary> | ||
public bool ReturnValue { get; } | ||
} | ||
} |
26 changes: 0 additions & 26 deletions
26
src/Grpc.AspNetCore.Server/Internal/NotNullWhenTrueAttribute.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/Grpc.Net.Client/Internal/Compression/GzipCompressionProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#region Copyright notice and license | ||
|
||
// Copyright 2019 The gRPC Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#endregion | ||
|
||
using System.IO; | ||
using System.IO.Compression; | ||
|
||
namespace Grpc.Net.Client.Internal.Compression | ||
{ | ||
/// <summary> | ||
/// GZIP compression provider. | ||
/// </summary> | ||
internal class GzipCompressionProvider : ICompressionProvider | ||
{ | ||
private readonly CompressionLevel _defaultCompressionLevel; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="GzipCompressionProvider"/> class with the specified <see cref="CompressionLevel"/>. | ||
/// </summary> | ||
/// <param name="defaultCompressionLevel">The default compression level to use when compressing data.</param> | ||
public GzipCompressionProvider(CompressionLevel defaultCompressionLevel) | ||
{ | ||
_defaultCompressionLevel = defaultCompressionLevel; | ||
} | ||
|
||
/// <summary> | ||
/// The encoding name used in the 'grpc-encoding' and 'grpc-accept-encoding' request and response headers. | ||
/// </summary> | ||
public string EncodingName => "gzip"; | ||
|
||
/// <summary> | ||
/// Create a new compression stream. | ||
/// </summary> | ||
/// <param name="stream">The stream that compressed data is written to.</param> | ||
/// <param name="compressionLevel">The compression level.</param> | ||
/// <returns>A stream used to compress data.</returns> | ||
public Stream CreateCompressionStream(Stream stream, CompressionLevel? compressionLevel) | ||
{ | ||
return new GZipStream(stream, compressionLevel ?? _defaultCompressionLevel); | ||
} | ||
|
||
/// <summary> | ||
/// Create a new decompression stream. | ||
/// </summary> | ||
/// <param name="stream">The stream that compressed data is copied from.</param> | ||
/// <returns>A stream used to decompress data.</returns> | ||
public Stream CreateDecompressionStream(Stream stream) | ||
{ | ||
return new GZipStream(stream, CompressionMode.Decompress); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Grpc.Net.Client/Internal/Compression/ICompressionProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#region Copyright notice and license | ||
|
||
// Copyright 2019 The gRPC Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#endregion | ||
|
||
using System.IO; | ||
using System.IO.Compression; | ||
|
||
namespace Grpc.Net.Client.Internal.Compression | ||
{ | ||
/// <summary> | ||
/// Provides a specific compression implementation to compress gRPC messages. | ||
/// </summary> | ||
internal interface ICompressionProvider | ||
{ | ||
/// <summary> | ||
/// The encoding name used in the 'grpc-encoding' and 'grpc-accept-encoding' request and response headers. | ||
/// </summary> | ||
string EncodingName { get; } | ||
|
||
/// <summary> | ||
/// Create a new compression stream. | ||
/// </summary> | ||
/// <param name="stream">The stream that compressed data is written to.</param> | ||
/// <param name="compressionLevel">The compression level.</param> | ||
/// <returns>A stream used to compress data.</returns> | ||
Stream CreateCompressionStream(Stream stream, CompressionLevel? compressionLevel); | ||
|
||
/// <summary> | ||
/// Create a new decompression stream. | ||
/// </summary> | ||
/// <param name="stream">The stream that compressed data is copied from.</param> | ||
/// <returns>A stream used to decompress data.</returns> | ||
Stream CreateDecompressionStream(Stream stream); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.