41 ESP_LOGI(__FILENAME__,
"Handling request: %s", req->uri);
52 int sockfd = httpd_req_to_sockfd(req);
53 char ipstr[INET6_ADDRSTRLEN];
54 struct sockaddr_in6 addr;
55 socklen_t addr_size =
sizeof(addr);
56 if (getsockname(sockfd, (
struct sockaddr*)&addr, &addr_size) < 0) {
57 ESP_LOGE(__FILENAME__,
"Error getting client IP");
60 inet_ntop(AF_INET, &addr.sin6_addr.un.u32_addr[3], ipstr,
sizeof(ipstr));
62 String ap_ip = WiFi.softAPIP().toString();
70 auth_required =
false;
86 String uri = req->uri;
89 char decoded_uri[uri.length() + 1];
91 String decoded_uri_str = String(decoded_uri);
94 int query_pos = decoded_uri_str.indexOf(
'?');
95 if (query_pos != -1) {
96 decoded_uri_str = decoded_uri_str.substring(0, query_pos);
100 String match_uri = handler->match_uri_;
103 if (match_uri.endsWith(
"*")) {
105 match_uri = match_uri.substring(0, match_uri.length() - 1);
107 if (decoded_uri_str.startsWith(match_uri)) {
108 if (handler->method_mask_ & (1 << req->method)) {
109 return handler->call(req);
112 }
else if (handler->match_uri_ == decoded_uri_str) {
113 if (handler->method_mask_ & (1 << req->method)) {
114 return handler->call(req);
119 return httpd_resp_send_404(req);
125 if (httpd_req_get_hdr_value_str(req,
"Host", host,
sizeof(host)) != ESP_OK) {
128 String host_hdr = host;
130 int pos = host_hdr.indexOf(
':');
132 host_hdr = host_hdr.substring(0, pos);
136 int sockfd = httpd_req_to_sockfd(req);
137 char ipstr[INET6_ADDRSTRLEN];
138 struct sockaddr_in6 addr;
139 socklen_t addr_size =
sizeof(addr);
140 if (getsockname(sockfd, (
struct sockaddr*)&addr, &addr_size) < 0) {
141 ESP_LOGE(__FILENAME__,
"Error getting client IP");
144 inet_ntop(AF_INET, &addr.sin6_addr.un.u32_addr[3], ipstr,
sizeof(ipstr));
146 String ap_ip = WiFi.softAPIP().toString();
149 if (ap_ip != ipstr) {
154 if (host_hdr != ap_ip) {
156 httpd_resp_set_status(req,
"302 Found");
157 String destination = String(
"http://") + ap_ip +
"/wifi";
158 httpd_resp_set_hdr(req,
"Location", destination.c_str());
159 httpd_resp_sendstr(req,
"Redirecting to captive portal");