@@ -375,11 +375,10 @@ static bool _origin_ok(const char *origin) {
375
375
return true;
376
376
}
377
377
378
- // Port or no port
379
378
const char * localhost = "127.0.0.1" ;
380
- const int locallen = 9 ;
381
- if (memcmp (origin + strlen (http ), localhost , locallen ) == 0
382
- && (localhost [ locallen ] == '\0' || localhost [ locallen ] == ':' )) {
379
+ end = origin + strlen ( http ) + strlen ( localhost ) ;
380
+ if (memcmp (origin + strlen (http ), localhost , strlen ( localhost ) ) == 0
381
+ && (end [ 0 ] == '\0' || end [ 0 ] == ':' )) {
383
382
return true;
384
383
}
385
384
@@ -913,8 +912,10 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) {
913
912
ESP_LOGE (TAG , "bad origin %s" , request -> origin );
914
913
_reply_forbidden (socket , request );
915
914
} else if (memcmp (request -> path , "/fs/" , 4 ) == 0 ) {
916
- // OPTIONS is sent for CORS preflight, unauthenticated
917
- if (!request -> authenticated && strcmp (request -> method , "OPTIONS" ) != 0 ) {
915
+ if (strcmp (request -> method , "OPTIONS" ) == 0 ) {
916
+ // OPTIONS is sent for CORS preflight, unauthenticated
917
+ _reply_access_control (socket , request );
918
+ } else if (!request -> authenticated ) {
918
919
if (_api_password [0 ] != '\0' ) {
919
920
_reply_unauthorized (socket , request );
920
921
} else {
@@ -935,9 +936,7 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) {
935
936
}
936
937
// Delete is almost identical for files and directories so share the
937
938
// implementation.
938
- if (strcmp (request -> method , "OPTIONS" ) == 0 ) {
939
- _reply_access_control (socket , request );
940
- } else if (strcmp (request -> method , "DELETE" ) == 0 ) {
939
+ if (strcmp (request -> method , "DELETE" ) == 0 ) {
941
940
if (_usb_active ()) {
942
941
_reply_conflict (socket , request );
943
942
return false;
0 commit comments