URL Substitution

HTML files can include BASIC code and thus be dynamic. Actual HTML contents received by the browser may partially be generated by your Tibbo BASIC/C application. Files of other types — plain text, graphics, etc. — cannot include executable code and are static in nature. These files are sent to the browser "as is."

So, what if you need to generate a non-HTTP file dynamically? For example, what if you want to generate a BMP file? The answer is in using "URL substitution." The sock.urlsubstitutes property allows you to do this.

The property stores a list of comma-separated file names (with extensions). When the web server receives a request for a non-HTML file from the browser (say, "pix.bmp"), it first tries to find this file among the HTML and resource files of your project. Failing this, the web server looks at defined substitutions. If the requested file is not on the list, the web server returns the "404" error.

If the file is on the list of defined substitutions, the browser looks for the file with the same name, but ".html" extension ("pix.html"). If there is no such file, the "404" error is, again, the answer. If this HTML file exists, the server outputs this file, but makes it look like it was a file of the original type (server processes "pix.html," brower gets "pix.bmp").

Since the actual behind-the-scenes output is done for the HTML file, you can put your own code into that file and generate content dynamically. The following example shows how we generate the file "pix.bmp" dynamically. For this to work, we need to set sock.urlsubstitutes = "pix.bmp" somewhere in the initialization section of the project. Here is what we have in the "pix.html" file:

   Dim x As Byte
   Dim s As String
   Loop While Len(s)=x

In this example, we simply read and output the contents of another BMP file ("source.bmp"). No value is added — we could just access that graphical file directly. Your code, however, is free to do anything and substitution opens up the way to create your picture on the fly or dynamically generate the content for other "static" files.