From: Rich Bowen Date: Fri, 13 Nov 2009 12:38:55 +0000 (+0000) Subject: This is a really cool example, and I don't want to lose it. However, I'm X-Git-Tag: 2.3.4~54 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=95a33e73d010305928f38cf85470a86e032518a5;p=apache This is a really cool example, and I don't want to lose it. However, I'm reasonably sure that there's easier ways to do this, and I'm not yet sure that the example given actually works. Need to revisit this soon. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@835826 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/rewrite/advanced.html.en b/docs/manual/rewrite/advanced.html.en index af849d7157..271cc4c6cb 100644 --- a/docs/manual/rewrite/advanced.html.en +++ b/docs/manual/rewrite/advanced.html.en @@ -35,6 +35,7 @@ configuration.

See also

top
@@ -182,6 +183,158 @@ featureful than anything you can cobble together using mod_rewrite.

+
top
+
+

Document With Autorefresh

+ + + +
+
Description:
+ +
+

Wouldn't it be nice, while creating a complex web page, if + the web browser would automatically refresh the page every + time we save a new version from within our editor? + Impossible?

+
+ +
Solution:
+ +
+

No! We just combine the MIME multipart feature, the + web server NPH feature, and the URL manipulation power of + mod_rewrite. First, we establish a new + URL feature: Adding just :refresh to any + URL causes the 'page' to be refreshed every time it is + updated on the filesystem.

+ +
+RewriteRule   ^(/[uge]/[^/]+/?.*):refresh  /internal/cgi/apache/nph-refresh?f=$1
+
+ +

Now when we reference the URL

+ +
+/u/foo/bar/page.html:refresh
+
+ +

this leads to the internal invocation of the URL

+ +
+/internal/cgi/apache/nph-refresh?f=/u/foo/bar/page.html
+
+ +

The only missing part is the NPH-CGI script. Although + one would usually say "left as an exercise to the reader" + ;-) I will provide this, too.

+ +
+#!/sw/bin/perl
+##
+##  nph-refresh -- NPH/CGI script for auto refreshing pages
+##  Copyright (c) 1997 Ralf S. Engelschall, All Rights Reserved.
+##
+$| = 1;
+
+#   split the QUERY_STRING variable
+@pairs = split(/&/, $ENV{'QUERY_STRING'});
+foreach $pair (@pairs) {
+($name, $value) = split(/=/, $pair);
+$name =~ tr/A-Z/a-z/;
+$name = 'QS_' . $name;
+$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
+eval "\$$name = \"$value\"";
+}
+$QS_s = 1 if ($QS_s eq '');
+$QS_n = 3600 if ($QS_n eq '');
+if ($QS_f eq '') {
+print "HTTP/1.0 200 OK\n";
+print "Content-type: text/html\n\n";
+print "<b>ERROR</b>: No file given\n";
+exit(0);
+}
+if (! -f $QS_f) {
+print "HTTP/1.0 200 OK\n";
+print "Content-type: text/html\n\n";
+print "<b>ERROR</b>: File $QS_f not found\n";
+exit(0);
+}
+
+sub print_http_headers_multipart_begin {
+print "HTTP/1.0 200 OK\n";
+$bound = "ThisRandomString12345";
+print "Content-type: multipart/x-mixed-replace;boundary=$bound\n";
+&print_http_headers_multipart_next;
+}
+
+sub print_http_headers_multipart_next {
+print "\n--$bound\n";
+}
+
+sub print_http_headers_multipart_end {
+print "\n--$bound--\n";
+}
+
+sub displayhtml {
+local($buffer) = @_;
+$len = length($buffer);
+print "Content-type: text/html\n";
+print "Content-length: $len\n\n";
+print $buffer;
+}
+
+sub readfile {
+local($file) = @_;
+local(*FP, $size, $buffer, $bytes);
+($x, $x, $x, $x, $x, $x, $x, $size) = stat($file);
+$size = sprintf("%d", $size);
+open(FP, "<$file");
+$bytes = sysread(FP, $buffer, $size);
+close(FP);
+return $buffer;
+}
+
+$buffer = &readfile($QS_f);
+&print_http_headers_multipart_begin;
+&displayhtml($buffer);
+
+sub mystat {
+local($file) = $_[0];
+local($time);
+
+($x, $x, $x, $x, $x, $x, $x, $x, $x, $mtime) = stat($file);
+return $mtime;
+}
+
+$mtimeL = &mystat($QS_f);
+$mtime = $mtime;
+for ($n = 0; $n < $QS_n; $n++) {
+while (1) {
+    $mtime = &mystat($QS_f);
+    if ($mtime ne $mtimeL) {
+        $mtimeL = $mtime;
+        sleep(2);
+        $buffer = &readfile($QS_f);
+        &print_http_headers_multipart_next;
+        &displayhtml($buffer);
+        sleep(5);
+        $mtimeL = &mystat($QS_f);
+        last;
+    }
+    sleep($QS_s);
+}
+}
+
+&print_http_headers_multipart_end;
+
+exit(0);
+
+##EOF##
+
+
+
+

Available Languages:  en 

diff --git a/docs/manual/rewrite/advanced.xml b/docs/manual/rewrite/advanced.xml index 4446eb2bd9..86fe6abace 100644 --- a/docs/manual/rewrite/advanced.xml +++ b/docs/manual/rewrite/advanced.xml @@ -191,6 +191,156 @@ featureful than anything you can cobble together using mod_rewrite.

+
+ Document With Autorefresh + +
+
Description:
+ +
+

Wouldn't it be nice, while creating a complex web page, if + the web browser would automatically refresh the page every + time we save a new version from within our editor? + Impossible?

+
+ +
Solution:
+ +
+

No! We just combine the MIME multipart feature, the + web server NPH feature, and the URL manipulation power of + mod_rewrite. First, we establish a new + URL feature: Adding just :refresh to any + URL causes the 'page' to be refreshed every time it is + updated on the filesystem.

+ +
+RewriteRule   ^(/[uge]/[^/]+/?.*):refresh  /internal/cgi/apache/nph-refresh?f=$1
+
+ +

Now when we reference the URL

+ +
+/u/foo/bar/page.html:refresh
+
+ +

this leads to the internal invocation of the URL

+ +
+/internal/cgi/apache/nph-refresh?f=/u/foo/bar/page.html
+
+ +

The only missing part is the NPH-CGI script. Although + one would usually say "left as an exercise to the reader" + ;-) I will provide this, too.

+ +
+#!/sw/bin/perl
+##
+##  nph-refresh -- NPH/CGI script for auto refreshing pages
+##  Copyright (c) 1997 Ralf S. Engelschall, All Rights Reserved.
+##
+$| = 1;
+
+#   split the QUERY_STRING variable
+@pairs = split(/&/, $ENV{'QUERY_STRING'});
+foreach $pair (@pairs) {
+($name, $value) = split(/=/, $pair);
+$name =~ tr/A-Z/a-z/;
+$name = 'QS_' . $name;
+$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
+eval "\$$name = \"$value\"";
+}
+$QS_s = 1 if ($QS_s eq '');
+$QS_n = 3600 if ($QS_n eq '');
+if ($QS_f eq '') {
+print "HTTP/1.0 200 OK\n";
+print "Content-type: text/html\n\n";
+print "<b>ERROR</b>: No file given\n";
+exit(0);
+}
+if (! -f $QS_f) {
+print "HTTP/1.0 200 OK\n";
+print "Content-type: text/html\n\n";
+print "<b>ERROR</b>: File $QS_f not found\n";
+exit(0);
+}
+
+sub print_http_headers_multipart_begin {
+print "HTTP/1.0 200 OK\n";
+$bound = "ThisRandomString12345";
+print "Content-type: multipart/x-mixed-replace;boundary=$bound\n";
+&print_http_headers_multipart_next;
+}
+
+sub print_http_headers_multipart_next {
+print "\n--$bound\n";
+}
+
+sub print_http_headers_multipart_end {
+print "\n--$bound--\n";
+}
+
+sub displayhtml {
+local($buffer) = @_;
+$len = length($buffer);
+print "Content-type: text/html\n";
+print "Content-length: $len\n\n";
+print $buffer;
+}
+
+sub readfile {
+local($file) = @_;
+local(*FP, $size, $buffer, $bytes);
+($x, $x, $x, $x, $x, $x, $x, $size) = stat($file);
+$size = sprintf("%d", $size);
+open(FP, "<$file");
+$bytes = sysread(FP, $buffer, $size);
+close(FP);
+return $buffer;
+}
+
+$buffer = &readfile($QS_f);
+&print_http_headers_multipart_begin;
+&displayhtml($buffer);
+
+sub mystat {
+local($file) = $_[0];
+local($time);
+
+($x, $x, $x, $x, $x, $x, $x, $x, $x, $mtime) = stat($file);
+return $mtime;
+}
+
+$mtimeL = &mystat($QS_f);
+$mtime = $mtime;
+for ($n = 0; $n < $QS_n; $n++) {
+while (1) {
+    $mtime = &mystat($QS_f);
+    if ($mtime ne $mtimeL) {
+        $mtimeL = $mtime;
+        sleep(2);
+        $buffer = &readfile($QS_f);
+        &print_http_headers_multipart_next;
+        &displayhtml($buffer);
+        sleep(5);
+        $mtimeL = &mystat($QS_f);
+        last;
+    }
+    sleep($QS_s);
+}
+}
+
+&print_http_headers_multipart_end;
+
+exit(0);
+
+##EOF##
+
+
+
+ +
diff --git a/docs/manual/rewrite/rewrite_guide.html.en b/docs/manual/rewrite/rewrite_guide.html.en index b05eaed87b..f6e161dec9 100644 --- a/docs/manual/rewrite/rewrite_guide.html.en +++ b/docs/manual/rewrite/rewrite_guide.html.en @@ -51,7 +51,6 @@
  • Dynamic Mirror
  • Retrieve Missing Data from Intranet
  • New MIME-type, New Service
  • -
  • Document With Autorefresh
  • Mass Virtual Hosting
  • Proxy Deny
  • Referer-based Deflector
  • @@ -510,158 +509,6 @@ HREF="*"
    top
    -

    Document With Autorefresh

    - - - -
    -
    Description:
    - -
    -

    Wouldn't it be nice, while creating a complex web page, if - the web browser would automatically refresh the page every - time we save a new version from within our editor? - Impossible?

    -
    - -
    Solution:
    - -
    -

    No! We just combine the MIME multipart feature, the - web server NPH feature, and the URL manipulation power of - mod_rewrite. First, we establish a new - URL feature: Adding just :refresh to any - URL causes the 'page' to be refreshed every time it is - updated on the filesystem.

    - -
    -RewriteRule   ^(/[uge]/[^/]+/?.*):refresh  /internal/cgi/apache/nph-refresh?f=$1
    -
    - -

    Now when we reference the URL

    - -
    -/u/foo/bar/page.html:refresh
    -
    - -

    this leads to the internal invocation of the URL

    - -
    -/internal/cgi/apache/nph-refresh?f=/u/foo/bar/page.html
    -
    - -

    The only missing part is the NPH-CGI script. Although - one would usually say "left as an exercise to the reader" - ;-) I will provide this, too.

    - -
    -#!/sw/bin/perl
    -##
    -##  nph-refresh -- NPH/CGI script for auto refreshing pages
    -##  Copyright (c) 1997 Ralf S. Engelschall, All Rights Reserved.
    -##
    -$| = 1;
    -
    -#   split the QUERY_STRING variable
    -@pairs = split(/&/, $ENV{'QUERY_STRING'});
    -foreach $pair (@pairs) {
    -    ($name, $value) = split(/=/, $pair);
    -    $name =~ tr/A-Z/a-z/;
    -    $name = 'QS_' . $name;
    -    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    -    eval "\$$name = \"$value\"";
    -}
    -$QS_s = 1 if ($QS_s eq '');
    -$QS_n = 3600 if ($QS_n eq '');
    -if ($QS_f eq '') {
    -    print "HTTP/1.0 200 OK\n";
    -    print "Content-type: text/html\n\n";
    -    print "<b>ERROR</b>: No file given\n";
    -    exit(0);
    -}
    -if (! -f $QS_f) {
    -    print "HTTP/1.0 200 OK\n";
    -    print "Content-type: text/html\n\n";
    -    print "<b>ERROR</b>: File $QS_f not found\n";
    -    exit(0);
    -}
    -
    -sub print_http_headers_multipart_begin {
    -    print "HTTP/1.0 200 OK\n";
    -    $bound = "ThisRandomString12345";
    -    print "Content-type: multipart/x-mixed-replace;boundary=$bound\n";
    -    &print_http_headers_multipart_next;
    -}
    -
    -sub print_http_headers_multipart_next {
    -    print "\n--$bound\n";
    -}
    -
    -sub print_http_headers_multipart_end {
    -    print "\n--$bound--\n";
    -}
    -
    -sub displayhtml {
    -    local($buffer) = @_;
    -    $len = length($buffer);
    -    print "Content-type: text/html\n";
    -    print "Content-length: $len\n\n";
    -    print $buffer;
    -}
    -
    -sub readfile {
    -    local($file) = @_;
    -    local(*FP, $size, $buffer, $bytes);
    -    ($x, $x, $x, $x, $x, $x, $x, $size) = stat($file);
    -    $size = sprintf("%d", $size);
    -    open(FP, "<$file");
    -    $bytes = sysread(FP, $buffer, $size);
    -    close(FP);
    -    return $buffer;
    -}
    -
    -$buffer = &readfile($QS_f);
    -&print_http_headers_multipart_begin;
    -&displayhtml($buffer);
    -
    -sub mystat {
    -    local($file) = $_[0];
    -    local($time);
    -
    -    ($x, $x, $x, $x, $x, $x, $x, $x, $x, $mtime) = stat($file);
    -    return $mtime;
    -}
    -
    -$mtimeL = &mystat($QS_f);
    -$mtime = $mtime;
    -for ($n = 0; $n < $QS_n; $n++) {
    -    while (1) {
    -        $mtime = &mystat($QS_f);
    -        if ($mtime ne $mtimeL) {
    -            $mtimeL = $mtime;
    -            sleep(2);
    -            $buffer = &readfile($QS_f);
    -            &print_http_headers_multipart_next;
    -            &displayhtml($buffer);
    -            sleep(5);
    -            $mtimeL = &mystat($QS_f);
    -            last;
    -        }
    -        sleep($QS_s);
    -    }
    -}
    -
    -&print_http_headers_multipart_end;
    -
    -exit(0);
    -
    -##EOF##
    -
    -
    -
    - -
    top
    -

    Mass Virtual Hosting

    diff --git a/docs/manual/rewrite/rewrite_guide.xml b/docs/manual/rewrite/rewrite_guide.xml index 91f2ea9b54..81be74287b 100644 --- a/docs/manual/rewrite/rewrite_guide.xml +++ b/docs/manual/rewrite/rewrite_guide.xml @@ -505,158 +505,6 @@ HREF="*" -
    - - Document With Autorefresh - -
    -
    Description:
    - -
    -

    Wouldn't it be nice, while creating a complex web page, if - the web browser would automatically refresh the page every - time we save a new version from within our editor? - Impossible?

    -
    - -
    Solution:
    - -
    -

    No! We just combine the MIME multipart feature, the - web server NPH feature, and the URL manipulation power of - mod_rewrite. First, we establish a new - URL feature: Adding just :refresh to any - URL causes the 'page' to be refreshed every time it is - updated on the filesystem.

    - -
    -RewriteRule   ^(/[uge]/[^/]+/?.*):refresh  /internal/cgi/apache/nph-refresh?f=$1
    -
    - -

    Now when we reference the URL

    - -
    -/u/foo/bar/page.html:refresh
    -
    - -

    this leads to the internal invocation of the URL

    - -
    -/internal/cgi/apache/nph-refresh?f=/u/foo/bar/page.html
    -
    - -

    The only missing part is the NPH-CGI script. Although - one would usually say "left as an exercise to the reader" - ;-) I will provide this, too.

    - -
    -#!/sw/bin/perl
    -##
    -##  nph-refresh -- NPH/CGI script for auto refreshing pages
    -##  Copyright (c) 1997 Ralf S. Engelschall, All Rights Reserved.
    -##
    -$| = 1;
    -
    -#   split the QUERY_STRING variable
    -@pairs = split(/&/, $ENV{'QUERY_STRING'});
    -foreach $pair (@pairs) {
    -    ($name, $value) = split(/=/, $pair);
    -    $name =~ tr/A-Z/a-z/;
    -    $name = 'QS_' . $name;
    -    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    -    eval "\$$name = \"$value\"";
    -}
    -$QS_s = 1 if ($QS_s eq '');
    -$QS_n = 3600 if ($QS_n eq '');
    -if ($QS_f eq '') {
    -    print "HTTP/1.0 200 OK\n";
    -    print "Content-type: text/html\n\n";
    -    print "<b>ERROR</b>: No file given\n";
    -    exit(0);
    -}
    -if (! -f $QS_f) {
    -    print "HTTP/1.0 200 OK\n";
    -    print "Content-type: text/html\n\n";
    -    print "<b>ERROR</b>: File $QS_f not found\n";
    -    exit(0);
    -}
    -
    -sub print_http_headers_multipart_begin {
    -    print "HTTP/1.0 200 OK\n";
    -    $bound = "ThisRandomString12345";
    -    print "Content-type: multipart/x-mixed-replace;boundary=$bound\n";
    -    &print_http_headers_multipart_next;
    -}
    -
    -sub print_http_headers_multipart_next {
    -    print "\n--$bound\n";
    -}
    -
    -sub print_http_headers_multipart_end {
    -    print "\n--$bound--\n";
    -}
    -
    -sub displayhtml {
    -    local($buffer) = @_;
    -    $len = length($buffer);
    -    print "Content-type: text/html\n";
    -    print "Content-length: $len\n\n";
    -    print $buffer;
    -}
    -
    -sub readfile {
    -    local($file) = @_;
    -    local(*FP, $size, $buffer, $bytes);
    -    ($x, $x, $x, $x, $x, $x, $x, $size) = stat($file);
    -    $size = sprintf("%d", $size);
    -    open(FP, "<$file");
    -    $bytes = sysread(FP, $buffer, $size);
    -    close(FP);
    -    return $buffer;
    -}
    -
    -$buffer = &readfile($QS_f);
    -&print_http_headers_multipart_begin;
    -&displayhtml($buffer);
    -
    -sub mystat {
    -    local($file) = $_[0];
    -    local($time);
    -
    -    ($x, $x, $x, $x, $x, $x, $x, $x, $x, $mtime) = stat($file);
    -    return $mtime;
    -}
    -
    -$mtimeL = &mystat($QS_f);
    -$mtime = $mtime;
    -for ($n = 0; $n < $QS_n; $n++) {
    -    while (1) {
    -        $mtime = &mystat($QS_f);
    -        if ($mtime ne $mtimeL) {
    -            $mtimeL = $mtime;
    -            sleep(2);
    -            $buffer = &readfile($QS_f);
    -            &print_http_headers_multipart_next;
    -            &displayhtml($buffer);
    -            sleep(5);
    -            $mtimeL = &mystat($QS_f);
    -            last;
    -        }
    -        sleep($QS_s);
    -    }
    -}
    -
    -&print_http_headers_multipart_end;
    -
    -exit(0);
    -
    -##EOF##
    -
    -
    -
    - -
    -
    Mass Virtual Hosting