Kyle Berezin
Kyle Berezin

Reputation: 649

Esp32 Arduino SPIFFS Based Static Web Addresses Case Sensitive

I am trying to make a static webserver on an ESP32 via PlatformIO. I am using the built in "Upload Filesystem" task in PlatformIO to upload a www folder. I then use server.serveStatic("/", SPIFFS, "/www/"); to serve the pages. The issue is the url is case sensitive, and I need them to not be.

I assume this is due to the underlying SPIFFS filesystem, and to fix it I should somehow change that.

Upvotes: 0

Views: 318

Answers (1)

Codebreaker007
Codebreaker007

Reputation: 2989

Assuming you are using the standard ESP32 webserver library you could do the following: In your handler function compare the path argument you get with

webServer.uri()

which is a char array then use int strcasecmp(const char *s1, const char *s2); the function part would be

if (strcasecmp (webServer.uri(), "www/mysmallcapslink.html") == 0) {
... do your stuff here ...
e.g. serve the file
}

Note == 0 means the two strings (C-strings with small s) are identic (apart from the case). So url requests like www/Mysmallcapslink.html www/MySmallCapsLink.html would all be handled by the same handler.

Info about srtcasecmp:

DESCRIPTION The strcasecmp() function shall compare, while ignoring differences in case, the string pointed to by s1 to the string pointed to by s2. The strncasecmp() function shall compare, while ignoring differences in case, not more than n bytes from the string pointed to by s1 to the string pointed to by s2.

strncasecmp() shall behave as if the strings had been converted to lowercase and then a byte comparison performed.

RETURN VALUE Upon completion, strcasecmp() shall return an integer greater than, equal to, or less than 0, if the string pointed to by s1 is, ignoring case, greater than, equal to, or less than the string pointed to by s2, respectively.

Upvotes: 1

Related Questions