#!/afs/athena/contrib/perl/p

require '/afs/sipb/user/mkgray/bin/http.pl';
&http'httpd();

sub user_input {
	local($n, $text)=@_;
	($request, @headers) = split("\n", $text);
	($method, $file, $proto) = split(" ", $request);
	if(-e $file){
	    print("Returning file\n");
	    $fcontents = `cat $file`;
	    if($file =~ /html/){
		&okheader($n, "text/html");
	    }
	    else{
		&okheader($n, "text/plain");
	    }
	    &http'tell($fcontents, $n);
	    print("Done giving file\n");
	}
	else{
		&http'tell("That file ($file)($x) does not exist\n", $n);
	}
}

sub okheader {
    local($n, $type) = @_;

    &http'tell("HTTP/1.0 200 OK\n", $n);
    &http'tell("Content-type: ".$type."\n", $n);
    &http'tell("Content-length: ".length($fcontents)."\n", $n);
    &http'tell("\n", $n);
}
