-
Notifications
You must be signed in to change notification settings - Fork 921
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a way to enable/disable streaming for a request or response (#…
…3956) Motivation: `HttpService` regards every request and response as streaming. The streaming request and response could be a super set of non-streaming ones. However, if we let users specify whether to use streaming or automatically detect for annotated services and gRPC services, we can get a chance to add enhanced code paths for non-streaming `HttpService`. Modifications: - Add `ExchangeType` that represents whether to stream a request or response - Add `HttpService.exchangeType(RequestHeaders,Route)` to determine an `ExchangeType` with the given parameters. - gRPC and annotated services will dynamically decide an `ExchangeType` in runtime. - Move `FixedStreamMessage` and its subclasses to `internal` package. - Add `AggregatingStreamMessage` that can buffer objects and can publish after closing the stream. - `AggregatingDecodedHttpRequest` uses `AggregatingStreamMessage` to accumulate `HttpObject`s before receiving end of stream. - Only closed `AggregatingDecodedHttpRequest`s can be fired to `HttpServerHandler` - Refactor a way to hold `ServerConfig` to see reconfigured `ServerConfig` without `configUpdateListener` - Add `EarlyResponseRoutingContext` that indicate a early response that can be served at `HttpServerHander`. - Fix `Http{1,2}RequestDecoder` to properly handle `AggregatingDecodedHttpRequest` Result: - You can now set an `ExchangeType` to `HttpService` for a non-streaming request or response.
- Loading branch information
Showing
90 changed files
with
3,602 additions
and
1,196 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
68 changes: 68 additions & 0 deletions
68
core/src/main/java/com/linecorp/armeria/common/ExchangeType.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,68 @@ | ||
/* | ||
* Copyright 2021 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.common; | ||
|
||
import com.linecorp.armeria.common.annotation.UnstableApi; | ||
|
||
/** | ||
* Represents whether to stream an {@link HttpRequest} or {@link HttpResponse}. | ||
*/ | ||
@UnstableApi | ||
public enum ExchangeType { | ||
/** | ||
* No streaming. A {@link HttpRequest} and a {@link HttpResponse} will be buffered | ||
* when they are sent or received. | ||
*/ | ||
UNARY(false, false), | ||
/** | ||
* A streaming {@link HttpRequest} with a non-streaming {@link HttpResponse}. | ||
* The {@link HttpResponse} will be buffered when it is sent or received. | ||
*/ | ||
REQUEST_STREAMING(true, false), | ||
/** | ||
* A non-streaming {@link HttpRequest} with a streaming {@link HttpResponse}. | ||
* The {@link HttpRequest} will be buffered when it is sent or received. | ||
*/ | ||
RESPONSE_STREAMING(false, true), | ||
/** | ||
* Bidirectional streaming. | ||
* Neither a {@link HttpRequest} nor a {@link HttpResponse} is buffered. | ||
*/ | ||
BIDI_STREAMING(true, true); | ||
|
||
private final boolean requestStreaming; | ||
private final boolean responseStreaming; | ||
|
||
ExchangeType(boolean requestStreaming, boolean responseStreaming) { | ||
this.requestStreaming = requestStreaming; | ||
this.responseStreaming = responseStreaming; | ||
} | ||
|
||
/** | ||
* Returns whether to support request streaming. | ||
*/ | ||
public boolean isRequestStreaming() { | ||
return requestStreaming; | ||
} | ||
|
||
/** | ||
* Returns whether to support response streaming. | ||
*/ | ||
public boolean isResponseStreaming() { | ||
return responseStreaming; | ||
} | ||
} |
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
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
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.