Skip to content

Commit

Permalink
Berry webserver: allow to content_send bytes (#21479)
Browse files Browse the repository at this point in the history
  • Loading branch information
Staars committed May 24, 2024
1 parent 01bd6ec commit 1ca91a8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,21 @@ extern "C" {
be_raise(vm, kTypeError, nullptr);
}

// Berry: `webserver.content_send(string) -> nil`
// Berry: `webserver.content_send(string or bytes) -> nil`
//
int32_t w_webserver_content_send(struct bvm *vm);
int32_t w_webserver_content_send(struct bvm *vm) {
int32_t argc = be_top(vm); // Get the number of arguments
if (argc >= 1 && (be_isstring(vm, 1) || be_iscomptr(vm, 1))) {
if (argc >= 1 && (be_isstring(vm, 1) || be_iscomptr(vm, 1) || be_isbytes(vm, 1))) {
const char * html;
if (be_isstring(vm, 1)) {
html = be_tostring(vm, 1);
}
else if(be_isbytes(vm, 1)) {
size_t buf_len;
const char* buf_ptr = (const char*) be_tobytes(vm, 1, &buf_len);
WSContentSend(buf_ptr, buf_len);
be_return_nil(vm);
} else {
html = (const char*) be_tocomptr(vm, 1);
}
Expand Down

0 comments on commit 1ca91a8

Please sign in to comment.