Skip to content
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

net: http: Add compression support in HTTP server #86490

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kica-z
Copy link
Contributor

@kica-z kica-z commented Feb 28, 2025

Add compression support using the accept-encoding header to the http server static filesystem resource.

In our use case we have different files with different compressions it is therefore important that the webserver is able to handle those compressions correctly. This is a first draft of the feature. I am open to discussion on how to implement this or if this is even wanted in upstream.

@zephyrbot zephyrbot added area: HTTP HTTP client/server support area: Networking labels Feb 28, 2025
@kica-z kica-z force-pushed the feature/http-server-compression-support branch from c247ea7 to f0533cf Compare February 28, 2025 15:44
Copy link
Member

@jukkar jukkar left a comment

Choose a reason for hiding this comment

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

No objection to the feature, just wondering if it would make sense to have this more configurable. I mean that if user only needs gzip support, then the other methods are useless to compile in. Perhaps have a Kconfig entries for each supported compression method, and then compile out code that is not needed.

@kica-z kica-z force-pushed the feature/http-server-compression-support branch from f0533cf to 70779c4 Compare March 4, 2025 08:50
@kica-z
Copy link
Contributor Author

kica-z commented Mar 4, 2025

@jukkar I agree in the sense that a kconfig to enable compression in general would be good. I am however not sure if kconfigs for each compression method would't be to much as the only thing they would remove is one if in the http_server_find_file function. What do you think? I added a general compression kconfig for now.

I will also have a look at the tests that are failing (need to add tests covering compression anyhow).

@kica-z kica-z requested a review from jukkar March 4, 2025 08:51
Add compression support using the accept-encoding
header to the http server static filesystem resource.

Signed-off-by: Carlo Kirchmeier <carlo.kirchmeier@zuehlke.com>
@kica-z kica-z force-pushed the feature/http-server-compression-support branch from 70779c4 to 7271508 Compare March 4, 2025 09:01
Copy link
Contributor

@rlubos rlubos left a comment

Choose a reason for hiding this comment

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

Any chance for some test for this? Or at least we should enable it in the sample to make sure it builds.

@@ -201,6 +201,21 @@ config WEBSOCKET_CONSOLE
help
Hidden option that is enabled only when all the necessary options
needed by websocket console are set.

config HTTP_SERVER_COMPRESSION
bool "Compression support in http fileserver"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
bool "Compression support in http fileserver"
bool "Compression support in HTTP fileserver"

HTTP_ZSTD = 4 /**< ZSTD */
};

void http_compression_parse_accept_encoding(const char *accept_encoding, size_t len,
Copy link
Contributor

Choose a reason for hiding this comment

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

I just wonder, does it need to be a public header, those efunctions seem rather internal?

Copy link
Member

Choose a reason for hiding this comment

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

And also the functions should be documented using doxygen comments.

return "";
}

int http_compression_from_text(enum http_compression compression[static 1], const char *text)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just enum http_compression *compression? TBH it's a bit confusing to see an 1-element array being passed here, plus, is static 1 even a valid C syntax, or just some GCC extension? First time I see a construct like this being used.
Same goes to other functions.

if (ret < 0) {
len = strlen(fname);
len = strlen(fname);
#ifdef CONFIG_HTTP_SERVER_COMPRESSION
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use if (IS_ENABLED(CONFIG_HTTP_SERVER_COMPRESSION)) { ... } whenever possible. Not only this makes code compile unconditionally, but should also allow to avoid extra ifdef slicing, like around return_filename label.

@jukkar
Copy link
Member

jukkar commented Mar 4, 2025

What do you think? I added a general compression kconfig for now.

What you have now (one Kconfig option) looks fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: HTTP HTTP client/server support area: Networking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants