-
Notifications
You must be signed in to change notification settings - Fork 926
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…#5586) Motivation: We have `HttpResult<T>` and `ResponseEntity<T>`, both of them support automatic JSON deserialization. However, we can't use `HttpResult` for clients because it is located in `com.linecorp.armeria.server.annotation`. So, we should support `ResponseEntity` in that package so that users are not confused as to which one to use, and so that it can be used commonly between server and client. Modifications: - Add logic to check if result type is `ResponseEntity`. - Create `ResponseEntityUtil` to build response headers as well as `HttpResult`. - Deprecate `HttpResult`. - Tests - Add `ResponseEntity` cases for the cases that verify `HttpResult` behavior itself. - Replace for the cases that use `HttpResult` to verify other behaviors. Result: - Closes #4910
- Loading branch information
Showing
12 changed files
with
470 additions
and
51 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
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
53 changes: 53 additions & 0 deletions
53
core/src/main/java/com/linecorp/armeria/internal/server/annotation/ResponseEntityUtil.java
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,53 @@ | ||
/* | ||
* Copyright 2024 LINE Corporation | ||
* | ||
* LINE Corporation licenses this file to you 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: | ||
* | ||
* https://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. | ||
*/ | ||
|
||
package com.linecorp.armeria.internal.server.annotation; | ||
|
||
import com.linecorp.armeria.common.MediaType; | ||
import com.linecorp.armeria.common.ResponseEntity; | ||
import com.linecorp.armeria.common.ResponseHeaders; | ||
import com.linecorp.armeria.common.ResponseHeadersBuilder; | ||
import com.linecorp.armeria.server.ServiceRequestContext; | ||
|
||
/** | ||
* Utilities for {@link ResponseEntity}. | ||
*/ | ||
final class ResponseEntityUtil { | ||
/** | ||
* Build {@link ResponseHeaders} from the given {@link ServiceRequestContext} and {@link ResponseEntity}. | ||
*/ | ||
static ResponseHeaders buildResponseHeaders(ServiceRequestContext ctx, ResponseEntity<?> result) { | ||
final ResponseHeaders headers = result.headers(); | ||
|
||
if (headers.status().isContentAlwaysEmpty()) { | ||
return headers; | ||
} | ||
if (headers.contentType() != null) { | ||
return headers; | ||
} | ||
|
||
final ResponseHeadersBuilder builder = headers.toBuilder(); | ||
|
||
final MediaType negotiatedResponseMediaType = ctx.negotiatedResponseMediaType(); | ||
if (negotiatedResponseMediaType != null) { | ||
builder.contentType(negotiatedResponseMediaType); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
|
||
private ResponseEntityUtil() {} | ||
} |
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.