Skip to content

Commit fc8d04c

Browse files
committed
Update
1 parent 3d53004 commit fc8d04c

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

src/Grpc.AspNetCore.Server/GrpcServiceOptions.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public class GrpcServiceOptions
2929
internal IList<ICompressionProvider>? _compressionProviders;
3030
internal int? _maxReceiveMessageSize;
3131
internal int? _maxSendMessageSize;
32+
internal bool _maxSendMessageSizeSpecified;
33+
internal bool _maxReceiveMessageSizeSpecified;
3234

3335
/// <summary>
3436
/// Gets or sets the maximum message size in bytes that can be sent from the server.
@@ -51,7 +53,18 @@ public int? MaxSendMessageSize
5153
/// Gets or sets a flag indicating whether <see cref="MaxSendMessageSize"/> is specified.
5254
/// This flag is automatically set to true when <see cref="MaxSendMessageSize"/> is configured.
5355
/// </summary>
54-
public bool MaxSendMessageSizeSpecified { get; set; }
56+
public bool MaxSendMessageSizeSpecified
57+
{
58+
get => _maxSendMessageSizeSpecified;
59+
set
60+
{
61+
_maxSendMessageSizeSpecified = value;
62+
if (!_maxSendMessageSizeSpecified)
63+
{
64+
_maxSendMessageSize = null;
65+
}
66+
}
67+
}
5568

5669
/// <summary>
5770
/// Gets or sets the maximum message size in bytes that can be received by the server.
@@ -74,7 +87,18 @@ public int? MaxReceiveMessageSize
7487
/// Gets or sets a flag indicating whether <see cref="MaxReceiveMessageSize"/> is specified.
7588
/// This flag is automatically set to true when <see cref="MaxReceiveMessageSize"/> is configured.
7689
/// </summary>
77-
public bool MaxReceiveMessageSizeSpecified { get; set; }
90+
public bool MaxReceiveMessageSizeSpecified
91+
{
92+
get => _maxReceiveMessageSizeSpecified;
93+
set
94+
{
95+
_maxReceiveMessageSizeSpecified = value;
96+
if (!_maxReceiveMessageSizeSpecified)
97+
{
98+
_maxReceiveMessageSize = null;
99+
}
100+
}
101+
}
78102

79103
/// <summary>
80104
/// Gets or sets a value indicating whether detailed error messages are sent to the peer.

src/Grpc.AspNetCore.Server/Internal/GrpcServiceOptionsSetup.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ public GrpcServiceOptionsSetup(IOptions<GrpcServiceOptions> options)
5252

5353
public void Configure(GrpcServiceOptions<TService> options)
5454
{
55-
options.MaxReceiveMessageSize = _options.MaxReceiveMessageSize;
56-
options.MaxSendMessageSize = _options.MaxSendMessageSize;
55+
// Copy internal fields to avoid running logic in property setters.
56+
options._maxReceiveMessageSize = _options._maxReceiveMessageSize;
57+
options._maxReceiveMessageSizeSpecified = _options._maxReceiveMessageSizeSpecified;
58+
options._maxSendMessageSize = _options._maxSendMessageSize;
59+
options._maxSendMessageSizeSpecified = _options._maxSendMessageSizeSpecified;
60+
5761
options.EnableDetailedErrors = _options.EnableDetailedErrors;
5862
options.ResponseCompressionAlgorithm = _options.ResponseCompressionAlgorithm;
5963
options.ResponseCompressionLevel = _options.ResponseCompressionLevel;

0 commit comments

Comments
 (0)