Skip to content

Commit d0450a6

Browse files
committed
added a server property for 'maxInboundMetadataSize'
1 parent 256efeb commit d0450a6

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

grpc-server-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/server/config/GrpcServerProperties.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ public class GrpcServerProperties {
160160
@DataSizeUnit(DataUnit.BYTES)
161161
private DataSize maxInboundMessageSize = null;
162162

163+
/**
164+
* The maximum size of metadata allowed to be received. If not set ({@code null}) then
165+
* {@link GrpcUtil#DEFAULT_MAX_HEADER_LIST_SIZE gRPC's default} should be used.
166+
*
167+
*/
168+
@DataSizeUnit(DataUnit.BYTES)
169+
private DataSize maxInboundMetadataSize = null;
170+
163171
/**
164172
* Whether gRPC health service is enabled or not. Defaults to {@code true}.
165173
*
@@ -313,4 +321,14 @@ public void setMaxInboundMessageSize(final DataSize maxInboundMessageSize) {
313321
}
314322
}
315323

324+
public void setmaxInboundMetadataSize(final DataSize maxInboundMetadataSize) {
325+
if (maxInboundMetadataSize == null || maxInboundMetadataSize.toBytes() >= 0) {
326+
this.maxInboundMetadataSize = maxInboundMetadataSize;
327+
} else if (maxInboundMetadataSize.toBytes() == -1) {
328+
this.maxInboundMetadataSize = DataSize.ofBytes(Integer.MAX_VALUE);
329+
} else {
330+
throw new IllegalArgumentException("Unsupported maxInboundMetadataSize: " + maxInboundMetadataSize);
331+
}
332+
}
333+
316334
}

grpc-server-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/server/serverfactory/AbstractGrpcServerFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ protected void configureLimits(final T builder) {
151151
if (maxInboundMessageSize != null) {
152152
builder.maxInboundMessageSize((int) maxInboundMessageSize.toBytes());
153153
}
154+
final DataSize maxInboundMetadataSize = this.properties.getMaxInboundMetadataSize();
155+
if (maxInboundMetadataSize != null) {
156+
builder.maxInboundMetadataSize((int) maxInboundMetadataSize.toBytes());
157+
}
154158
}
155159

156160
@Override

grpc-server-spring-boot-autoconfigure/src/test/java/net/devh/boot/grpc/server/config/GrpcServerPropertiesGivenUnitTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
@ExtendWith(SpringExtension.class)
3535
@SpringBootTest(properties = {
3636
"grpc.server.keepAliveTime=42m",
37-
"grpc.server.maxInboundMessageSize=5MB"
37+
"grpc.server.maxInboundMessageSize=5MB",
38+
"grpc.server.maxInboundMetadataSize=10KB"
3839
})
3940
class GrpcServerPropertiesGivenUnitTest {
4041

@@ -45,6 +46,7 @@ class GrpcServerPropertiesGivenUnitTest {
4546
void test() {
4647
assertEquals(Duration.ofMinutes(42), this.grpcServerProperties.getKeepAliveTime());
4748
assertEquals(DataSize.ofMegabytes(5), this.grpcServerProperties.getMaxInboundMessageSize());
49+
assertEquals(DataSize.ofKilobytes(10), this.grpcServerProperties.getMaxInboundMetadataSize());
4850
}
4951

5052
}

0 commit comments

Comments
 (0)