1 /*
2  * Copyright (c) 2023, Emna Rekik
3  * Copyright (c) 2023 Nordic Semiconductor ASA
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #ifndef HTTP_SERVER_INTERNAL_H_
9 #define HTTP_SERVER_INTERNAL_H_
10 
11 #include <stdbool.h>
12 
13 #include <zephyr/net/http/server.h>
14 #include <zephyr/net/http/service.h>
15 #include <zephyr/net/http/status.h>
16 #include <zephyr/net/http/hpack.h>
17 #include <zephyr/net/http/frame.h>
18 
19 /* HTTP1/HTTP2 state handling */
20 int handle_http_frame_rst_stream(struct http_client_ctx *client);
21 int handle_http_frame_goaway(struct http_client_ctx *client);
22 int handle_http_frame_settings(struct http_client_ctx *client);
23 int handle_http_frame_priority(struct http_client_ctx *client);
24 int handle_http_frame_continuation(struct http_client_ctx *client);
25 int handle_http_frame_window_update(struct http_client_ctx *client);
26 int handle_http_frame_header(struct http_client_ctx *client);
27 int handle_http_frame_headers(struct http_client_ctx *client);
28 int handle_http_frame_data(struct http_client_ctx *client);
29 int handle_http_frame_padding(struct http_client_ctx *client);
30 int handle_http1_request(struct http_client_ctx *client);
31 int handle_http1_to_http2_upgrade(struct http_client_ctx *client);
32 int handle_http1_to_websocket_upgrade(struct http_client_ctx *client);
33 void http_server_release_client(struct http_client_ctx *client);
34 
35 int enter_http1_request(struct http_client_ctx *client);
36 int enter_http2_request(struct http_client_ctx *client);
37 int enter_http_done_state(struct http_client_ctx *client);
38 
39 /* Others */
40 struct http_resource_detail *get_resource_detail(const char *path, int *len, bool is_ws);
41 int http_server_sendall(struct http_client_ctx *client, const void *buf, size_t len);
42 void http_server_get_content_type_from_extension(char *url, char *content_type,
43 						 size_t content_type_size);
44 int http_server_find_file(char *fname, size_t fname_size, size_t *file_size, bool *gzipped);
45 void http_client_timer_restart(struct http_client_ctx *client);
46 bool http_response_is_final(struct http_response_ctx *rsp, enum http_data_status status);
47 bool http_response_is_provided(struct http_response_ctx *rsp);
48 
49 /* TODO Could be static, but currently used in tests. */
50 int parse_http_frame_header(struct http_client_ctx *client, const uint8_t *buffer,
51 			    size_t buflen);
52 const char *get_frame_type_name(enum http2_frame_type type);
53 
54 void populate_request_ctx(struct http_request_ctx *req_ctx, uint8_t *data, size_t len,
55 			  struct http_header_capture_ctx *header_ctx);
56 
57 #endif /* HTTP_SERVER_INTERNAL_H_ */
58