moonming commented on a change in pull request #1217: enable local DNS
URL: https://github.com/apache/incubator-apisix/pull/1217#discussion_r393468088
 
 

 ##########
 File path: t/APISIX.pm
 ##########
 @@ -37,6 +37,38 @@ sub read_file($) {
     $data;
 }
 
+sub local_dns_resolver() {
+    open my $in, "/etc/resolv.conf" or die "cannot open /etc/resolv.conf";
+    my @lines =  <$in>;
+    my @dns_addrs = ();
+    foreach my $line (@lines){
+        $line =~ m/^nameserver\s+(\d+[.]\d+[.]\d+[.]\d+)\s*$/;
+        if ($1) {
+            push(@dns_addrs, $1);
+        }
+    }
+    close($in);
+    return @dns_addrs
+}
+
+
+my $dns_addrs_str = "";
+my $dns_addrs_tbl_str = "";
+my $enable_local_dns = 0;
+if ($enable_local_dns) {
+    my @dns_addrs = local_dns_resolver();
+    $dns_addrs_tbl_str = "{";
+    foreach my $addr (@dns_addrs){
+        $dns_addrs_str = "$dns_addrs_str $addr";
+        $dns_addrs_tbl_str = "$dns_addrs_tbl_str\"$addr\", ";
+    }
+    $dns_addrs_tbl_str = "$dns_addrs_tbl_str}";
+} else {
+    $dns_addrs_str = "8.8.8.8 114.114.114.114";
+    $dns_addrs_tbl_str = "{\"8.8.8.8\", \"114.114.114.114\"}";
+}
+
+
 
 Review comment:
   why modify `t/APISIX.pm`? which is just for test cases. And you hard-code 
`enable_local_dns=0`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to