Skip to content

Release 8.1.0 - #81

Open
harshrathorr wants to merge 4 commits into
Cimpress-MCP:mainfrom
harshrathorr:harsh/PRC-13163/request_compressed_responses
Open

harshrathorr wants to merge 4 commits into
Cimpress-MCP:mainfrom
harshrathorr:harsh/PRC-13163/request_compressed_responses

Conversation

@harshrathorr

@harshrathorr harshrathorr commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Jira: PRC-13163. HttpClient now explicitly asks servers for compressed responses, which reduces transferred data and NAT gateway costs.

Changes

  • New HttpClientOptions.requestCompressedResponses (default true). The request interceptor sets Accept-Encoding: gzip, compress, deflate, br.
  • requestCompressedResponses: false sends Accept-Encoding: identity.
  • An Accept-Encoding header set on the request, or in the defaults of a provided axios instance, always takes precedence. It is only set when absent, so the instance defaults are not mutated.
  • Release 8.1.0 (new option; first stable 8.x release, includes the 8.0.0-beta changes): package.json, CHANGELOG.md, README.md.

Why existing services keep working

  • The default value is exactly what the pinned axios (1.21.1) Node http adapter already sends implicitly. Wire check against a local server: default HttpClient and plain axios send identical Accept-Encoding: gzip, compress, deflate, br, and brotli/gzip responses are decoded transparently.
  • No change to createHeadersWithResolvedToken, auth stripping, cache keys, or retries. Tests cover each.
  • Consumers on versions older than 7.0.0 did not send the header, so they will start receiving compressed responses after upgrading (decoded transparently). This is noted in the changelog.

Verification

  • yarn lint, yarn build, yarn test (146 tests, on Node 22) pass.
  • New tests cover all HTTP methods, the option on/off, caller header precedence, no mutation of axios defaults, token/correlation id coexistence, non-whitelisted domains, cache and retry.
  • No as/any introduced in source. No dependency changes.
  • Snyk scan could not be run locally (not authenticated); no dependencies changed.

@harshrathorr harshrathorr changed the title PRC-13163 Add option to request compressed responses Release 8.0.0-beta.1 Dec 1, 2026
@harshrathorr harshrathorr changed the title Release 8.0.0-beta.1 Release 8.1.0 Dec 1, 2026
Comment thread src/httpClient/httpClient.ts Outdated

const compressedResponseEncodings: string = 'gzip, compress, deflate, br';

const uncompressedResponseEncoding: string = 'identity';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. Nothing is added to the request when the option is disabled, so the identity constant is gone.

Comment thread src/httpClient/httpClient.ts Outdated

const invalidToken: string = 'Invalid token';

const compressedResponseEncodings: string = 'gzip, compress, deflate, br';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is compress, deflate necessary? Also let's remove br at least for now, given the recent events

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I checked - let's just use gzip

image

@harshrathorr harshrathorr Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, the default is now Accept-Encoding: gzip

Comment thread src/httpClient/httpClient.ts Outdated
private setAcceptEncodingIfNotSpecified(config: InternalAxiosRequestConfig): void {
config.headers.set(
'Accept-Encoding',
this.requestCompressedResponses ? compressedResponseEncodings : uncompressedResponseEncoding,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just not add any header if the compression is not needed

@harshrathorr harshrathorr Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. With requestCompressedResponses: false no header is added. Note that axios' Node adapter then sends its own default (gzip, compress, deflate, br) because it sets Accept-Encoding when it is missing, so false means 'leave it to axios', not 'disable compression

};
}

private setAcceptEncodingIfNotSpecified(config: InternalAxiosRequestConfig): void {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 3 lines of code inside this function are used exactly 1 time. What's the benefit of creating this function?


private setAcceptEncodingIfNotSpecified(config: InternalAxiosRequestConfig): void {
if (this.requestCompressedResponses) {
config.headers.set('Accept-Encoding', compressedResponseEncoding, false);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter mutation. Let's avoid this

const testToken = 'unit-test-token';
const testCorrelationId = 'test-correlation-id';
const url = 'https://api.example.com/data';
const methods = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options'] as const;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the as const here?

this.clientExceptionStatusCodeMapOverride = options?.clientExceptionStatusCodeMapOverride;
this.client = options?.client ?? axios.create();
this.whitelistedDomains = options?.whitelistedDomains;
this.requestCompressedResponses = options?.requestCompressedResponses ?? true;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default behavior should be the same as in the current version - no explicit compression headers are sent. Otherwise this'll be a somewhat breaking change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants