Recent

Author Topic: [SOLVED] PostStream is nil on latest OPM Indy10  (Read 5532 times)

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 757
  • Professional amateur ;-P
[SOLVED] PostStream is nil on latest OPM Indy10
« on: June 30, 2021, 04:35:25 am »
Hey Remy,

FPC: 3.2.2 or 3.3.1 (via fpcupdeluxe)
Lazarus: 2.0.12 or 2.3.0 (via fpcupdeluxe)
Indy10: 10.6.2.38.2 installed via OPM
OS: Ubuntu 21.04 64b

On the project attached the event OnCreatePostStream is never called and subsequently, the ARequestInfo.PostStream is nil.
Even if I omit the event OnCreatePostStream, I still get a null ARequestInfo.PostStream.

I'm testing with cURL:
Code: Bash  [Select][+][-]
  1. $ curl -X POST http://127.0.0.1:6969 --data-binary "@rpc-request-test.json"

and the JSON file's content is: (Zipped version attached)
Code: Javascript  [Select][+][-]
  1. {
  2.   "jsonrpc": "2.0",
  3.   "method": "test",
  4.   "params": [],
  5.   "id": 69
  6. }

What baffles me is that, not even a month ago, I was able to compile this type of code and all was well, but now, I'm guessing, after 3.2.2 it suddenly doesn't work.

Is this something specific to my setup or can anyone else reproduce this?

I'm gonna try with these to eliminate versions:
  • Lazarus 2.0.12 and 3.2.0
  • Lazarus 2.0.6 and 3.0.4

If any of those combinations give me the same error then it's something with my system.

Many thanks in advance!!

Cheers,
Gus
« Last Edit: July 01, 2021, 09:18:15 am by Gustavo 'Gus' Carreno »
Lazarus 2.3.0(trunk) FPC 3.3.1(trunk) Ubuntu 21.04 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.2(stable) Ubuntu 21.04 64b Dark Theme
http://github.com/gcarreno

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 757
  • Professional amateur ;-P
Re: [SOLVED] PostStream is nil on latest OPM Indy10
« Reply #1 on: June 30, 2021, 05:21:14 am »
Hey Remy,

Please disregard this whole post!!!

I was too stupid to remember that if you don't specify the Content-Type as application/json, then cURL will use the www-form-encode by default when you specify method POST.

If I use:
Code: Bash  [Select][+][-]
  1.     $ curl -X POST -H "Content-Type: application/json" --data-binary "@rpc-request-test.json" http://127.0.0.1:6969
Then it works, DOH!!!

Again, sorry for being so stupid, LOL!!

My deepest apologies to all, completely mea culpa this unnecessary post...

Cheers,
Gus
« Last Edit: July 01, 2021, 09:15:58 am by Gustavo 'Gus' Carreno »
Lazarus 2.3.0(trunk) FPC 3.3.1(trunk) Ubuntu 21.04 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.2(stable) Ubuntu 21.04 64b Dark Theme
http://github.com/gcarreno

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1007
    • Lebeau Software
Re: [SOLVED] PostStream is nil on latest OPM Indy10
« Reply #2 on: June 30, 2021, 05:33:38 pm »
I was too stupid to remember that if you don't specify the Content-Type as application/json, then cURL will use the www-form-encode by default when you specify method POST.

Even so, TIdHTTPServer should be firing its OnCreatePostStream event for ALL requests that carry a body payload, before the payload is processed and potentially discarded before the OnCommand... event is fired.  If the OnCreatePostStream handler is not assigned, or does not create a TStream object, then TIdHTTPServer will create a TMemoryStream object by default.  So, it makes sense that the ARequestInfo.PostStream is nil for an 'application/x-www-form-urlencoded' request, but it does not make sense for the OnCreatePostStream event to not be fired if it has a handler assigned.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 757
  • Professional amateur ;-P
Re: [SOLVED] PostStream is nil on latest OPM Indy10
« Reply #3 on: July 01, 2021, 09:14:45 am »
Hey Remy,

Even so, TIdHTTPServer should be firing its OnCreatePostStream event for ALL requests that carry a body payload, before the payload is processed and potentially discarded before the OnCommand... event is fired.  If the OnCreatePostStream handler is not assigned, or does not create a TStream object, then TIdHTTPServer will create a TMemoryStream object by default. 

I was wondering why the Event wasn't fired, but I kinda put it down to the fact that TidHTTPServer will parse the application/x-www-form-urlencoded into somewhere(Haven't played with that yet) and then nil's the PostStream. It never occurred to me, after thinking that, that the event should still be fired.

So, it makes sense that the ARequestInfo.PostStream is nil for an 'application/x-www-form-urlencoded' request, but it does not make sense for the OnCreatePostStream event to not be fired if it has a handler assigned.

Okies, so are you on top of that, or do you want me to create an issue on the GitHub repo?

Cheers,
Gus
Lazarus 2.3.0(trunk) FPC 3.3.1(trunk) Ubuntu 21.04 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.2(stable) Ubuntu 21.04 64b Dark Theme
http://github.com/gcarreno

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1007
    • Lebeau Software
Re: [SOLVED] PostStream is nil on latest OPM Indy10
« Reply #4 on: July 01, 2021, 08:31:39 pm »
I was wondering why the Event wasn't fired, but I kinda put it down to the fact that TidHTTPServer will parse the application/x-www-form-urlencoded into somewhere(Haven't played with that yet) and then nil's the PostStream.

Yes, it will (the data is stored in ARequestInfo.UnparsedParams and ARequestInfo.FormParams, and parsed into ARequestInfo.Params).  But, it still gives you the chance to decide which kind of TStream to use to receive the data beforehand.

Okies, so are you on top of that, or do you want me to create an issue on the GitHub repo?

I would want you to first verify the issue actually exists in the latest code before opening a ticket about it.
« Last Edit: July 01, 2021, 08:34:06 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 757
  • Professional amateur ;-P
Re: [SOLVED] PostStream is nil on latest OPM Indy10
« Reply #5 on: July 01, 2021, 08:49:23 pm »
Hey Remy,

Yes, it will (the data is stored in ARequestInfo.UnparsedParams and ARequestInfo.FormParams, and parsed into ARequestInfo.Params).  But, it still gives you the chance to decide which kind of TStream to use to receive the data beforehand.

Thanks for giving this rather precious lesson. Now I know where to find them. You're a star Remy !!

I would want you to first verify the issue actually exists in the latest code before opening a ticket about it.

Sorry, but you'll have to be a bit more specific here: When you say the latest code are you talking about the latest version on GitHub or the latest version on OPM?
If it's the former, I'll have to clone the repo and test.
If it's the latter then the tests I've performed were made with the latest version on OPM like my first post mentions. I've tested it with version 10.6.2.3802.

So which one is it?

Cheers,
Gus
Lazarus 2.3.0(trunk) FPC 3.3.1(trunk) Ubuntu 21.04 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.2(stable) Ubuntu 21.04 64b Dark Theme
http://github.com/gcarreno

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1007
    • Lebeau Software
Re: [SOLVED] PostStream is nil on latest OPM Indy10
« Reply #6 on: July 01, 2021, 09:44:35 pm »
Sorry, but you'll have to be a bit more specific here: When you say the latest code are you talking about the latest version on GitHub or the latest version on OPM?

Preferably GitHub, though Indy in OPM was updated just a few weeks ago (but needs a new update anyway).

If it's the former, I'll have to clone the repo and test.
If it's the latter then the tests I've performed were made with the latest version on OPM like my first post mentions. I've tested it with version 10.6.2.3802.

So which one is it?

Shouldn't really matter in this case, since the way TIdHTTPServer manages the PostStream hasn't changed for a long time.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 757
  • Professional amateur ;-P
Re: [SOLVED] PostStream is nil on latest OPM Indy10
« Reply #7 on: July 05, 2021, 02:31:06 am »
Hey Remy,

Shouldn't really matter in this case, since the way TIdHTTPServer manages the PostStream hasn't changed for a long time.

Okydokes, then I'll post and issue on Github after I come back from hospital, around Wednesday(2021/07/07).

Cheers,
Gus
Lazarus 2.3.0(trunk) FPC 3.3.1(trunk) Ubuntu 21.04 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.2(stable) Ubuntu 21.04 64b Dark Theme
http://github.com/gcarreno

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 757
  • Professional amateur ;-P
Re: [SOLVED] PostStream is nil on latest OPM Indy10
« Reply #8 on: July 09, 2021, 09:44:55 pm »
Hey Remy and all,

As you all can see in this Indy10 issue I've made a complete fool of myself.

Looks like the last version of Indy10 that is installable via OPM does not have the issue of not firing the event in question.

I've apologised to you on that issue but I wanted to make it public here too:

I'm really sorry for wasting your time on this wild goose chase!! :( :-[

Many thanks for your immense patience!!

Cheers,
Gus
Lazarus 2.3.0(trunk) FPC 3.3.1(trunk) Ubuntu 21.04 64b Dark Theme
Lazarus 2.0.12(stable) FPC 3.2.2(stable) Ubuntu 21.04 64b Dark Theme
http://github.com/gcarreno

 

TinyPortal © 2005-2018