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 server: add support for additional methods #83033

Open
viktorcsanak opened this issue Dec 16, 2024 · 2 comments · May be fixed by #83060
Open

net: http server: add support for additional methods #83033

viktorcsanak opened this issue Dec 16, 2024 · 2 comments · May be fixed by #83060
Assignees
Labels
area: Networking Feature Request A request for a new feature

Comments

@viktorcsanak
Copy link

Is your feature request related to a problem? Please describe.

The HTTP Server currently only supports GET and POST methods as seen in http_server_http1.c

switch (client->method) {
	case HTTP_HEAD:
		if (user_method & BIT(HTTP_HEAD)) {
			ret = SEND_RESPONSE(RESPONSE_TEMPLATE_DYNAMIC,
					    dynamic_detail->common.content_type);
			if (ret < 0) {
				return ret;
			}

			dynamic_detail->holder = NULL;

			return 0;
		}

	case HTTP_GET:
		/* For GET request, we do not pass any data to the app but let the app
		 * send data to the peer.
		 */
		if (user_method & BIT(HTTP_GET)) {
			return dynamic_get_req(dynamic_detail, client);
		}

		goto not_supported;

	case HTTP_POST:
		if (user_method & BIT(HTTP_POST)) {
			return dynamic_post_req(dynamic_detail, client);
		}

		goto not_supported;

not_supported:
	default:
		LOG_DBG("HTTP method %s (%d) not supported.",
			http_method_str(client->method),
			client->method);

		return -ENOTSUP;
	} 

And http_server_http2.c

switch (client->method) {
	case HTTP_GET:
		if (user_method & BIT(HTTP_GET)) {
			return dynamic_get_req_v2(dynamic_detail, client);
		}

		goto not_supported;

	case HTTP_POST:
		/* The data will come in DATA frames. Remember the detail ptr
		 * which needs to be known when passing data to application.
		 */
		if (user_method & BIT(HTTP_POST)) {
			client->current_detail =
				(struct http_resource_detail *)dynamic_detail;
			break;
		}

		goto not_supported;

not_supported:
	default:
		LOG_DBG("HTTP method %s (%d) not supported.",
			http_method_str(client->method),
			client->method);

		return -ENOTSUP;
	}

Describe the solution you'd like
The HTTP server should support additional methods, at least PUT and DELETE to allow proper API implementations.

@rlubos
Copy link
Contributor

rlubos commented Dec 16, 2024

Looking briefly into this it seems we could re-use the existing dynamic method handlers for PUT/DELETE, I'll try to wrap this up and send a patch.

@rlubos
Copy link
Contributor

rlubos commented Dec 16, 2024

@viktorcsanak Please give #83060 a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Networking Feature Request A request for a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants