Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Blog demo redirect problem, UrlFor(THome) returns empty string #2

Closed
leledumbo opened this issue Dec 29, 2012 · 23 comments
Closed

Blog demo redirect problem, UrlFor(THome) returns empty string #2

leledumbo opened this issue Dec 29, 2012 · 23 comments
Labels

Comments

@leledumbo
Copy link
Collaborator

I convert the blog demo into fastcgi project, replacing hardcoded link in the form action of newpost.html template into /post/. The problem is after I press the post button, I got empty page. The data does get in to the database though. Quick investigation shows that this piece of code:

procedure TPost.Post;
begin
  Table.Insert(Fields).Apply;
  Redirect(UrlFor(THome), BROOK_HTTP_STATUS_CODE_FOUND);
end;

cause the problem because UrlFor(THome) returns empty string.

@silvioprog
Copy link
Owner

UrlFor depends of TRequest.PathInfo, and it must return the current PATH_INFO. Can you execute the test below?:

procedure TMyAction.Request(ARequest: TRequest; AResponse: TResponse);
begin
  Write(ARequest.PathInfo);
end;

initialization
  TMyAction.Register('/a/b'); // call http://localhost/cgi-bin/cgi1/a/b

If you not got /a/b on the browser, the problem is in FCL-Web for FastCGI.

@leledumbo
Copy link
Collaborator Author

Yes, I do get /a/b on the browser. THome is registered with '*' pattern (and is set as default), would that be the problem? Since the pathinfo will be / (tested and proven), even if I give a non-existent path (because it's set as default).

@silvioprog
Copy link
Owner

The 'problem' is in the FCL-Web for FastCGI. Using this code below:

procedure TMyAction.Request(ARequest: TRequest; AResponse: TResponse);
begin
  Write(GetEnvironmentVariable('SCRIPT_NAME'));
end;

compiled for CGI and calling http://localhost/cgi-bin/cgi1, the result is: /cgi-bin/cgi1. But, compiled for FastCGI and calling http://localhost/cgi-bin/cgi1, the result is empty.

So the problem isnt in Brook. :/ Open a entry in Free Pascal bugtracker?

@leledumbo
Copy link
Collaborator Author

OK, but actually I don't know what's wrong with that. I mean, should SCRIPT_NAME be equal for both?

@silvioprog
Copy link
Owner

I don't think so. :(
Please see: http://www.fastcgi.com/devkit/doc/fcgi-spec.html

@leledumbo
Copy link
Collaborator Author

I'm still not sure what to report to FPC mantis (my brain has a problem reading specs :p), could you do that instead?

@silvioprog
Copy link
Owner

I do not feel safe to report this due to limitation of my English. XD
So, what will we do hehehe?

It would be interesting to test a small FastCGI script in another programming language (Perl?) and check if it returns this variable.

@silvioprog
Copy link
Owner

Oh god, Perl FCGI return the SCRIPT_NAME, please see:

http://brookframework.org/test.fbf

Response:

FastCGI Demo Page (perl)

This is coming from a FastCGI server. 
Running on brookframework.org - /test.fbf to XXX
This is connection number 1

The code of this test:

#!/usr/bin/perl -wT

use strict;
use vars qw( $cnt );
use FCGI;

local $cnt = 0;

while ( FCGI::accept >= 0 ) {
  print "Content-type: text/html\r\n\r\n";
  print "<head>\n<title>FastCGI Demo Page (perl)</title>\n</head>\n";
  print  "<h1>FastCGI Demo Page (perl)</h1>\n";
  print "This is coming from a FastCGI server.\n<BR>\n";
  print "Running on <EM>$ENV{SERVER_NAME}-$ENV{SCRIPT_NAME}</EM> to <EM>$ENV{REMOTE_HOST}</EM>\n<BR>\n";
   $cnt++;
  print "This is connection number $cnt\n";
}

@leledumbo
Copy link
Collaborator Author

Perhaps this report is enough: SCRIPT_NAME in a FastCGI application returns empty string. What do you think?

@silvioprog
Copy link
Owner

Perfect! Send me the issue link after you submit.

@leledumbo
Copy link
Collaborator Author

Could you try this first on Apache? In my Nginx, I don't even find SCRIPT_NAME at all...

@silvioprog
Copy link
Owner

Yes:

http://brookframework.org/project1.fbf

But if I'm not mistaken, the FastCGI not read the informations directly from the environment variables.

But in my mind there is way to solve this easily: BrookSettings.RootUrl. By default this property is filled by SCRIPT_NAME value. It seems a good idea? :)

@silvioprog
Copy link
Owner

This will be implemented as soon as possible. :)

ps. Oh, sorry friend, I accidentally deleted your comment, but I pasted it below (copied from my Gmail). x(

2013/1/7 Mario Ray Mahardhika says:

But if I'm not mistaken, the FastCGI not read the informations directly
from the environment variables.

I'll ask Michael to ensure.

But in my mind there is way to solve this easily: BrookSettings.RootUrl.
By default this property is filled by SCRIPT_NAME value. It seems a good
idea? :)

Filled automatically on each request? Seems good.

silvioprog added a commit that referenced this issue Jan 17, 2013
@silvioprog
Copy link
Owner

Hello Mario,

Done (685a03e).

Can you test it please?

Thanks! :)

@silvioprog
Copy link
Owner

I implemented it in "working" branch (http://imagebin.org/243220).

@leledumbo
Copy link
Collaborator Author

Tested and works, the documentation needs to be expanded though. It should say that RootURL must be filled in order for Redirect (or UrlFor) to work

@silvioprog
Copy link
Owner

Guy, more adjusts: cb3fcb4

Can you help me to add more details on documentation? My translator is still on vacation hehehe...

@silvioprog
Copy link
Owner

Nice?:

(...)
    { Set the default root URL. This is used by methods such as
      @code(TBrookAction.UrlFor), @code(TBrookActionHelper.LinkTo),
      @code(TBrookActionHelper.ButtonTo) etc. By default, Brook assumes
      @code(SCRIPT_NAME) as root URL. }
    RootUrl: string;
(...)

@leledumbo
Copy link
Collaborator Author

By default, Brook assumes @code(SCRIPT_NAME) as root URL

Just to be sure, which code fills this field when it's empty?

@silvioprog
Copy link
Owner

The new "pasdoc comment" for documentation is good?

@leledumbo
Copy link
Collaborator Author

OK, then it's good.

silvioprog added a commit that referenced this issue Jan 20, 2013
@silvioprog
Copy link
Owner

Done (538afb4). Thank you friend!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants