Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2011-03

Fcl-Web 404 error

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Leonardo M. Ramé

Hi, does anyone knows how to return a correct 404 error from an fcl-web cgi app?.

I'm doing this:

procedure TFPWebModule1.myRequest(Sender: TObject;
  ARequest: TRequest; AResponse: TResponse; var Handled: boolean);
begin
  AResponse.Code := 404;
  AResponse.CodeText := 'Not Found';
  Handled := True;
end;

I use this because my Apache has an .htaccess's "ErrorDocument 404 ..." directive to take actions when 404 errors are found, but this is not working with my CGI. In my case, the contents (empty) sent by the CGI are shown in the client side, while I whould like to show the 404 message generated by Apache.

This is the response I'm getting from my cgi:

* About to connect() to 127.0.0.1 port 80 (#0)
* Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)

Show quoted text 5 lines
GET /cgi-bin/gpacs/seriesImages?AccessionNumber=1112 HTTP/1.1 User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18 Host: 127.0.0.1 Accept: */*

< HTTP/1.1 404 Not Found
< Date: Fri, 11 Mar 2011 13:34:19 GMT
< Server: Apache/2.2.16 (Ubuntu)
< Vary: Accept-Encoding
< Content-Length: 0
< Content-Type: text/html
<
* Connection #0 to host 127.0.0.1 left intact
* Closing connection #0

And this is a correct 404 error mesage:

* About to connect() to 127.0.0.1 port 80 (#0)
* Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)

Show quoted text 5 lines
GET /cgi-bin/gpacs3/seriesImages?AccessionNumber=1112 HTTP/1.1 User-Agent: curl/7.21.0 (x86_64-pc-linux-gnu) libcurl/7.21.0 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18 Host: 127.0.0.1 Accept: */*

< HTTP/1.1 404 Not Found
< Date: Fri, 11 Mar 2011 13:34:46 GMT
< Server: Apache/2.2.16 (Ubuntu)
< Vary: Accept-Encoding
< Content-Length: 300
< Content-Type: text/html; charset=iso-8859-1
<
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /cgi-bin/gpacs3/seriesImages was not found on this server.</p> <hr>
<address>Apache/2.2.16 (Ubuntu) Port 80</address> </body></html>
* Connection #0 to host 127.0.0.1 left intact
* Closing connection #0

Leonardo M. Ramé
http://leonardorame.blogspot.com

Reply by email

Unknown author
to Leonardo M. Ramé
Leonardo M. Ramé wrote 17 lines
Hi, does anyone knows how to return a correct 404 error from an fcl-web cgi app?. I'm doing this: procedure TFPWebModule1.myRequest(Sender: TObject; ARequest: TRequest; AResponse: TResponse; var Handled: boolean); begin AResponse.Code := 404; AResponse.CodeText := 'Not Found'; Handled := True; end; I use this because my Apache has an .htaccess's "ErrorDocument 404 ..." directive to take actions when 404 errors are found, but this is not working with my CGI. In my case, the contents (empty) sent by the CGI are shown in the client side, while I whould like to show the 404 message generated by Apache.
Then you should add it to
   AResponse.Content:='The html';

Michael.

Reply by email

Leonardo M. Ramé
to Unknown author
Show quoted text 35 lines
From: Subject: Re: [fpc-devel] Fcl-Web 404 error To: "FPC developers' list" Date: Friday, March 11, 2011, 11:59 AM On Fri, 11 Mar 2011, Leonardo M. Ramé wrote: > Hi, does anyone knows how to return a correct 404 error from an fcl-web cgi app?. > > I'm doing this: > > procedure TFPWebModule1.myRequest(Sender: TObject; >  ARequest: TRequest; AResponse: TResponse; var Handled: boolean); begin >  AResponse.Code := 404; >  AResponse.CodeText := 'Not Found'; >  Handled := True; > end; > > I use this because my Apache has an .htaccess's "ErrorDocument 404 ..." > directive to take actions when 404 errors are found, but this is not > working with my CGI.  In my case, the contents (empty) sent by the CGI are > shown in the client side, while I whould like to show the 404 message > generated by Apache. Then you should add it to   AResponse.Content:='The html'; Michael.

Thanks Michael, but it's a little more complicated than that.

I need the 404 error to be handled by Apache, not by my app. I need this because I'm trying to let Apache search in a 2nd server when an 404 error is returned by the first server.

Leonardo.

Reply by email

Unknown author
to Leonardo M. Ramé
Leonardo M. Ramé wrote 41 lines
--- On Fri, 3/11/11, wrote: > From: > Subject: Re: [fpc-devel] Fcl-Web 404 error > To: "FPC developers' list" > Date: Friday, March 11, 2011, 11:59 AM > > > On Fri, 11 Mar 2011, Leonardo M. Ramé wrote: > > > Hi, does anyone knows how to return a correct 404 > error from an fcl-web cgi app?. > > > > I'm doing this: > > > > procedure TFPWebModule1.myRequest(Sender: TObject; > >  ARequest: TRequest; AResponse: TResponse; var > Handled: boolean); begin > >  AResponse.Code := 404; > >  AResponse.CodeText := 'Not Found'; > >  Handled := True; > > end; > > > > I use this because my Apache has an .htaccess's > "ErrorDocument 404 ..." > > directive to take actions when 404 errors are found, > but this is not > > working with my CGI.  In my case, the contents > (empty) sent by the CGI are > > shown in the client side, while I whould like to show > the 404 message > > generated by Apache. > > Then you should add it to >   AResponse.Content:='The html'; > > Michael. Thanks Michael, but it's a little more complicated than that. I need the 404 error to be handled by Apache, not by my app. I need this because I'm trying to let Apache search in a 2nd server when an 404 error is returned by the first server.

I don't think the CGI protocol supports that.

You'll have to consult the Apache docs.

Michael.

Reply by email

Leonardo M. Ramé
to Unknown author
Show quoted text 67 lines
From: Subject: Re: [fpc-devel] Fcl-Web 404 error To: "FPC developers' list" Date: Friday, March 11, 2011, 1:00 PM On Fri, 11 Mar 2011, Leonardo M. Ramé wrote: > --- On Fri, 3/11/11, wrote: > >> From: >> Subject: Re: [fpc-devel] Fcl-Web 404 error >> To: "FPC developers' list" >> Date: Friday, March 11, 2011, 11:59 AM >> >> >> On Fri, 11 Mar 2011, Leonardo M. Ramé wrote: >> >> > Hi, does anyone knows how to return a correct 404 >> error from an fcl-web cgi app?. >> > > I'm doing this: >> > > procedure TFPWebModule1.myRequest(Sender: TObject; >> >  ARequest: TRequest; AResponse: TResponse; var >> Handled: boolean); begin >> >  AResponse.Code := 404; >> >  AResponse.CodeText := 'Not Found'; >> >  Handled := True; >> > end; >> > > I use this because my Apache has an .htaccess's >> "ErrorDocument 404 ..." >> > directive to take actions when 404 errors are found, >> but this is not >> > working with my CGI.  In my case, the contents >> (empty) sent by the CGI are >> > shown in the client side, while I whould like to show >> the 404 message >> > generated by Apache. >> >> Then you should add it to >>   AResponse.Content:='The html'; >> >> Michael. > > Thanks Michael, but it's a little more complicated than that. > > I need the 404 error to be handled by Apache, not by my app. I need this because I'm trying to let Apache search in a 2nd server when an 404 error is returned by the first server. I don't think the CGI protocol supports that. You'll have to consult the Apache docs. Michael. -----Inline Attachment Follows-----

Nevermind. The solution was to create a file under /var/wwww/cgi-bin called "failoverserver.cfg", containing only one line, for example "192.168.0.10".

If the cgi doesn't find a requested record, then, do a AResponse.SendRedirect to the server defined in failoverserver.cfg and the same ARequest.URL.

Leonardo.

Reply by email