Recent

Author Topic: TFPHTTPServer in a thread  (Read 14326 times)

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: TFPHTTPServer in a thread
« Reply #30 on: July 30, 2019, 07:38:44 pm »
No. I got a compile error in trunk, removed the unit and tested basic functionality. The simpleserver works and serves what you ask. I did not test anything else.
« Last Edit: July 30, 2019, 07:40:53 pm by Thaddy »
Specialize a type, not a var.

julkas

  • Guest
Re: TFPHTTPServer in a thread
« Reply #31 on: July 30, 2019, 08:23:31 pm »
Because wmecho is not needed and makes it fail to compile because it can not be found.
After that, try to start the server and ask for a page (must exist) like index.html.
Works.
I don't know if wmecho is needed. I have found this unit. After successfully compilation and run open chrom and make request, app fails with exception.
Continue tomorrow. I think code is broken or has bug.
This example must working out of the box.

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: TFPHTTPServer in a thread
« Reply #32 on: July 30, 2019, 09:19:05 pm »
No. I got a compile error in trunk, removed the unit and tested basic functionality. The simpleserver works and serves what you ask. I did not test anything else.
Yes, neat. It works with one index.htm  :(

But when serving a complete website (with css), even the simpleserver example craps out.

Try it with the website provided (and attached), which contains .css files.

For me, there is really something fishy going on in function TFPHTTPConnection.ReadString() and shows a real potential problem in core FPC. Like we had a few weeks ago with the wrong reference counting in the pure calculator app (which was also confirmed a real problem).

Can anybody test simplehttpserver.lpi (in fpc\packages\fcl-web\examples\httpserver) with attached website and confirm the problem?

euMesmo

  • New Member
  • *
  • Posts: 12
Re: TFPHTTPServer in a thread
« Reply #33 on: July 31, 2019, 01:16:47 am »
Hi rvk.
Yes, I tested the simplehttpserver on W7 with firefox and chrome and it works after commenting the line "if FCount>=5 then Active:=false" as it prevented the complete loading of all files.

As anecdote, the avast antivirus considers simplehttpserver a "threat".

However there is something "strange", when closing the browser the exception "EHTTPServer" appears with the message: "Missing HTTP protocol version in request".  If we click on the continue button of the exception message the server is still working.
I have placed in the code the line "Arequest.ProtocolVersion:='HTTP/1.1';" but it doesn't seem to solve it.

I have tried a bigger web (several html+css+js), the only problem is that when, from the web, a new html file is requested, the exception reappears. Clicking on the continue button of the exception message continues to work and loads the html, even html inserted into iframes.

julkas

  • Guest
Re: TFPHTTPServer in a thread
« Reply #34 on: July 31, 2019, 08:11:53 am »
Hi rvk.
Yes, I tested the simplehttpserver on W7 with firefox and chrome and it works after commenting the line "if FCount>=5 then Active:=false" as it prevented the complete loading of all files.

As anecdote, the avast antivirus considers simplehttpserver a "threat".

However there is something "strange", when closing the browser the exception "EHTTPServer" appears with the message: "Missing HTTP protocol version in request".  If we click on the continue button of the exception message the server is still working.
I have placed in the code the line "Arequest.ProtocolVersion:='HTTP/1.1';" but it doesn't seem to solve it.

I have tried a bigger web (several html+css+js), the only problem is that when, from the web, a new html file is requested, the exception reappears. Clicking on the continue button of the exception message continues to work and loads the html, even html inserted into iframes.
Install Apache or nginx ... and you have working solution.
I have same exception.
« Last Edit: July 31, 2019, 08:14:21 am by julkas »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: TFPHTTPServer in a thread
« Reply #35 on: August 02, 2019, 08:13:28 am »
However there is something "strange", when closing the browser the exception "EHTTPServer" appears with the message: "Missing HTTP protocol version in request".  If we click on the continue button of the exception message the server is still working.
Intentional, the exception actually happens internally and handled gracefully without ever leaking out of the webserver unit code. But GDB will still catch it unless you whitelist it.

euMesmo

  • New Member
  • *
  • Posts: 12
Re: TFPHTTPServer in a thread
« Reply #36 on: August 04, 2019, 01:24:41 am »
Install Apache or nginx ... and you have working solution.
I have same exception.

Yeah, it's the solution I'm using for my application. But if I could insert an http server into my application, users would no longer have to "add" anything. If that server also supported php it would be perfect.

euMesmo

  • New Member
  • *
  • Posts: 12
Re: TFPHTTPServer in a thread
« Reply #37 on: August 04, 2019, 01:27:31 am »
Intentional, the exception actually happens internally and handled gracefully without ever leaking out of the webserver unit code. But GDB will still catch it unless you whitelist it.
Indeed, once compiled there is no problem, maybe a little slow but everything seems to work fine.

julkas

  • Guest
Re: TFPHTTPServer in a thread
« Reply #38 on: August 04, 2019, 12:27:10 pm »
Install Apache or nginx ... and you have working solution.
I have same exception.

Yeah, it's the solution I'm using for my application. But if I could insert an http server into my application, users would no longer have to "add" anything. If that server also supported php it would be perfect.
Check - https://wiki.freepascal.org/Brook_for_Free_Pascal

euMesmo

  • New Member
  • *
  • Posts: 12
Re: TFPHTTPServer in a thread
« Reply #39 on: August 06, 2019, 01:44:37 pm »
Hi julkas. THanks for the feedback. I'm gonna try it.

julkas

  • Guest
Re: TFPHTTPServer in a thread
« Reply #40 on: August 06, 2019, 02:23:36 pm »

noszone

  • New Member
  • *
  • Posts: 46
Re: TFPHTTPServer in a thread
« Reply #41 on: April 01, 2021, 10:48:49 am »
Does anyone know how to set header - Access-Control-Allow-Origin "*" for this http server? I am trying to read the page from JavaScript, but receiving CORS policy:

Access to XMLHttpRequest at 'http://127.0.0.1:8001/' from origin 'https://192.168.0.34:8443' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
index.js:62 GET http://127.0.0.1:8001/ net::ERR_FAILED

noszone

  • New Member
  • *
  • Posts: 46
Re: TFPHTTPServer in a thread
« Reply #42 on: April 01, 2021, 11:46:43 am »
I found it. Please refer to below code in case if need:

AResponse.SetCustomHeader('Access-Control-Allow-Origin','*');
AResponse.SendHeaders;

 

TinyPortal © 2005-2018