A bit more cleanup

This commit is contained in:
Scott Shawcroft 2022-07-11 14:53:20 -07:00
parent 8cfdfb95f7
commit 425a0efeca
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
3 changed files with 9 additions and 21 deletions

View File

@ -26,13 +26,6 @@
#include "shared-bindings/hashlib/Hash.h" #include "shared-bindings/hashlib/Hash.h"
// #include "shared-bindings/util.h"
// #include "shared/runtime/buffer_helper.h"
// #include "shared/runtime/interrupt_char.h"
// #include "py/mperrno.h"
// #include "py/mphal.h"
#include "py/obj.h" #include "py/obj.h"
#include "py/objproperty.h" #include "py/objproperty.h"
#include "py/objstr.h" #include "py/objstr.h"

View File

@ -21,7 +21,6 @@ function onSubmit() {
input.focus(); input.focus();
} }
// Connect to Web Socket
ws = new WebSocket("ws://" + window.location.host + "/cp/serial/"); ws = new WebSocket("ws://" + window.location.host + "/cp/serial/");
ws.onopen = function() { ws.onopen = function() {
@ -32,7 +31,6 @@ var setting_title = false;
var encoder = new TextEncoder(); var encoder = new TextEncoder();
var left_count = 0; var left_count = 0;
ws.onmessage = function(e) { ws.onmessage = function(e) {
// e.data contains received string.
if (e.data == "\x1b]0;") { if (e.data == "\x1b]0;") {
setting_title = true; setting_title = true;
title.textContent = ""; title.textContent = "";

View File

@ -522,10 +522,16 @@ static void _reply_redirect(socketpool_socket_obj_t *socket, _request *request,
"HTTP/1.1 301 Moved Permanently\r\n", "HTTP/1.1 301 Moved Permanently\r\n",
"Connection: close\r\n", "Connection: close\r\n",
"Content-Length: 0\r\n", "Content-Length: 0\r\n",
"Location: http://", hostname, ".local", path, "\r\n", NULL); "Location: ", NULL);
if (request->websocket) {
_send_str(socket, "ws");
} else {
_send_str(socket, "http");
}
_send_strs(socket, "://", hostname, ".local", path, "\r\n", NULL);
_cors_header(socket, request); _cors_header(socket, request);
_send_str(socket, "\r\n"); _send_str(socket, "\r\n");
ESP_LOGI(TAG, "redirect");
} }
static void _reply_directory_json(socketpool_socket_obj_t *socket, _request *request, FF_DIR *dir, const char *request_path, const char *path) { static void _reply_directory_json(socketpool_socket_obj_t *socket, _request *request, FF_DIR *dir, const char *request_path, const char *path) {
@ -853,10 +859,7 @@ static void _reply_static(socketpool_socket_obj_t *socket, _request *request, co
#define _REPLY_STATIC(socket, request, filename) _reply_static(socket, request, filename, filename##_length, filename##_content_type) #define _REPLY_STATIC(socket, request, filename) _reply_static(socket, request, filename, filename##_length, filename##_content_type)
static void _reply_websocket_upgrade(socketpool_socket_obj_t *socket, _request *request) { static void _reply_websocket_upgrade(socketpool_socket_obj_t *socket, _request *request) {
ESP_LOGI(TAG, "websocket!");
// Compute accept key // Compute accept key
hashlib_hash_obj_t hash; hashlib_hash_obj_t hash;
common_hal_hashlib_new(&hash, "sha1"); common_hal_hashlib_new(&hash, "sha1");
@ -876,8 +879,6 @@ static void _reply_websocket_upgrade(socketpool_socket_obj_t *socket, _request *
"Sec-WebSocket-Accept: ", encoded_accept, "\r\n", "Sec-WebSocket-Accept: ", encoded_accept, "\r\n",
"\r\n", NULL); "\r\n", NULL);
websocket_handoff(socket); websocket_handoff(socket);
ESP_LOGI(TAG, "socket upgrade done");
// socket is now closed and "disconnected". // socket is now closed and "disconnected".
} }
@ -885,7 +886,7 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) {
if (request->redirect) { if (request->redirect) {
_reply_redirect(socket, request, request->path); _reply_redirect(socket, request, request->path);
} else if (strlen(request->origin) > 0 && !_origin_ok(request->origin)) { } else if (strlen(request->origin) > 0 && !_origin_ok(request->origin)) {
ESP_LOGI(TAG, "bad origin %s", request->origin); ESP_LOGE(TAG, "bad origin %s", request->origin);
_reply_forbidden(socket, request); _reply_forbidden(socket, request);
} else if (memcmp(request->path, "/fs/", 4) == 0) { } else if (memcmp(request->path, "/fs/", 4) == 0) {
if (!request->authenticated) { if (!request->authenticated) {
@ -1199,7 +1200,6 @@ static void _process_request(socketpool_socket_obj_t *socket, _request *request)
return; return;
} }
bool reload = _reply(socket, request); bool reload = _reply(socket, request);
ESP_LOGI(TAG, "reply done");
_reset_request(request); _reset_request(request);
autoreload_resume(AUTORELOAD_SUSPEND_WEB); autoreload_resume(AUTORELOAD_SUSPEND_WEB);
if (reload) { if (reload) {
@ -1217,12 +1217,10 @@ void supervisor_web_workflow_background(void) {
uint32_t port; uint32_t port;
int newsoc = socketpool_socket_accept(&listening, (uint8_t *)&ip, &port); int newsoc = socketpool_socket_accept(&listening, (uint8_t *)&ip, &port);
if (newsoc == -EBADF) { if (newsoc == -EBADF) {
ESP_LOGI(TAG, "listen closed");
common_hal_socketpool_socket_close(&listening); common_hal_socketpool_socket_close(&listening);
return; return;
} }
if (newsoc > 0) { if (newsoc > 0) {
ESP_LOGI(TAG, "new socket %d", newsoc);
// Close the active socket because we have another we accepted. // Close the active socket because we have another we accepted.
if (!common_hal_socketpool_socket_get_closed(&active)) { if (!common_hal_socketpool_socket_get_closed(&active)) {
common_hal_socketpool_socket_close(&active); common_hal_socketpool_socket_close(&active);
@ -1243,7 +1241,6 @@ void supervisor_web_workflow_background(void) {
// If we have a request in progress, continue working on it. // If we have a request in progress, continue working on it.
if (common_hal_socketpool_socket_get_connected(&active)) { if (common_hal_socketpool_socket_get_connected(&active)) {
// ESP_LOGI(TAG, "active connected %d", active_request.in_progress);
_process_request(&active, &active_request); _process_request(&active, &active_request);
} }
} }