[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Web Server

Sorry it took a little while to get back to you, I've been travelling.

> I am currently using your web server and have a couple of questions:
> 1) How can I do remote administration and what all can be administered?
Theres no 'cool' remote administration interface. You can always use
telnet to access the server machine and directly modify the file
config.pi3 using a text editor, you could a little CGI program in a 
new protected cgi-admin realm and remotely restart the server also.

This follows the model used by UNIX servers. 

At some point I could extend EnhPi3 to work remotely - or write a 
CGI based admin - but none exists right now.

> 2) I'm trying to use a webcam program to put updated photos on my page.

> The problem is that the web server stores information in cache and uses
> that so even if I change the picture or even delete it from my drive, the
> same picture keeps coming up.  How can I change this?
Very interesting question, and I'd like to answer it in detail so I 
can post it also to the user list and get it archived. 

Pi3Web does not currently cache files, and I don't think it ever will
(if server caching is added, as it probably will be - it will not
be the default). This is because server caching just causes a lot of
confusion and not a whole lot of performance gain.

What is happening in your case is that the browser is caching the request,
you should be able to test this immediately by clearing all browser caches
and reducing memory and disk caches (temporarily) to 0 - notice any change
 --> then its the browser cache. Another thing to test is >> Explicity <<
hit reload, this forces the browser to at least ask the server the last
modification time of the file - in this case the if the file has been
written more recently than the browsers copy, the server will send the 
entire file and the browser will display the new one. Now these
things alway you to >> test << that the browser caching the server
file is the problem.

Fortunately theres a lot of options available to make the server tell the
browser (and any intervening proxy servers) not to cache the file.

But first:

A Real Quick Overview of HTTP WRT Caching
The browser requests an item in the following way

	GET /item.gif HTTP/1.0
	If-Modified-Since: Sat, 01 Nov 1997 19:09:10 GMT

The [If-Modified-Since] is optional and requests that the server
return a 302 (Not Modified) code if item.gif has not been modified
since the date supplied. Browsers use this to update the timestamp of
cache items.

A server typically responds with 

    HTTP/1.0 200 OK
    Server: foo
    Last-Modified-Date: Sun, 02 Nov 1997 19:09:10 GMT

If the resource has been modified since the browser cache date 
(If-Modified-Since) or

    HTTP/1.0 302 Not Modified

If the file has not been modified.

If browser have a recently retrieved file, they will typically not
even make a conditional get request (If-Modified-Since), they just 
show the cached image, etc. You can test this by retrieving a page
with inline GIFS, follow a link to a new page, bring down and server
and use the back bottom to go back to the first page without hitting
reload - the page comes up perfectly even though the server is down.

To force an item not to be cached (by the browser OR any itervening
proxies) theres a couple of headers can be sent.

    Expires: Mon, 23 Feb 1970 15:30:00 GMT

tells any browser or proxy that the file should not be cached after
the specified date, setting it to a date way in the past makes the
file never be cached - unless the time on the server is REALLY off :-).

    Pragma: no-cache

also works, HTTP/1.1 defines other methods, partially implemented
to different degrees by different browsers and servers.

Does Pi3Web Use 'Expires' and 'Pragma' Headers?
Yes, but only where appropriate. If you look at the following
output from Pi3Web in snoop mode, you'll see that the server-side
include handler makes all server-side includes be uncachable by
sending 'Expires' and 'Pragma' headers.

0000:  48 54 54 50 2F 31 2E 30  20 32 30 30 20 4F 4B 0D  HTTP/1.0 200 OK.
0010:  0A 53 65 72 76 65 72 3A  20 50 69 33 57 65 62 2F  .Server: Pi3Web/
0020:  30 2E 39 62 34 0D 0A 44  61 74 65 3A 20 46 72 69  0.9b5..Date: Fri
0030:  2C 20 31 32 20 44 65 63  20 31 39 39 37 20 31 37  , 12 Dec 1997 17
0040:  3A 30 32 3A 33 34 20 47  4D 54 0D 0A 43 6F 6E 74  :02:34 GMT..Cont
0050:  65 6E 74 2D 54 79 70 65  3A 20 74 65 78 74 2F 68  ent-Type: text/h
0060:  74 6D 6C 0D 0A 50 72 61  67 6D 61 3A 20 6E 6F 2D  tml..Pragma: no-
0070:  63 61 63 68 65 0D 0A 45  78 70 69 72 65 73 3A 20  cache..Expires:
0080:  4D 6F 6E 2C 20 32 33 20  46 65 62 20 31 39 37 30  Mon, 23 Feb 1970
0090:  20 31 35 3A 33 30 3A 30  30 20 47 4D 54 0D 0A 4C   15:30:00 GMT..L

How Can I Add Response Headers?
The easiest way to add response headers is to modify the configuration
file (most often called Config.pi3) and use the generic 'Action' handler
to add the following line to the 'HANDLE' phase of the request processing

    Handle Action Pi3Expression="&dbreplace(response,rfc822,Expires,'Mon, 23 Feb 1970 15:30:00 GMT')"

Selectively Adding Headers
The above line added in the appropriate place in Config.pi3 will make
all resources sent by Pi3Web uncachable. This may be desirable in certain
circumstances is generally not. In general network bandwith and download
time will increase by an order of magnitude or two (particularly for
sites with lots of big gif's) - this is not nice.

First of all include this line so that only the general type of resources
requested are effected. In Config.pi3 different resources (document,
CGI,fast CGI) have different sequences of handlers invoked for
different phases. Typically the handlers for 'documents' starts like this

        Name Default
        Class FlexibleHandlerClass

The top level handler 'Default' is place behind those for CGI, Fast CGI,
etc so that only items not handled by those steps is executed.

To add a response header for a particular file look for the line

    Handle SendFile

In the list of handlers for this top-level handler. This tells the
server to handle the request by sending the requested resource as a file.

Now add the following line before this 'SendFile' line

    Handle Condition="&regexp('*/item.gif',$f)" \
        Action Pi3Expression="&dbreplace(response,rfc822,Expires,'Mon, 23 Feb 1970 15:30:00 GMT')"

This line makes adds the 'Expires' header only for those resources
which are documents and whose paths match '*/item.gif'

Won't I Lose Changes Made to Config.pi3?
The windows 95/NT GUI (EnhPi3.exe) does overwrite the file Config.pi3
but not the sections between lines. 

#+++---AD Saved Section, modifications will be retained---+++
#+++---AD Saved section end---+++

Typically the 'top-level' handlers like 'Default', 'Start', 'Errors',
and 'Scripts' are placed between in these sections so that changes to
these like the above line will be retained by EnhPi3.exe

Things to Be Careful Of
You can disable conditional gets (server sends 302 Not Modified instead
of full response) by finding the line
    CheckType ConditionalGet

and commenting it out by inserting a '#'

#   CheckType ConditionalGet

This may simplify debugging, it should not be necessary to solve the problem
and adds some overhead, because browser re-loads will bring over the
full file each time.

Sometimes the in the 'Default' top level handler the first 'Handle' line
    Handle Condition="&and(&not(&dblookup(response,string,ObjectMap)),\
&not(&regexp('internal/*',$c)))" SendFile

This is an optimization to immediatly send files that do not have 
content types matching internal/*. Remove this line or comment it out by
inserting '#' as the first character to avoid shortcircuiting the above
piece of caching cleverness.

> Thanks for your time.
>                         Kirk Gossage
You're welcome, sorry the answer is a little long - its really only
one line you have to add. I needed an excuse for writting how to
fully control caching and HTTP headers.