title: Perl CGI with HTTP Status Codes in RESTful api
body: <p>I have the following validation in a CGI script that will check for the GET method and return a 405 HTTP status code if the GET method is not used. Unfortunately it is still returning a 200 Status OK when using POST or PUT.</p>
  
  <pre><code>my ($buffer);
  # Read in text
  $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;
  if ($ENV{'REQUEST_METHOD'} eq "GET")
    {
  $buffer = $ENV{'QUERY_STRING'};
    }
  else
   {
    print $cgi-&gt;header(
      -type=&gt;'text/plain',
      -status=&gt; '405 Method Not Allowed'
    );
   }
  </code></pre>
  
  <p>but when i use LWP at client and print status_code it still gives 200 OK and when i print content it is printing the Status: 405 </p>
  
  <p>code i am using at Client:</p>
  
  <pre><code>use LWP;
  use HTTP:Request::Common;
  
  my $ua = LWP::UserAgent-&gt;new;
  my $req =PUT("/path/to/request");
  
  my $result = $ua-&gt;request($req);
  
  if($result-&gt;is_success) {
    print "HTTP RESPONSE CODE:" , $result-&gt;status_line;
    print $result-&gt;decoded_content;
  }
  </code></pre>
  
  <p>from above code it prints the following information on success</p>
  
  <pre><code> HTTP RESPONSE CODE: 200 OK
   Status: 405 Method Not Allowed
   "some text regarding why method not allowed"
   Requested Method Not allowed
  </code></pre>
  
  <p>How can i match the status_line to the value coming from CGI header?</p>