Skip to content

OKAPI-1240: Delete Accept-Encoding and Content-Encoding headers in proxy#1436

Draft
julianladisch wants to merge 2 commits intomasterfrom
OKAPI-1240
Draft

OKAPI-1240: Delete Accept-Encoding and Content-Encoding headers in proxy#1436
julianladisch wants to merge 2 commits intomasterfrom
OKAPI-1240

Conversation

@julianladisch
Copy link
Contributor

https://folio-org.atlassian.net/browse/OKAPI-1240

There are four sections when ProxyService proxies a request and response:

a) Request from client to Okapi.

b) Request from Okapi to module.

c) Response from module to Okapi

d) Response from Okapi to client.

Each section can have a different compression (none, deflate, gzip,br, …). Therefore the compression headers Accept-Encoding and Content-Encoding must not be copied from a) to b) and must not be copied from c) to d).

If Accept-Encoding is wrong the client or Okapi may get a body that it cannot decompress resulting in an exception.

If Content-Encoding is wrong the decompression of the body fails in Okapi or the client.

Fix: Remove the compression headers when copying the headers into the next section.

https://folio-org.atlassian.net/browse/OKAPI-1240

There are four sections when ProxyService proxies a request and response:

a) Request from client to Okapi.

b) Request from Okapi to module.

c) Response from module to Okapi

d) Response from Okapi to client.

Each section can have a different compression (none, deflate, gzip,br, …).
Therefore the compression headers Accept-Encoding and Content-Encoding
must not be copied from a) to b) and must not be copied from c) to d).

If Accept-Encoding is wrong the client or Okapi may get a body that it cannot decompress resulting in an exception.

If Content-Encoding is wrong the decompression of the body fails in Okapi or the client.

Fix: Remove the compression headers when copying the headers into the next section.
@julianladisch
Copy link
Contributor Author

Okapi runs with .setCompressionSupported(true): https://github.com/folio-org/okapi/blob/v7.0.2/okapi-core/src/main/java/org/folio/okapi/MainVerticle.java#L345

Vertx' HttpServer automatically compresses the response body if the client send an Accept-Encoding header: https://vertx.io/docs/vertx-core/java/#_http_compression

@sonarqubecloud
Copy link

@adamdickmeiss
Copy link
Contributor

Okapi runs with .setCompressionSupported(true): https://github.com/folio-org/okapi/blob/v7.0.2/okapi-core/src/main/java/org/folio/okapi/MainVerticle.java#L345

Vertx' HttpServer automatically compresses the response body if the client send an Accept-Encoding header: https://vertx.io/docs/vertx-core/java/#_http_compression

And the content is not compressed already.

Copy link
Contributor

@adamdickmeiss adamdickmeiss left a comment

Choose a reason for hiding this comment

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

Looks good. I think the testing module should not bind to 8081, but the "reserved" ports , such s 9131.

void test(String contentEncoding1, String contentEncoding2, VertxTestContext vtc) {
deployOkapi()
.compose(x -> deployModule(contentEncoding1))
.compose(server -> put("http://localhost:8081/foo", null, contentEncoding1))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that it would be better to use a port such as 9131 this is in range of "reserved" ports for testing.
Of course, it would be better to get a free port. But that would be a large undertaking (separate PR).

@julianladisch julianladisch marked this pull request as draft February 25, 2026 13:03
@julianladisch
Copy link
Contributor Author

Moving to draft because Adam pointed out important aspects:

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