Run Hypnotoad HTTP server to serve up XHTML page

155 Views Asked by At

I was having a bit of a problem serving up a dot xhtml page using hypnotoad.

the xhtml file starts off like this so perhaps I am not declaring something that would allow hypnotoad to display it as something other than text when I head over to localhost port 8080.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="http://www.w3.org/1999/xhtml; charset=utf-8" />
        <title>
            Index
        </title>
        <link rel="stylesheet" href="book.css" type="text/css" />

When I just open up the page locally without a server in the middle it renders fine in Firefox, but when I created a myapp.pl and stuck it in a sub-folder by the name of public it serves it up but only as text on port 8080.

Any help would be appreciated.

1

There are 1 best solutions below

8
On BEST ANSWER

I'm not too familiar with Perl, certainly not it's headers though you could try the following...

require HTTP::Headers;
$h = HTTP::Headers->new;
$h->header('Content-Type' => 'application/xhtml+xml');

Of course you'll need to check if the client supports XHTML via the client's accept header. Keep in mind that Microsoft thinks IE7 literally supports . which is wildly far from the truth.

I serve XHTML as application/xhtml+xml at my site and use PHP so if you're familiar with that and Perl this may help bridge it a bit easier...

if (isset($_SERVER['HTTP_ACCEPT']))
{
 if (stristr($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml'))
 {
  header('Content-Type: application/xhtml+xml');
 }
 else {header('Content-Type: text/html');}
}

I'm not sure what Perl's equivelant of PHP's include('file.pl'); would be though you want good structure.

_0_header_0 // Your primary header file that starts the includes tree, so-to-speak.

_0_header_1_base // Determines relative and absolute path for BOTH local/live server so the EXACT same code runs on local/live servers.

_0_header_2_sql // Connect to your database to be able to fetch content.

_0_header_3_sessions // Sessions, e.g. signed-in members/admins/etc, should be handled at this point.

_0_header_4_classes // Establish your programming classes here.

_1_functions_date // Site-wide functions such as converting Unix Epoch in to human readable date, other functions, etc. ...

_2_includes_01_xml // At this point you are no longer able to send headers.

_2_includes_02_dtd

_2_includes_03_head

_2_includes_04_title

_2_includes_05_meta_0

_2_includes_05_meta_01_description

_2_includes_05_meta_02_keywords

_2_includes_05_meta_03_language

_2_includes_05_meta_04_robots

_2_includes_05_meta_05_redirect

_2_includes_06_base // Use the base element to set the default base path.

_2_includes_07_css

_2_includes_08_js // Never put JavaScript in the body element or you will have a horrid mess.

_2_includes_09_body

...

I'm also not familiar with Hypnotoad HTTP server (though I get the Futurama reference). Ideally you want to do what is akin to Apache rewrites and have the content served by main handlers. In essence a file in another directory will serve the content sometimes...for which there is no actual directory, at least for custom pages. When you have established modules (e.g. blog, email, forums) you'd simply move the main handler files to that.

It's a general approach that I could spend hours getting in to though it's intended more of as a direction. I was doing single files with hoards of includes and was uncomfortable with things like databases for reasons such as not being able to quickly copy a folder and say the site was backed up. As long as you have some good backup system in place build such an approach as a new version and attempt to break things down to smaller versions. When you do have a fundamentally different approach code wise it's okay to have a version that might be months to a year or two to release. Just keep refining it over and over and over and push yourself for high standards (e.g. XHTML as application/xhtml+xml with Firefox (since other browsers won't give hide the page and give you the error outright). This has all been my general approach and now I have my own web platform that can run circles around all the other platforms I've seen for doing the things I need, want and will eventually to do.