From a779e91d100bf47893119de322e7708118120983 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Mon, 2 Feb 2026 14:42:15 +0100 Subject: [PATCH 1/5] chore: [JS] Document Request Compression Middleware --- .../connectivity/generic-http-client.mdx | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/docs-js/features/connectivity/generic-http-client.mdx b/docs-js/features/connectivity/generic-http-client.mdx index 7a92cdb5e3..daf3818777 100644 --- a/docs-js/features/connectivity/generic-http-client.mdx +++ b/docs-js/features/connectivity/generic-http-client.mdx @@ -221,6 +221,77 @@ const response = await executeHttpRequest( ); ``` +### Request Compression + +:::caution + +Not all servers support decompressing request payloads with every supported algorithm - or any algorithm at all. +Verify your target server supports decompression of compressed requests before enabling this middleware. + +::: + +:::info + +Place compression middleware at the beginning of your middleware array. +This ensures the payload is compressed once and reused across retry attempts. + +::: + +The SAP Cloud SDK provides a [`compressRequest()`](pathname:///api/v4/functions/sap-cloud-sdk_http-client.compressRequest.html) middleware to compress HTTP request payloads using a selected compression algorithm. +This can reduce bandwidth usage and improve performance when sending large payloads to remote APIs. +For details on supported algorithms and options, see the [API documentation](pathname:///api/v4/interfaces/sap-cloud-sdk_http-client.RequestCompressionMiddlewareOptions.html). + +To enable automatic compression with `gzip` based on payload size: + +```ts +import { compressRequest } from '@sap-cloud-sdk/http-client'; + +const response = await executeHttpRequest( + { + url: 'https://example.com' + }, + { + method: 'post', + data: largePayload, + middleware: [compressRequest()] + } +); +``` + +The [`compressRequest()`](pathname:///api/v4/functions/sap-cloud-sdk_http-client.compressRequest.html) middleware supports [four modes of operation](pathname:///api/v4/interfaces/sap-cloud-sdk_http-client.RequestCompressionMiddlewareOptions.html#mode): + +**Auto mode (recommended, default):** Compresses payloads only if they exceed a size threshold. + +```ts +// Use default threshold of 1024 bytes +middleware: [compressRequest()]; +``` + +```ts +// Use custom threshold +middleware: [compressRequest({ mode: 'auto', autoCompressMinSize: 5000 })]; +``` + +**Always compress:** Forces compression regardless of payload size. + +```ts +middleware: [compressRequest({ mode: true, compressOptions: { level: 1 } })]; +``` + +**Pass-through mode:** Sets the `Content-Encoding` header without compressing. +Use this mode when the payload is already compressed with the selected algorithm. + +```ts +middleware: [compressRequest({ algorithm: 'zstd', mode: 'passthrough' })]; +``` + +**No compression:** Disables compression even if the middleware is included. +This mode is useful for conditional logic. + +```ts +middleware: [compressRequest({ mode: false })]; +``` + ## `executeHttpRequestWithOrigin()` The `executeHttpRequestWithOrigin()` function is a variation of `executeHttpRequest()` which allows more fine-grained control over configuration precedence. From f355629b1d34984f7e4d5c82db7699a8d37f7e1c Mon Sep 17 00:00:00 2001 From: David Knaack Date: Wed, 11 Feb 2026 16:08:58 +0100 Subject: [PATCH 2/5] use updated api --- docs-js/features/connectivity/generic-http-client.mdx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs-js/features/connectivity/generic-http-client.mdx b/docs-js/features/connectivity/generic-http-client.mdx index daf3818777..b545206181 100644 --- a/docs-js/features/connectivity/generic-http-client.mdx +++ b/docs-js/features/connectivity/generic-http-client.mdx @@ -275,21 +275,21 @@ middleware: [compressRequest({ mode: 'auto', autoCompressMinSize: 5000 })]; **Always compress:** Forces compression regardless of payload size. ```ts -middleware: [compressRequest({ mode: true, compressOptions: { level: 1 } })]; +middleware: [compressRequest({ mode: 'always', compressOptions: { level: 1 } })]; ``` -**Pass-through mode:** Sets the `Content-Encoding` header without compressing. +**Header-only mode:** Sets the `Content-Encoding` header without compressing. Use this mode when the payload is already compressed with the selected algorithm. ```ts -middleware: [compressRequest({ algorithm: 'zstd', mode: 'passthrough' })]; +middleware: [compressRequest({ algorithm: 'zstd', mode: 'header-only' })]; ``` **No compression:** Disables compression even if the middleware is included. This mode is useful for conditional logic. ```ts -middleware: [compressRequest({ mode: false })]; +middleware: [compressRequest({ mode: 'never' })]; ``` ## `executeHttpRequestWithOrigin()` From 841014bea64d1515c6bb37cf0f9fca8c4ddbde2d Mon Sep 17 00:00:00 2001 From: cloud-sdk-js Date: Wed, 11 Feb 2026 15:10:29 +0000 Subject: [PATCH 3/5] fix: Changes from lint --- docs-js/features/connectivity/generic-http-client.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs-js/features/connectivity/generic-http-client.mdx b/docs-js/features/connectivity/generic-http-client.mdx index b545206181..5025672168 100644 --- a/docs-js/features/connectivity/generic-http-client.mdx +++ b/docs-js/features/connectivity/generic-http-client.mdx @@ -275,7 +275,9 @@ middleware: [compressRequest({ mode: 'auto', autoCompressMinSize: 5000 })]; **Always compress:** Forces compression regardless of payload size. ```ts -middleware: [compressRequest({ mode: 'always', compressOptions: { level: 1 } })]; +middleware: [ + compressRequest({ mode: 'always', compressOptions: { level: 1 } }) +]; ``` **Header-only mode:** Sets the `Content-Encoding` header without compressing. From 4cd4940df90fd7b224691a53a9ac4af98e144f96 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Fri, 20 Feb 2026 15:44:40 +0100 Subject: [PATCH 4/5] Update middleware function name from compressRequest to compress and enhance compression details --- .../connectivity/generic-http-client.mdx | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/docs-js/features/connectivity/generic-http-client.mdx b/docs-js/features/connectivity/generic-http-client.mdx index 5025672168..3f6cf4ab31 100644 --- a/docs-js/features/connectivity/generic-http-client.mdx +++ b/docs-js/features/connectivity/generic-http-client.mdx @@ -237,14 +237,19 @@ This ensures the payload is compressed once and reused across retry attempts. ::: -The SAP Cloud SDK provides a [`compressRequest()`](pathname:///api/v4/functions/sap-cloud-sdk_http-client.compressRequest.html) middleware to compress HTTP request payloads using a selected compression algorithm. +The SAP Cloud SDK provides a [`compress()`](pathname:///api/v4/functions/sap-cloud-sdk_http-client.compress.html) middleware to compress HTTP request payloads using a selected compression algorithm. This can reduce bandwidth usage and improve performance when sending large payloads to remote APIs. + +Compression requires additional computational resources to encode the payload, and the compressed payload could be slightly larger than the original if the payload is not suited for compression (e.g., too small or already compressed). +For small payloads or in a high-bandwidth environment, the overhead may outweigh potential bandwidth savings. +The default "auto" mode addresses this by only compressing payloads above a size threshold. + For details on supported algorithms and options, see the [API documentation](pathname:///api/v4/interfaces/sap-cloud-sdk_http-client.RequestCompressionMiddlewareOptions.html). To enable automatic compression with `gzip` based on payload size: ```ts -import { compressRequest } from '@sap-cloud-sdk/http-client'; +import { compress } from '@sap-cloud-sdk/http-client'; const response = await executeHttpRequest( { @@ -253,30 +258,30 @@ const response = await executeHttpRequest( { method: 'post', data: largePayload, - middleware: [compressRequest()] + middleware: [compress()] } ); ``` -The [`compressRequest()`](pathname:///api/v4/functions/sap-cloud-sdk_http-client.compressRequest.html) middleware supports [four modes of operation](pathname:///api/v4/interfaces/sap-cloud-sdk_http-client.RequestCompressionMiddlewareOptions.html#mode): +The [`compress()`](pathname:///api/v4/functions/sap-cloud-sdk_http-client.compress.html) middleware supports [four modes of operation](pathname:///api/v4/interfaces/sap-cloud-sdk_http-client.RequestCompressionMiddlewareOptions.html#mode): **Auto mode (recommended, default):** Compresses payloads only if they exceed a size threshold. ```ts // Use default threshold of 1024 bytes -middleware: [compressRequest()]; +middleware: [compress()]; ``` ```ts // Use custom threshold -middleware: [compressRequest({ mode: 'auto', autoCompressMinSize: 5000 })]; +middleware: [compress({ mode: 'auto', autoCompressMinSize: 5000 })]; ``` **Always compress:** Forces compression regardless of payload size. ```ts middleware: [ - compressRequest({ mode: 'always', compressOptions: { level: 1 } }) + compress({ mode: 'always', compressOptions: { level: 1 } }) ]; ``` @@ -284,14 +289,14 @@ middleware: [ Use this mode when the payload is already compressed with the selected algorithm. ```ts -middleware: [compressRequest({ algorithm: 'zstd', mode: 'header-only' })]; +middleware: [compress({ algorithm: 'zstd', mode: 'header-only' })]; ``` **No compression:** Disables compression even if the middleware is included. This mode is useful for conditional logic. ```ts -middleware: [compressRequest({ mode: 'never' })]; +middleware: [compress({ mode: 'never' })]; ``` ## `executeHttpRequestWithOrigin()` From b5b18af2fd192f6566d3517221ee870e973585e4 Mon Sep 17 00:00:00 2001 From: cloud-sdk-js Date: Fri, 20 Feb 2026 14:47:02 +0000 Subject: [PATCH 5/5] fix: Changes from lint --- docs-js/features/connectivity/generic-http-client.mdx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs-js/features/connectivity/generic-http-client.mdx b/docs-js/features/connectivity/generic-http-client.mdx index 3f6cf4ab31..779fef1226 100644 --- a/docs-js/features/connectivity/generic-http-client.mdx +++ b/docs-js/features/connectivity/generic-http-client.mdx @@ -280,9 +280,7 @@ middleware: [compress({ mode: 'auto', autoCompressMinSize: 5000 })]; **Always compress:** Forces compression regardless of payload size. ```ts -middleware: [ - compress({ mode: 'always', compressOptions: { level: 1 } }) -]; +middleware: [compress({ mode: 'always', compressOptions: { level: 1 } })]; ``` **Header-only mode:** Sets the `Content-Encoding` header without compressing.