Skip to content

Commit

Permalink
🔀 merge: pull request #6 from kresil/ktor-retry-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoengenheiro authored Apr 16, 2024
2 parents fdb673a + 700c932 commit 99d34f3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
Binary file modified docs/imgs/ktor-server-pipeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
agp = "8.2.0"
kotlin = "1.9.20"
coroutines = "1.8.0"
ktor = "2.3.9"
ktor = "2.3.10"
mockito = "5.3.1"
nexus-publish = "2.0.0-rc-1"
android-minSdk = "24"
Expand Down
14 changes: 7 additions & 7 deletions ktor-custom-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,24 +217,24 @@ Available pipelines in `ktor-client` are:
- `Render`: Encode a request body to `OutgoingContent`;
- `Send`: A phase for the `HttpSend` plugin.
- [HttpSendPipeline](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.request/-http-send-pipeline/-phases/index.html):
A pipeline used for sending a request.It has the following phases:
A pipeline used for sending a request. It has the following phases:
- `Before`: The earliest phase that happens before any other;
- `State`: Use this phase to modify a request with a shared state;
- `Monitoring`: Use this phase for logging and other actions that don't modify a request or shared data;
- `Engine`: Send a request to a remote server;
- `Receive`: Receive a pipeline execution phase.
- [HttpReceivePipeline](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.statement/-http-receive-pipeline/-phases/index.html):
A pipeline used for receiving a response without processing. It has the following phases:
- `Before`: The earliest phase that happens before any other;
- `State`: Use this phase to store request shared state;
- `After`: Latest response pipeline phase.
- [HttpResponsePipeline](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.statement/-http-response-pipeline/-phases/index.html):
A pipeline used for processing responses. It has the following phases:
- `Receive`: The earliest phase that happens before any other;
- `Parse`: Decode response body;
- `Transform`: Transform response body to expected format;
- `State`: Use this phase to store request shared state;
- `After`: Latest response pipeline phase
- [HttpReceivePipeline](https://api.ktor.io/ktor-client/ktor-client-core/io.ktor.client.statement/-http-receive-pipeline/-phases/index.html):
A pipeline used for receiving a request. It has the following phases:
- `Before`: The earliest phase that happens before any other;
- `State`: Use this phase to store request shared state;
- `After`: Latest response pipeline phase
- `After`: Latest response pipeline phase.

| ![Client Pipelines](../docs/imgs/ktor-client-pipelines.png) |
|:-----------------------------------------------------------:|
Expand Down
15 changes: 9 additions & 6 deletions ktor-retry-plugin/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Ktor Retry Plugin

### Install
This plugin intercepts the `HttpSend` plugin which in turn intercepts the `HttpRequestPipeline` pipeline during the `Send` phase,
which is the last default phase of this pipeline.

The `HttpRequestRetry` plugin can be installed using the `install` function
and configured using its **last parameter function**
(_trailing lambda_), as with other Ktor plugins.
The `HttpRequestPipeline` is the first client pipeline and is responsible for processing all requests sent by a client. It acts before the `HttpSendPipeline` pipeline, which is responsible for sending the request to the server.

The plugin is part of the `ktor-client-core` module.
See `ktor-custom-plugin` module [documentation](../ktor-custom-plugin/README.md#pipelines-1) for more details on client pipelines.

In short,
this plugin intercepts the request before it is sent to the server
and can retry it based on policies defined in the plugin configuration.

### Configuration

Expand All @@ -19,7 +22,7 @@ The plugin is part of the `ktor-client-core` module.

> [!NOTE]
> The plugin also provides more specific methods to retry for
> (e.g., on server errors, for example, `retryOnServerErrors()` retries on server 5xx errors).
> (e.g., `retryOnServerErrors()` retries on server 5xx errors).
Example:

Expand Down

0 comments on commit 99d34f3

Please sign in to comment.