Skip to content

Commit

Permalink
Berry webserver.header to read browser sent headers (arendst#20447)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hadinger authored Jan 9, 2024
1 parent 8712aba commit 85fb54f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
- Berry add `string` to `bytes()` (#20420)
- Berry button to dynamically load GPIO Viewer with Berry backend (#20424)
- Berry `debug_panel.tapp` to display real-time heap and wifi rssi
- Berry `webserver.header` to read browser sent headers

### Breaking Changed

Expand Down
3 changes: 3 additions & 0 deletions lib/libesp32/berry_tasmota/src/be_webserver_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern int w_webserver_arg(bvm *vm);
extern int w_webserver_arg_name(bvm *vm);
extern int w_webserver_has_arg(bvm *vm);

extern int w_webserver_header(bvm *vm);

// To allow a full restart of the Berry VM, we need to supplement the webserver Request Handler
// model from Arduino framework.
Expand Down Expand Up @@ -160,6 +161,8 @@ module webserver (scope: global) {
arg, func(w_webserver_arg)
arg_name, func(w_webserver_arg_name)
has_arg, func(w_webserver_has_arg)
header, func(w_webserver_header)
}
@const_object_info_end */
#include "be_fixed_webserver.h"
Expand Down
17 changes: 17 additions & 0 deletions tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,23 @@ extern "C" {
be_raise(vm, kTypeError, nullptr);
}

// Berry: `webserver.header(name:string) -> string or nil`
int32_t w_webserver_header(struct bvm *vm);
int32_t w_webserver_header(struct bvm *vm) {
int32_t argc = be_top(vm); // Get the number of arguments
if (argc >= 1 && be_isstring(vm, 1)) {
const char * header_name = be_tostring(vm, 1);
String header = Webserver->header(header_name);
if (header.length() > 0) {
be_pushstring(vm, header.c_str());
be_return(vm);
} else {
be_return_nil(vm);
}
}
be_raise(vm, kTypeError, nullptr);
}

}

#endif // USE_WEBSERVER
Expand Down

0 comments on commit 85fb54f

Please sign in to comment.