title: How to send a custom http status code with mod_perl
body: <p>I have written a <strong>CGI</strong> program and I send a status error with the HTTP header to the client. but when I tried to use <strong>mod_perl</strong> it only responds with 200 ok status. How can I send a custom status code?</p>
  
  <p>here is the code when I want to respond with the custom status error :</p>
  
  <pre><code>my $cgi      = new CGI;
  print $cgi-&gt;header(-type=&gt;"text/html", -charset=&gt;'utf-8', -status=&gt;599);
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT</strong> : <br>
  here is the code :</p>
  
  <pre><code>#!/usr/bin/perl -w
  use strict;
  use warnings;
  use CGI;
  use SessionManagement;
  
  
  my $cgi      = new CGI;
  my $method = $cgi-&gt;param("method");
  
  my $sessionManagement = new SessionManagement(cgi=&gt;$cgi);
  if($sessionManagement){
  
    if (defined($method)) {
      if($method eq "authentication") {
          loginMethod($cgi,$sessionManagement);
      } elsif ($method eq "someMethod"){
          someMethod($cgi);
      } else{
          print $cgi-&gt;header(-type=&gt;"text/xml", -charset=&gt;'utf-8');
          print "&lt;html&gt;method does not exist&lt;/html&gt;";
      }
  
    } else {
        print $cgi-&gt;header(-type=&gt;"text/html", -charset=&gt;'utf-8' , -status=&gt;599);
        print "&lt;html&gt;blah blah&lt;/html&gt;";
    }
  
  }else{
    print $cgi-&gt;header(-type=&gt;"text/html", -charset=&gt;'utf-8' , -status=&gt;599);
    print "&lt;html&gt;blah blah&lt;/html&gt;";
  }
  </code></pre>
  
  <h2>-------------------------------------------</h2>
  
  <p><strong>EDIT 2</strong><br></p>
  
  <p>giving some more information:
  when I use <code>curl -v 192.168.1.212/mymodperl/test.pl</code> command in shell.<br>
  here is the response : </p>
  
  <pre><code>* About to connect() to 192.168.1.212 port 80 (#0)
  *   Trying 192.168.1.212... connected
  * Connected to 192.168.1.212 (192.168.1.212) port 80 (#0)
  &gt; GET /mymodperl/test.pl HTTP/1.1
  &gt; User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
  &gt; Host: 192.168.1.212
  &gt; Accept: */*
  &gt; 
  &lt; HTTP/1.1 200 OK
  &lt; Date: Sat, 25 Nov 2017 11:04:18 GMT
  &lt; Server: Apache/2.2.15 (Red Hat)
  &lt; Connection: close
  &lt; Transfer-Encoding: chunked
  &lt; Content-Type: text/html; charset=ISO-8859-1
  &lt; 
  &lt;html&gt;hi&lt;/html&gt;&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt;
  &lt;html&gt;&lt;head&gt;
  &lt;title&gt;500 Internal Server Error&lt;/title&gt;
  &lt;/head&gt;&lt;body&gt;
  &lt;h1&gt;Internal Server Error&lt;/h1&gt;
  &lt;p&gt;The server encountered an internal error or
  misconfiguration and was unable to complete
  your request.&lt;/p&gt;
  &lt;p&gt;Please contact the server administrator,
   root@localhost and inform them of the time the error occurred,
  and anything you might have done that may have
  caused the error.&lt;/p&gt;
  &lt;p&gt;More information about this error may be available
  in the server error log.&lt;/p&gt;
  &lt;hr&gt;
  &lt;address&gt;Apache/2.2.15 (Red Hat) Server at 192.168.1.212 Port 80&lt;/address&gt;
  &lt;/body&gt;&lt;/html&gt;
  * Closing connection #0
  </code></pre>