Просмотр исходного кода

Handle reference redirect like //www.site.org/test

See https://tools.ietf.org/html/rfc3986

The code is based on a pull request:
https://github.com/nagios-plugins/nagios-plugins/pull/148
I had to make a couple of small changes.
John C. Frickson 9 лет назад
Родитель
Сommit
d5fb1b067f
1 измененных файлов с 15 добавлено и 2 удалено
  1. 15 2
      plugins/check_http.c

+ 15 - 2
plugins/check_http.c

@@ -1404,7 +1404,9 @@ check_http (void)
 #define HD2 URI_HTTP "://" URI_HOST "/" URI_PATH
 #define HD3 URI_HTTP "://" URI_HOST ":" URI_PORT
 #define HD4 URI_HTTP "://" URI_HOST
-#define HD5 URI_PATH
+/* HD5 - relative reference redirect like //www.site.org/test https://tools.ietf.org/html/rfc3986 */
+#define HD5 URI_HTTP "//" URI_HOST "/" URI_PATH
+#define HD6 URI_PATH
 
 void
 redir (char *pos, char *status_line)
@@ -1482,8 +1484,19 @@ redir (char *pos, char *status_line)
       i = server_port_check (use_ssl);
     }
 
+    /* URI_HTTP, URI_HOST, URI_PATH */
+    else if (sscanf (pos, HD5, addr, url) == 2) {
+      if(use_ssl)
+        strcpy (type,"https");
+      else
+        strcpy (type,"server_type");
+      xasprintf(&url, "/%s", url);
+      use_ssl = server_type_check (type);
+      i = server_port_check (use_ssl);
+    }
+
     /* URI_PATH */
-    else if (sscanf (pos, HD5, url) == 1) {
+    else if (sscanf (pos, HD6, url) == 1) {
       /* relative url */
       if ((url[0] != '/')) {
         if ((x = strrchr(server_url, '/')))