45 const char* query = strchr(req->uri,
'?');
46 int path_len = query ?
static_cast<int>(query - req->uri)
47 :
static_cast<int>(strlen(req->uri));
48 ESP_LOGI(__FILENAME__,
"Handling request: %.*s", path_len, req->uri);
59 int sockfd = httpd_req_to_sockfd(req);
60 char ipstr[INET6_ADDRSTRLEN];
61 struct sockaddr_in6 addr;
62 socklen_t addr_size =
sizeof(addr);
63 if (getsockname(sockfd, (
struct sockaddr*)&addr, &addr_size) < 0) {
64 ESP_LOGE(__FILENAME__,
"Error getting client IP");
67 inet_ntop(AF_INET, &addr.sin6_addr.un.u32_addr[3], ipstr,
sizeof(ipstr));
79 auth_required =
false;
95 String uri = req->uri;
98 char decoded_uri[uri.length() + 1];
100 String decoded_uri_str = String(decoded_uri);
103 int query_pos = decoded_uri_str.indexOf(
'?');
104 if (query_pos != -1) {
105 decoded_uri_str = decoded_uri_str.substring(0, query_pos);
109 String match_uri = handler->match_uri_;
112 if (match_uri.endsWith(
"*")) {
114 match_uri = match_uri.substring(0, match_uri.length() - 1);
116 if (decoded_uri_str.startsWith(match_uri)) {
117 if (handler->method_mask_ & (1 << req->method)) {
118 return handler->call(req);
121 }
else if (handler->match_uri_ == decoded_uri_str) {
122 if (handler->method_mask_ & (1 << req->method)) {
123 return handler->call(req);
128 return httpd_resp_send_404(req);
134 if (httpd_req_get_hdr_value_str(req,
"Host", host,
sizeof(host)) != ESP_OK) {
137 String host_hdr = host;
139 int pos = host_hdr.indexOf(
':');
141 host_hdr = host_hdr.substring(0, pos);
145 int sockfd = httpd_req_to_sockfd(req);
146 char ipstr[INET6_ADDRSTRLEN];
147 struct sockaddr_in6 addr;
148 socklen_t addr_size =
sizeof(addr);
149 if (getsockname(sockfd, (
struct sockaddr*)&addr, &addr_size) < 0) {
150 ESP_LOGE(__FILENAME__,
"Error getting client IP");
153 inet_ntop(AF_INET, &addr.sin6_addr.un.u32_addr[3], ipstr,
sizeof(ipstr));
158 if (ap_ip != ipstr) {
163 if (host_hdr != ap_ip) {
165 httpd_resp_set_status(req,
"302 Found");
166 String destination = String(
"http://") + ap_ip +
"/wifi";
167 httpd_resp_set_hdr(req,
"Location", destination.c_str());
168 httpd_resp_sendstr(req,
"Redirecting to captive portal");