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: define http service and resource iterable sections #55430

Conversation

cfriedt
Copy link
Member

@cfriedt cfriedt commented Mar 4, 2023

Provide a means of declaring zero or more HTTP services, each with zero or more static HTTP resources.

Static HTTP resources are those which have fixed paths[1] that are known prior to system initialization. Some examples of static http resources would be

  • a forwarder from '/' to '/index.html'
  • a REST endpoint with fixed path '/api/foo' and detail pointing at some implementation-specific function
  • a Javascript file in string form with fixed path '/js/util.js'
  • a 'construction' image with path '/res/work.png'
  • a gzip-compressed 'Hello' HTML file at '/hello.html'

Without loss of generality in how static HTTP resources are organized or served by any given HTTP server, we can describe what static resources exist on a system in a common way that

  • does not require any optional facilities (e.g. filesystem) and
  • relies exclusively on addressable memory.

Additionally, for the purposes of simply allowing others to implement custom HTTP servers in a consistent way, or benchmarking implementations, or having a consistent testsuite to use across multiple implementations, it is helpful to have a common method to declare HTTP services and static resources for Zephyr.

[1] https://en.wikipedia.org/wiki/URL

@cfriedt
Copy link
Member Author

cfriedt commented Mar 4, 2023

In draft / blocked on #55429

@cfriedt cfriedt force-pushed the add-http-service-and-resource-iterable-sections branch from d92d8f1 to a5f394f Compare March 4, 2023 22:59
@cfriedt
Copy link
Member Author

cfriedt commented Mar 4, 2023

Also, just to clarify, yes, this does allow multiple HTTP servers to operate simultaneously (or a single server, serving multiple ports).

@cfriedt cfriedt force-pushed the add-http-service-and-resource-iterable-sections branch from a5f394f to 71b333e Compare March 4, 2023 23:49
@cfriedt
Copy link
Member Author

cfriedt commented Mar 4, 2023

  • removed BUILD_ASSERT() from service.h because llvm was throwing errors of the form
error: static_assert expression is not an integral constant expression

@cfriedt
Copy link
Member Author

cfriedt commented Mar 5, 2023

I would say that possibly the most useful result of this change is that it allows us to test or benchmark any HTTP server implementation using the same testsuite

@cfriedt cfriedt requested a review from jukkar March 5, 2023 00:13
@cfriedt
Copy link
Member Author

cfriedt commented Mar 5, 2023

This is important to get in well before GSoC contributors finish preparing their applications / sample code.

@cfriedt cfriedt force-pushed the add-http-service-and-resource-iterable-sections branch from 71b333e to 2455c07 Compare March 5, 2023 00:21
@cfriedt cfriedt mentioned this pull request Mar 5, 2023
2 tasks
@cfriedt cfriedt force-pushed the add-http-service-and-resource-iterable-sections branch 2 times, most recently from 3be5979 to e585a3f Compare March 5, 2023 01:15
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.

Looks cool, nice work 👍

tests/net/lib/http_server/common/src/main.c Outdated Show resolved Hide resolved
@cfriedt cfriedt force-pushed the add-http-service-and-resource-iterable-sections branch 4 times, most recently from 6ee42b1 to 9617232 Compare March 5, 2023 21:32
include/zephyr/net/http/service.h Show resolved Hide resolved
include/zephyr/net/http/service.h Outdated Show resolved Hide resolved
subsys/net/lib/http/Kconfig Outdated Show resolved Hide resolved
@cfriedt cfriedt force-pushed the add-http-service-and-resource-iterable-sections branch from 9617232 to e66d15b Compare March 6, 2023 10:24
rlubos
rlubos previously approved these changes Mar 6, 2023
@cfriedt cfriedt force-pushed the add-http-service-and-resource-iterable-sections branch 5 times, most recently from c76d40e to d1fc992 Compare March 7, 2023 11:17
@cfriedt cfriedt marked this pull request as ready for review March 7, 2023 11:20
@cfriedt cfriedt requested review from nashif and andyross as code owners March 7, 2023 11:20
@cfriedt cfriedt requested review from jukkar and rlubos March 7, 2023 11:20
cfriedt added 2 commits March 7, 2023 06:23
Provide a means of declaring zero or more HTTP services, each
with zero or more static HTTP resources.

Static HTTP resources are those which have fixed paths[1] which
are known prior to system initialization. Some examples of
static http resources would be

* a forwarder from '/' to '/index.html'
* a REST endpoint with fixed path '/api/foo' and detail
  pointing at some implementation-specific function
* a Javascript file in string form with fixed path '/js/util.js'
* a 'construction' image with path '/res/work.png'
* a gzip-compressed 'Hello' HTML file at '/hello.html'

Without describing in any detail how static HTTP resources are
organized or served by any given HTTP server, we can describe
what static resources exist on a system in a common way that
does not require any optional facilities (e.g. filesystem) and
relies only on addressable memory.

Additionally, for the purposes of simply allowing others
to implement custom HTTP servers in a consistent way, or
benchmarking implementations, or having a consistent testsuite
to use across multiple implementations, it is helpful to have
a common method to declare HTTP services and static resources
for Zephyr.

[1] https://en.wikipedia.org/wiki/URL

Signed-off-by: Chris Friedt <cfriedt@meta.com>
Add tests to verify the newly-added HTTP service and resource
macros.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
@cfriedt cfriedt force-pushed the add-http-service-and-resource-iterable-sections branch from d1fc992 to 5df0df5 Compare March 7, 2023 11:23
@cfriedt
Copy link
Member Author

cfriedt commented Mar 7, 2023

@rlubos @jukkar - taken out of draft. Please pre-approve if it looks ok.

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.

LGTM

@fabiobaltieri fabiobaltieri merged commit 7b364c7 into zephyrproject-rtos:main Mar 8, 2023
@cfriedt cfriedt deleted the add-http-service-and-resource-iterable-sections branch June 3, 2023 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants