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));
72 auth_required =
false;
88 String uri = req->uri;
91 char decoded_uri[uri.length() + 1];
93 String decoded_uri_str = String(decoded_uri);
96 int query_pos = decoded_uri_str.indexOf(
'?');
97 if (query_pos != -1) {
98 decoded_uri_str = decoded_uri_str.substring(0, query_pos);
102 String match_uri = handler->match_uri_;
105 if (match_uri.endsWith(
"*")) {
107 match_uri = match_uri.substring(0, match_uri.length() - 1);
109 if (decoded_uri_str.startsWith(match_uri)) {
110 if (handler->method_mask_ & (1 << req->method)) {
111 return handler->call(req);
114 }
else if (handler->match_uri_ == decoded_uri_str) {
115 if (handler->method_mask_ & (1 << req->method)) {
116 return handler->call(req);
121 return httpd_resp_send_404(req);
127 if (httpd_req_get_hdr_value_str(req,
"Host", host,
sizeof(host)) != ESP_OK) {
130 String host_hdr = host;
132 int pos = host_hdr.indexOf(
':');
134 host_hdr = host_hdr.substring(0, pos);
138 int sockfd = httpd_req_to_sockfd(req);
139 char ipstr[INET6_ADDRSTRLEN];
140 struct sockaddr_in6 addr;
141 socklen_t addr_size =
sizeof(addr);
142 if (getsockname(sockfd, (
struct sockaddr*)&addr, &addr_size) < 0) {
143 ESP_LOGE(__FILENAME__,
"Error getting client IP");
146 inet_ntop(AF_INET, &addr.sin6_addr.un.u32_addr[3], ipstr,
sizeof(ipstr));
151 if (ap_ip != ipstr) {
156 if (host_hdr != ap_ip) {
158 httpd_resp_set_status(req,
"302 Found");
159 String destination = String(
"http://") + ap_ip +
"/wifi";
160 httpd_resp_set_hdr(req,
"Location", destination.c_str());
161 httpd_resp_sendstr(req,
"Redirecting to captive portal");