Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
esp32-http-server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
esp32-http-server
Commits
73679ecd
Commit
73679ecd
authored
May 17, 2018
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add config options in menuconfig to enable/disable https and examples
parent
baf849bf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
14 deletions
+45
-14
Kconfig.projbuild
Kconfig.projbuild
+24
-0
https_server.c
https_server.c
+17
-12
https_server.h
https_server.h
+4
-2
No files found.
Kconfig.projbuild
0 → 100644
View file @
73679ecd
menu "HTTPD Server"
choice HTTPS_SERVER_MODE
prompt "http or https"
default HTTPS_SERVER_DISABLED
help
Wheter the http server is secure or not
config HTTPS_SERVER_ENABLED
bool "Https enabled"
config HTTPS_SERVER_DISABLED
bool "Https disabled"
endchoice
config HTTPS_SERVER
bool
default y if HTTPS_SERVER_ENABLED
default n if HTTPS_SERVER_DISABLED
config HTTPD_EXAMPLE
bool "Enable HTTP POST/GET Example functions"
default n
https_server.c
View file @
73679ecd
...
...
@@ -51,6 +51,8 @@
#define MBEDTLS_EXAMPLE_RECV_BUF_LEN 1024
#define HTTPD_EXAMPLE CONFIG_HTTPD_EXAMPLE
typedef
enum
{
HTTP_PARSING_URI
,
//!< HTTP_PARSING_URI
HTTP_PARSING_HEADER_NAME
,
//!< HTTP_PARSING_HEADER_NAME
...
...
@@ -102,7 +104,7 @@ struct http_context_ {
const
char
*
data_ptr
;
size_t
data_size
;
http_header_list_t
request_args
;
#if
def
HTTPS_SERVER
#if HTTPS_SERVER
mbedtls_ssl_context
*
ssl_conn
;
mbedtls_net_context
*
client_fd
;
#else
...
...
@@ -118,7 +120,7 @@ struct http_server_context_ {
SLIST_HEAD
(,
http_handler_t
)
handlers
;
_lock_t
handlers_lock
;
struct
http_context_
connection_context
;
#if
def
HTTPS_SERVER
#if HTTPS_SERVER
mbedtls_net_context
*
listen_fd
;
mbedtls_entropy_context
*
entropy
;
mbedtls_ctr_drbg_context
*
ctr_drbg
;
...
...
@@ -552,7 +554,7 @@ static esp_err_t http_send_response_headers(http_context_t http_ctx)
headers_list_clear
(
&
http_ctx
->
response_headers
);
#if
def
HTTPS_SERVER
#if HTTPS_SERVER
int
ret
;
int
actual_len
;
ESP_LOGI
(
TAG
,
"Writing response headers..."
);
...
...
@@ -636,7 +638,7 @@ esp_err_t http_response_write(http_context_t http_ctx, const http_buffer_t* buff
}
}
len
=
buffer
->
size
?
buffer
->
size
:
strlen
((
const
char
*
)
buffer
->
data
);
#if
def
HTTPS_SERVER
#if HTTPS_SERVER
ESP_LOGI
(
TAG
,
"Writing to client:"
);
ret
=
0
;
do
...
...
@@ -776,7 +778,7 @@ static void http_handle_connection(http_server_t server, void *arg_conn)
/* Initialize context */
ctx
->
state
=
HTTP_PARSING_URI
;
#if
def
HTTPS_SERVER
#if HTTPS_SERVER
#else
struct
netbuf
*
inbuf
=
NULL
;
u16_t
buflen
;
...
...
@@ -796,7 +798,7 @@ static void http_handle_connection(http_server_t server, void *arg_conn)
.
on_message_complete
=
&
http_message_done_cb
};
#if
def
HTTPS_SERVER
#if HTTPS_SERVER
int
ret
;
size_t
parsed_bytes
=
0
;
/*
...
...
@@ -860,7 +862,7 @@ static void http_handle_connection(http_server_t server, void *arg_conn)
}
#endif
#if
def
HTTPS_SERVER
#if HTTPS_SERVER
if
(
ret
>
0
)
{
ctx
->
state
=
HTTP_COLLECTING_RESPONSE_HEADERS
;
if
(
ctx
->
handler
==
NULL
)
{
...
...
@@ -891,7 +893,7 @@ static void http_handle_connection(http_server_t server, void *arg_conn)
ctx
->
uri
=
NULL
;
ctx
->
handler
=
NULL
;
#if
def
HTTPS_SERVER
#if HTTPS_SERVER
ESP_LOGI
(
TAG
,
"Closing the connection..."
);
while
(
(
ret
=
mbedtls_ssl_close_notify
(
server
->
connection_context
.
ssl_conn
)
)
<
0
)
{
...
...
@@ -934,7 +936,7 @@ static void http_server(void *arg)
//If server has not successfully been started yet,
if
(
!
(
bits
&
SERVER_STARTED_BIT
))
{
#if
def
HTTPS_SERVER
#if HTTPS_SERVER
char
*
error_buf
;
ESP_LOGV
(
TAG
,
"Declaring local mbedTLS context on task..."
);
int
ret
;
...
...
@@ -1291,7 +1293,7 @@ esp_err_t http_server_start(const http_server_options_t* options, http_server_t*
esp_err_t
http_server_stop
(
http_server_t
server
)
{
/* FIXME: figure out a thread safe way to do this */
#if
def
HTTPS_SERVER
#if HTTPS_SERVER
/* FIXME: Add function to stop HTTPS */
#else
netconn_close
(
server
->
server_conn
);
...
...
@@ -1301,6 +1303,8 @@ esp_err_t http_server_stop(http_server_t server)
return
ESP_OK
;
}
#if HTTPD_EXAMPLE
static
void
cb_GET_method
(
http_context_t
http_ctx
,
void
*
ctx
)
{
size_t
response_size
=
strlen
(
index_html
);
...
...
@@ -1313,7 +1317,7 @@ static void cb_GET_method(http_context_t http_ctx, void* ctx)
esp_err_t
simple_GET_method_example
(
void
)
{
http_server_t
server
;
#if
def
HTTPS_SERVER
#if HTTPS_SERVER
http_server_options_t
http_options
=
HTTPS_SERVER_OPTIONS_DEFAULT
();
#else
http_server_options_t
http_options
=
HTTP_SERVER_OPTIONS_DEFAULT
();
...
...
@@ -1361,7 +1365,7 @@ static void cb_POST_method(http_context_t http_ctx, void* ctx)
esp_err_t
simple_POST_method_example
(
void
)
{
http_server_t
server
;
#if
def
HTTPS_SERVER
#if HTTPS_SERVER
http_server_options_t
http_options
=
HTTPS_SERVER_OPTIONS_DEFAULT
();
#else
http_server_options_t
http_options
=
HTTP_SERVER_OPTIONS_DEFAULT
();
...
...
@@ -1380,3 +1384,4 @@ esp_err_t simple_POST_method_example(void)
return
res
;
}
#endif // HTTPD_EXAMPLE
https_server.h
View file @
73679ecd
...
...
@@ -43,8 +43,10 @@ extern "C" {
/** Error buffer length */
#define ERROR_BUF_LENGTH 100
/** Uncomment to enable secure server */
#define HTTPS_SERVER
#define HTTPS_SERVER CONFIG_HTTPS_SERVER
#define HTTPD_EXAMPLE CONFIG_HTTPD_EXAMPLE
/** Opaque type representing single HTTP connection */
typedef
struct
http_context_
*
http_context_t
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment