logo

Making Use of Oddities of the Domino Server

We should all know of the following three uses of the Print statement in web agents by now:

  1. You can perform a HTTP 302 redirect (effectively replacing the $$Return field) with a line of code like this:

    Print  "Location: /"+web.path+"/thanks?ReadForm"
  2. You can change the content type of the page (allowing you to create the whole HTML yourself) by using the following print statement before any others in the code:

    Print  "Content-Type: text/html"
  3. Also that you can set cookies using a similar piece of code.

    Print "Set-Cookie: style=red; expires=Friday, 11-Jan-2030 01:10:00 GMT; path=/;"

What I never knew — which now seems a logical progression of the above — is that you can use the Print statement to set any header you like, whether it's a valid header or not. For example, the following line works:

Print "foo: bar"

As do other valid ones, which let you over-ride values, like so:

Print "Server: jakester v0.999999999"

Inspecting the headers of the returned page you see this:

Whether this is useful or not it's definitely worth knowing about. Why? Well imagine you've written some code like this, which is pretty much what I'd done when I discovered this behaviour:

Sub Initialize
 On Error Goto ErrorProcess
        
 'Error producing code goes here
        
ExitProcess:
 Exit Sub
        
ErrorProcess:
 Print "Error: " + Error
 Resume ExitProcess
End Sub

Expecting an error message to help me debug the code I was working on, imagine my confusion when I saw nothing but a blank page — suggesting there was in fact no error when I knew there was. If I'd checked the headers to this blank page I would have seen the error in there.

It seems that using the Print statement to send a word with no white-space, followed by a colon, followed by a space and then a string will send the browser a header param/value pair (as long as no other Print statements were used before it). No matter whether the word you use before the colon is a valid header name or not. Maybe this is something all web servers do? I don't know. Either way, it's something you ought to know about!

Armed with this knowledge you now know not to expect to see it actually appear on the page. This could in fact be beneficial! You can now debug without the user knowing by sending "invisible" data back the browser and then using a sniffer like HTTPWatch to see this "hidden" information.

Comments

    • avatar
    • Kerr
    • Fri 5 Oct 2007 07:05 AM

    I hadn't thought of doing a redirect by changing the location header before, I normally just use the square bracket method, but I have been tripped up regularly by the old problem of spitting out some debugging code that had a colon and was interpreted as a header.

    A related not to this (that I'm sure you know Jake) is that if you set *any* header this way, you need to supply the complete content of the page, Domino will *not* put in the html and body tags that it would do otherwise.

    Another good tip to remember is that you can set the charset in the Content-Type header, but be careful, domino can be *very* picky about recognising it. use:

    Content-type: text/xml; charset=UTF-8

  1. I'll be darned. I know now I've encountered this issue in the past (the debugging error: statement) and hadn't realized what was happening. Thanks!

    • avatar
    • Michael
    • Fri 5 Oct 2007 10:14 AM

    Careful. I heard that jakester v0.999999999 servers have issues serving up RSS feeds. ;)

  2. Unfortunately, you might be able to set any, but not every header (hope this little play of words is even correct): You cannot set the Status directly. For most parts, this is good and well, because Domino should know what Status to return.

    The downside is, that Domino does not allow us to create a 301 permanent redirect, neither through programming, nor through configuration. For this special case, I wish you could override the HTTP Status.

  3. Cool. Didn't thought of using it this way especially for error message into the header.

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Fri 5 Oct 2007

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content