@@ -522,10 +522,16 @@ static void _reply_redirect(socketpool_socket_obj_t *socket, _request *request,
522
522
"HTTP/1.1 301 Moved Permanently\r\n" ,
523
523
"Connection: close\r\n" ,
524
524
"Content-Length: 0\r\n" ,
525
- "Location: http://" , hostname , ".local" , path , "\r\n" , NULL );
525
+ "Location: " , NULL );
526
+ if (request -> websocket ) {
527
+ _send_str (socket , "ws" );
528
+ } else {
529
+ _send_str (socket , "http" );
530
+ }
531
+
532
+ _send_strs (socket , "://" , hostname , ".local" , path , "\r\n" , NULL );
526
533
_cors_header (socket , request );
527
534
_send_str (socket , "\r\n" );
528
- ESP_LOGI (TAG , "redirect" );
529
535
}
530
536
531
537
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
853
859
854
860
#define _REPLY_STATIC (socket , request , filename ) _reply_static(socket, request, filename, filename##_length, filename##_content_type)
855
861
856
-
857
-
858
862
static void _reply_websocket_upgrade (socketpool_socket_obj_t * socket , _request * request ) {
859
- ESP_LOGI (TAG , "websocket!" );
860
863
// Compute accept key
861
864
hashlib_hash_obj_t hash ;
862
865
common_hal_hashlib_new (& hash , "sha1" );
@@ -876,16 +879,14 @@ static void _reply_websocket_upgrade(socketpool_socket_obj_t *socket, _request *
876
879
"Sec-WebSocket-Accept: " , encoded_accept , "\r\n" ,
877
880
"\r\n" , NULL );
878
881
websocket_handoff (socket );
879
-
880
- ESP_LOGI (TAG , "socket upgrade done" );
881
882
// socket is now closed and "disconnected".
882
883
}
883
884
884
885
static bool _reply (socketpool_socket_obj_t * socket , _request * request ) {
885
886
if (request -> redirect ) {
886
887
_reply_redirect (socket , request , request -> path );
887
888
} else if (strlen (request -> origin ) > 0 && !_origin_ok (request -> origin )) {
888
- ESP_LOGI (TAG , "bad origin %s" , request -> origin );
889
+ ESP_LOGE (TAG , "bad origin %s" , request -> origin );
889
890
_reply_forbidden (socket , request );
890
891
} else if (memcmp (request -> path , "/fs/" , 4 ) == 0 ) {
891
892
if (!request -> authenticated ) {
@@ -1199,7 +1200,6 @@ static void _process_request(socketpool_socket_obj_t *socket, _request *request)
1199
1200
return ;
1200
1201
}
1201
1202
bool reload = _reply (socket , request );
1202
- ESP_LOGI (TAG , "reply done" );
1203
1203
_reset_request (request );
1204
1204
autoreload_resume (AUTORELOAD_SUSPEND_WEB );
1205
1205
if (reload ) {
@@ -1217,12 +1217,10 @@ void supervisor_web_workflow_background(void) {
1217
1217
uint32_t port ;
1218
1218
int newsoc = socketpool_socket_accept (& listening , (uint8_t * )& ip , & port );
1219
1219
if (newsoc == - EBADF ) {
1220
- ESP_LOGI (TAG , "listen closed" );
1221
1220
common_hal_socketpool_socket_close (& listening );
1222
1221
return ;
1223
1222
}
1224
1223
if (newsoc > 0 ) {
1225
- ESP_LOGI (TAG , "new socket %d" , newsoc );
1226
1224
// Close the active socket because we have another we accepted.
1227
1225
if (!common_hal_socketpool_socket_get_closed (& active )) {
1228
1226
common_hal_socketpool_socket_close (& active );
@@ -1243,7 +1241,6 @@ void supervisor_web_workflow_background(void) {
1243
1241
1244
1242
// If we have a request in progress, continue working on it.
1245
1243
if (common_hal_socketpool_socket_get_connected (& active )) {
1246
- // ESP_LOGI(TAG, "active connected %d", active_request.in_progress);
1247
1244
_process_request (& active , & active_request );
1248
1245
}
1249
1246
}
0 commit comments