pathing issue? fpweb / HTTP Server Application lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- IPguy · 2012-06-19 01:42 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]      

Main Page

      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 · 2012-06-19 06:32 Open "View source" in your browser, then click on mos.gif link. What do you get? ---------------------------------------------------------------------- IPguy · 2012-06-19 23:50 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 · 2012-06-20 09:29 QuoteWhen 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.gifOK, using your debugging tool (probably firebug), find mos.gif request/response. What's the response? QuoteI 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 · 2012-06-21 02:32 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 · 2012-06-21 03:02 Attached is the program I'm attempting to get running. ---------------------------------------------------------------------- Leledumbo · 2012-06-21 08:57 QuoteRegisterFileLocation('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 · 2012-06-22 00:57 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]    

Main Page

    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 · 2012-06-22 06:50 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 · 2012-06-22 11:35 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 · 2012-06-22 12:07 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 · 2012-06-23 01:21 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. ---------------------------------------------------------------------- Leledumbo · 2012-06-23 03:55 QuoteI 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. QuoteLeledumbo - 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 · 2012-06-23 23:59 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 · 2012-06-24 06:24 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. ---------------------------------------------------------------------- BigChimp · 2012-06-24 09:53 Compiled it using x86 Laz 1.1 (SVN today), FPC 2.6.1 (SVN today), Windows Vista x64 This URL Code: [Select]http://localhost:8081/main/default gives this page source: Code: [Select]    

Main Page

    this is some image ... but no mos.gif is shown... I get the alt text. Direct image link: Code: [Select]http://localhost:8081/img/mos.gif gives an error, no image Is this how I should test it? ---------------------------------------------------------------------- IPguy · 2012-06-24 12:12 Leledumbo - requesting the image directly (via:http://localhost:8081/img/mos.gif) shows a blank page.  When I view the source of that page, it is also blank. I did add a .jpg image on my web page to see this was an issue with .gif's.  I was not able to see either image. BigChimp - that is the result I get as well.  I see the text but not the image, although I'm not getting an error when I view the image via http://localhost:8081/img/mos.gif with firefox.  When using IE8, I do get the message: webpage cannot be found. Yes I believe this is how we should be testing it. But Leledumbo does see the image.  I'm confused. BigChimp - what setup are you using? IPGuy - Laz 1.1-37738-2.6.1, win32-Vista Leledumbo -     Kubuntu 12.04 & Windows XP SP3, all 32-bit     FPC 2.7.1 r21512     Laz 1.1 r37563M ---------------------------------------------------------------------- BigChimp · 2012-06-24 14:20 Quote from: IPguyBigChimp - what setup are you using? Quote from: BigChimp on June 24, 2012, 11:53:35 amx86 Laz 1.1 (SVN today), FPC 2.6.1 (SVN today), Windows Vista x64 Quote from: IPGuyvia http://localhost:8081/img/mos.gif with firefox.  When using IE8, I do get the message: webpage cannot be found. Yep, that's what I'm talking about - tested in IE. With either IE or Firefox, I don't get the image. ---------------------------------------------------------------------- Leledumbo · 2012-06-24 14:23 My bad... looks like I forgot one line in the .lpr: Quote... ImageDir  := GetCurrentDir + DirectorySeparator; MimeTypesFile := 'mime.types'; RegisterFileLocation('img',ImageDir); ... Please add the bold line. Somehow Chrome (sorry, I didn't say it earlier. I quit using FF and IE since I found Chrome) is able to detect the real content type despite it's sent as application/octet- stream. ---------------------------------------------------------------------- IPguy · 2012-06-24 14:49 I've been using FF, IE and Chrome.  No luck with any of them. Leledumbo, I added the mime line to the .lpr, but that did not make any difference.  I still do not see an image.  No difference if I run the app inside the IDE or outside the IE. One difference between our setups is that Leledumbo is using 2.7.1 and BigChimp and I are using 2.6.1.  If there are no other thoughts, I'll open a bug report on this. Thanks for your help. ---------------------------------------------------------------------- Leledumbo · 2012-06-24 16:29 QuoteOne difference between our setups is that Leledumbo is using 2.7.1 and BigChimp and I are using 2.6.1That could be the problem or not. Could you try diff-ing the 2.7.1 and 2.6.1 source of fcl-web? ---------------------------------------------------------------------- IPguy · 2012-06-24 19:33 comparing 2.6.1, dated 2012/6/23 & 2.7.1-v21686: httpdefs.pp differs    adding free content stream code custweb.pp differs    added new property - defaultModuleName & associated code I'll attempt switching over to 2.7.1 and see if that makes a difference. ---------------------------------------------------------------------- IPguy · 2012-07-05 23:16 Finally have fpc 2.7.1 installed. No change - I still do not see the images. I'm going to open a bug report. Using laz-1.1-37884, fpc 2.7.1 21798, win32-Vista....