This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int sockfd; | |
struct addrinfo hints, *servinfo, *p; | |
int rv; | |
memset(&hints, 0, sizeof hints); | |
hints.ai_family = AF_UNSPEC; // use AF_INET6 to force IPv6 | |
hints.ai_socktype = SOCK_STREAM; | |
if ((rv = getaddrinfo(host, "http", &hints, &servinfo)) != 0) { | |
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// server.on("/debug", HTTP_GET, dirList); | |
// server.on("/debug", HTTP_PUT, dirList); | |
// server.on("/debug", HTTP_POST, dirList); | |
void handleDebug() { | |
String message = "HTTP Request\n\n"; | |
message += "URI: "; | |
message += server.uri(); | |
message += "\nMethod: "; | |
message += (server.method() == HTTP_GET) ? "GET" : "POST"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// server.on("/dir", HTTP_GET, handleDirList); | |
void handleDirList() { | |
SPIFFS.begin(); | |
String str = ""; | |
Dir dir = SPIFFS.openDir("/"); | |
while (dir.next()) { | |
str += dir.fileName(); | |
str += " "; | |
str += dir.fileSize(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this serves all URLs that can be resolved to a file on the SPIFFS filesystem | |
// server.onNotFound(handleNotFound); | |
static String getContentType(const String& path) { | |
if (path.endsWith(".html")) return "text/html"; | |
else if (path.endsWith(".htm")) return "text/html"; | |
else if (path.endsWith(".css")) return "text/css"; | |
else if (path.endsWith(".txt")) return "text/plain"; | |
else if (path.endsWith(".js")) return "application/javascript"; | |
else if (path.endsWith(".png")) return "image/png"; |
NewerOlder