-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to access current response timeout (#1811) #1828
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
14a4fcf
Ability to access current response timeout (#1811)
nrktkt a161687
docs
nrktkt 01571e1
indentation
nrktkt 6262f34
Merge remote-tracking branch 'origin/master' into jr/review-1828
jrudolph 1bb479b
Add @DoNotInherit to TimeoutAccess
jrudolph 09b956f
=htp add mima filter
jrudolph File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
28 changes: 28 additions & 0 deletions
28
...main/paradox/routing-dsl/directives/timeout-directives/extractRequestTimeout.md
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,28 @@ | ||
# extractRequestTimeout | ||
|
||
@@@ div { .group-scala } | ||
|
||
## Signature | ||
|
||
@@signature [TimeoutDirectives.scala]($akka-http$/akka-http/src/main/scala/akka/http/scaladsl/server/directives/TimeoutDirectives.scala) { #extractRequestTimeout } | ||
|
||
@@@ | ||
|
||
## Description | ||
|
||
This directive extracts the currently set request timeout. | ||
|
||
@@@ warning | ||
Please note that this extracts the request timeout at the current moment, but the timeout can be changed concurrently. | ||
See other timeout directives about raciness inherent to timeout directives. | ||
@@@ | ||
|
||
For more information about various timeouts in Akka HTTP see @ref[Akka HTTP Timeouts](../../../common/timeouts.md). | ||
|
||
## Example | ||
|
||
Scala | ||
: @@snip [TimeoutDirectivesExamplesSpec.scala]($test$/scala/docs/http/scaladsl/server/directives/TimeoutDirectivesExamplesSpec.scala) { #extractRequestTimeout } | ||
|
||
Java | ||
: @@snip [TimeoutDirectivesExamplesTest.java]($test$/java/docs/http/javadsl/server/directives/TimeoutDirectivesExamplesTest.java) { #extractRequestTimeout } |
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 |
---|---|---|
|
@@ -177,4 +177,29 @@ public void testRequestTimeoutCustomResponseCanBeAddedSeparately() { | |
assert (StatusCodes.ENHANCE_YOUR_CALM.equals(statusCode)); | ||
//#withRequestTimeoutResponse | ||
} | ||
|
||
@Test | ||
public void extractRequestTimeout(){ | ||
//#extractRequestTimeout | ||
Duration timeout1 = Duration.create(500, TimeUnit.MILLISECONDS); | ||
Duration timeout2 = Duration.create(1000, TimeUnit.MILLISECONDS); | ||
Route route = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use 2 spaces as indentation for Java doc snippets as well for better readability. |
||
path("timeout", () -> | ||
withRequestTimeout(timeout1, () -> | ||
extractRequestTimeout( t1 -> | ||
withRequestTimeout(timeout2, () -> | ||
extractRequestTimeout( t2 -> { | ||
if (t1 == timeout1 && t2 == timeout2) | ||
return complete(StatusCodes.OK); | ||
else | ||
return complete(StatusCodes.INTERNAL_SERVER_ERROR); | ||
}) | ||
) | ||
) | ||
) | ||
); | ||
//#extractRequestTimeout | ||
StatusCode statusCode = runRoute(system, materializer, route, "timeout").get().status(); | ||
assert (StatusCodes.OK.equals(statusCode)); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyone have input on how this error case should be handled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duration.Inf
is fine, no need to log a warning. Let's document it on the directive.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a common case that the timeout access header is missing? What situation should we tell users to expect it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point. I think there's currently no way the header would be missing. Maybe we can just fail in that case because it should be seldom enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think failing or continuing with
Duration.Inf
would both be fine, maybe bump the log to error level.What would failure look like here? Completing with an exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, let's keep it for now. We might want to allow switching off request timeouts completely for performance reasons later on, so not requiring that this header is always available is maybe the best solution.