Recent

Author Topic: pathing issue? fpweb / HTTP Server Application  (Read 18732 times)

IPguy

  • Sr. Member
  • ****
  • Posts: 385
pathing issue? fpweb / HTTP Server Application
« on: June 19, 2012, 03:42:01 am »
I'm able to display the background when I point my browser to the file containing the below html code, but when I set the below file as my default file for my HTTP Server App, the background image (mos.gif) is not displayed.

Any suggestions?
Laz-1.1-36568-2.6.1, win32-Vista.

Code: [Select]
<!DOCTYPE HTML public "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
  <BODY BACKGROUND="mos.gif" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#000080" VLINK="#800080" ALINK="#FF0000">
    <h1 > Main Page </h1>
</HTML>     

Code: [Select]
procedure TMain.DefaultRequest(Sender: TObject; ARequest: TRequest;
  AResponse: TResponse; var Handled: Boolean);
var
  sFormData : string;
  iLoc : Integer;
  sName : String;
  sData : String;
  FormData : TStringList;
begin
  AResponse.ContentType := 'text/html;charset=utf-8';
  AResponse.Contents.LoadFromFile('test.html');
 

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: pathing issue? fpweb / HTTP Server Application
« Reply #1 on: June 19, 2012, 08:32:18 am »
Open "View source" in your browser, then click on mos.gif link. What do you get?

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: pathing issue? fpweb / HTTP Server Application
« Reply #2 on: June 20, 2012, 01:50:49 am »
When I open the source (fyi: using firefox) and click on mos.gif, it is not displayed in my browser.  When I click on mos.gif, the title of the FF browser turns to: Source of: http://localhost:8081/mos.gif.

I have the text.html and mos.gif files in the same directory as my httpserver.exe application.

When I open test.html directly, the background is displayed correctly.  When I open the source from that web page and click on mos.gif, it is displayed in my browser.

At this point I suspect there is a pathing problem, but given that the gif file is in the same directory as the html file, I'm having troubles accepting that conclusion.

Should I be setting the web page root/home directory somehow when the app starts up? 

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: pathing issue? fpweb / HTTP Server Application
« Reply #3 on: June 20, 2012, 11:29:37 am »
Quote
When I open the source (fyi: using firefox) and click on mos.gif, it is not displayed in my browser.  When I click on mos.gif, the title of the FF browser turns to: Source of: http://localhost:8081/mos.gif
OK, using your debugging tool (probably firebug), find mos.gif request/response. What's the response?
Quote
I have the text.html and mos.gif files in the same directory as my httpserver.exe application.

At this point I suspect there is a pathing problem, but given that the gif file is in the same directory as the html file, I'm having troubles accepting that conclusion.
HTTP server application doesn't automatically act as static file server. i.e. even if you have a file in the same directory as your http server executable, you can't assume that it would serve the file as is. e.g. if you request /mos.gif and the file is in the same directory as the executable, it won't work. You need to register the location using RegisterFileLocation function or implement the action handler yourself.

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: pathing issue? fpweb / HTTP Server Application
« Reply #4 on: June 21, 2012, 04:32:44 am »
I added
  - fpwebfile to my Uses statement and
  -   ImageDir := GetCurrentDir + '\images'; 
           (also tested with just:  := GetCurrentDir; - same error)
      RegisterFileLocation('mos.gif',ImageDir);   
in the DefaultRequest() procedure.  The above lines run when the initial page is loaded.

I verified that the AppDirectory path is correct and the image file exists in ImageDir.

Now I get the exception class 'EFPWebError' with the message
  Could not determine HTTP module for request ""

Which appears to be the resource string SErrNoModuleForRequest from fpweb/base/custweb.pp.

The application encountered the following error:

    Error: Could not determine HTTP module for request ""
    Stack trace:
    $00437593
    $00437C01
    $0043A6FE
    $0043A26C
    $0043A60D
    $0043895A
    $0043A6B6
    $00402C9B main, line 12 of httpprojectPAR.lpr

Other thoughts?

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: pathing issue? fpweb / HTTP Server Application
« Reply #5 on: June 21, 2012, 05:02:57 am »
Attached is the program I'm attempting to get running.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: pathing issue? fpweb / HTTP Server Application
« Reply #6 on: June 21, 2012, 10:57:30 am »
Quote
RegisterFileLocation('mos.gif',ImageDir);
This is incorrect use. The first argument is the virtual path/directory, not a filename. So if you have:
Code: [Select]
RegisterFileLocation('img','/home/myfpweb/images')and you have mos.gif in /home/myfpweb/images, you can refer to mos.gif using this uri:
Quote
/img/mos.gif

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: pathing issue? fpweb / HTTP Server Application
« Reply #7 on: June 22, 2012, 02:57:58 am »
Made the change, but still having the same error.

Corrected the RegisterFileLocation statement.
Code: [Select]
  ImageDir  := GetCurrentDir + PathDelim + 'images';
  RegisterFileLocation('img',ImageDir); 

I have verified that the ImageDir path is correct and that mos.gif exists in that directory.
The path is an absolute path ('C:\Programming\PAR\images').

Below is the html source when the program runs.  As you can see, I added an image statement to see if I could get the image to show up that way.  No luck.

Code: [Select]
<BODY BACKGROUND="/img/mos.gif" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#000080" VLINK="#800080" ALINK="#FF0000">
    <h1> Main Page </h1>
    <img src="/img/mos.gif" alt="this is some image"/>

I'm going to start over again with a new / clean program and see if I continue to have the same issues.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: pathing issue? fpweb / HTTP Server Application
« Reply #8 on: June 22, 2012, 08:50:47 am »
I just opened your attachment and now I see you put RegisterFileLocation in the wrong place. It should NOT be put in a request, but prior to Application.Run. I still haven't tried your code though (my office has a weird internet usage rules), I'll try whenever I get access to my Lazarus.

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: pathing issue? fpweb / HTTP Server Application
« Reply #9 on: June 22, 2012, 01:35:58 pm »
re: RegisterFileLocation - I had played with putting that before Application.run and I was still getting errors.  (I do not remember the error message at the moment.)  I'll move RegisterFileLocation out of the request tonight.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: pathing issue? fpweb / HTTP Server Application
« Reply #10 on: June 22, 2012, 02:07:18 pm »
Try the attached project, you also miss the mime.types file (included in attached project), which is used to determine what kind of mimetype the server should send (could cause the browser to download instead of display the image)

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: pathing issue? fpweb / HTTP Server Application
« Reply #11 on: June 23, 2012, 03:21:04 am »
This appears to be worse.

I get the following error immediately after pointing my browser to the app, both when
when running within the IDE and when I start the app up outside of the IDE.  Also with multiple browsers.

Code: [Select]
The application encountered the following error:
Error: Could not determine HTTP module for request ""
Stack trace:
$00437DA3
$00438411
$0043AF0E
$0043AA7C
$0043AE1D
$0043916A
$0043AEC6
$00402CF8 main, line 15 of httpprojectPAR.lpr


I also added the line:
Code: [Select]
  MimeTypes.LoadFromFile('mime.types');   in the .lpr file and that did not make a difference.

Leledumbo - What OS did you use to test this? What Laz version?
I'm using: Laz-1.1-36568-2.6.1, win32-Vista.

« Last Edit: June 23, 2012, 03:22:58 am by IPguy »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: pathing issue? fpweb / HTTP Server Application
« Reply #12 on: June 23, 2012, 05:55:15 am »
Quote
I get the following error immediately after pointing my browser to the app, both when
when running within the IDE and when I start the app up outside of the IDE.  Also with multiple browsers.
What's your URL? You didn't set any default module/action so http://localhost:8081 would give you that error. Use http://localhost:8081/main/default.
Quote
also added the line:
  MimeTypes.LoadFromFile('mime.types');   
in the .lpr file and that did not make a difference.
That's not required, fpwebfile would automatically load it.
Quote
Leledumbo - What OS did you use to test this? What Laz version?
Kubuntu 12.04 & Windows XP SP3, all 32-bit
FPC 2.7.1 r21512
Laz 1.1 r37563M

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: pathing issue? fpweb / HTTP Server Application
« Reply #13 on: June 24, 2012, 01:59:08 am »
localhost:8081 had been presenting the web page as expected (except for the image issue).

I just upgrade Laz to 1.1-37738 (still 2.6.1).  No change in behavior.  No image is display.

After recompiling the revised program you provided, the image still does not show. 

Any other thoughts?  I could share this with the mailing list?
I still suspect my programming is the issue.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: pathing issue? fpweb / HTTP Server Application
« Reply #14 on: June 24, 2012, 08:24:35 am »
I give up. It works perfectly fine in my computer, both of my OS. Last thing you might want to do: try requesting the image again directly (http://localhost:8081/img/mos.gif) and see what your browser get. If it downloads the image, then mime.types doesn't get loaded. If it can display the image, that's weird. Otherwise, there's something wrong and I have no clue what it is.

 

TinyPortal © 2005-2018