Skip to content

Commit e25665c

Browse files
committed
fix: Restore the shutdownTimeoutSeconds javadoc
The two content-coding setters were inserted between that javadoc and the method it documents, so it bound to nothing and shutdownTimeoutSeconds lost its documentation. Moves it back and folds the cap's two range checks into the one range they describe. Also un-nests the ternary that resolving a byte body's content type had grown, which SonarQube flags as S3358 on new code.
1 parent 059b0ef commit e25665c

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

src/main/java/com/retailsvc/http/OpenApiServer.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -391,24 +391,15 @@ public Builder https(Path certificateChainPem, Path privateKeyPem) {
391391
return this;
392392
}
393393

394-
/**
395-
* Sets the default drain timeout used by {@link OpenApiServer#close()}. {@code 0} (the default)
396-
* stops immediately; positive values wait up to that many seconds for in-flight exchanges to
397-
* finish.
398-
*/
399394
/**
400395
* Ceiling on the inflated size of a gzip request body, 10 MiB by default. A compressed payload
401396
* can expand by orders of magnitude, so this bounds what a single request may allocate;
402397
* exceeding it fails the request with 413. Bodies that arrive uncompressed are not affected.
403398
*/
404399
public Builder maxDecompressedRequestBytes(long maxDecompressedRequestBytes) {
405-
if (maxDecompressedRequestBytes <= 0) {
406-
throw new IllegalArgumentException(
407-
"maxDecompressedRequestBytes must be positive, got " + maxDecompressedRequestBytes);
408-
}
409-
if (maxDecompressedRequestBytes > Integer.MAX_VALUE) {
400+
if (maxDecompressedRequestBytes <= 0 || maxDecompressedRequestBytes > Integer.MAX_VALUE) {
410401
throw new IllegalArgumentException(
411-
"maxDecompressedRequestBytes must not exceed "
402+
"maxDecompressedRequestBytes must be between 1 and "
412403
+ Integer.MAX_VALUE
413404
+ ", got "
414405
+ maxDecompressedRequestBytes);
@@ -432,6 +423,11 @@ public Builder minimumGzipResponseBytes(long minimumGzipResponseBytes) {
432423
return this;
433424
}
434425

426+
/**
427+
* Sets the default drain timeout used by {@link OpenApiServer#close()}. {@code 0} (the default)
428+
* stops immediately; positive values wait up to that many seconds for in-flight exchanges to
429+
* finish.
430+
*/
435431
public Builder shutdownTimeoutSeconds(int shutdownTimeoutSeconds) {
436432
if (shutdownTimeoutSeconds < 0) {
437433
throw new IllegalArgumentException(

src/main/java/com/retailsvc/http/internal/ResponseRenderer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ private static long declaredLength(Headers headers) {
129129
private void renderBytes(
130130
HttpExchange exchange, Headers headers, int status, String contentType, Object body)
131131
throws IOException {
132-
String effectiveContentType =
133-
contentType != null ? contentType : (body instanceof byte[] ? OCTET_STREAM : DEFAULT_JSON);
132+
String fallback = body instanceof byte[] ? OCTET_STREAM : DEFAULT_JSON;
133+
String effectiveContentType = contentType != null ? contentType : fallback;
134134
byte[] bytes = body instanceof byte[] raw ? raw : serialize(body, effectiveContentType);
135135
defaultContentType(headers, effectiveContentType);
136136
byte[] payload = maybeCompress(exchange, headers, status, effectiveContentType, bytes);
137-
exchange.sendResponseHeaders(status, payload.length == 0 ? -1 : payload.length);
137+
exchange.sendResponseHeaders(status, payload.length == 0 ? UNKNOWN_LENGTH : payload.length);
138138
if (payload.length > 0) {
139139
try (OutputStream out = exchange.getResponseBody()) {
140140
out.write(payload);

0 commit comments

Comments
 (0)