Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TidHTTPServer does not call event to create Post Stream #366

Closed
gcarreno opened this issue Jul 5, 2021 · 5 comments
Closed

TidHTTPServer does not call event to create Post Stream #366

gcarreno opened this issue Jul 5, 2021 · 5 comments
Labels
Element: HTTP Issues related to HTTP handling, TIdHTTP, TIdHTTPServer, TIdHTTPProxyServer, etc Status: Completed Issue has been closed, no further work needed Type: Bug Issue is a bug in existing code

Comments

@gcarreno
Copy link

gcarreno commented Jul 5, 2021

Hi Remy (@rlebeau)

Like you asked on the Lazarus forums, I'm posting this issue:

When a post is performed with Content-Type: www-form-urlencoded the HTTP server should fire up the event to create the post stream.

This only happens if the Content-Type is something else than above.

Cheers,
Gus

@rlebeau
Copy link
Member

rlebeau commented Jul 6, 2021

I assume you meant application/x-www-form-urlencoded. And as I told you in the other forum, TIdHTTPServer should always be firing the OnCreatePostStream event if there is body data present (Transfer-Encoding is present and not 'identity', or Content-Length is present), regardless of the Content-Type header. Can you please provide an example where this is not the case?

@rlebeau rlebeau added Type: Bug Issue is a bug in existing code Element: HTTP Issues related to HTTP handling, TIdHTTP, TIdHTTPServer, TIdHTTPProxyServer, etc labels Jul 6, 2021
@gcarreno
Copy link
Author

gcarreno commented Jul 7, 2021

Hey Remy(@rlebeau),

Apologies

I assume you meant application/x-www-form-urlencoded

You are absolutely correct and I'm sorry I was lazy to include the full correct string 😃

Again I beg for forgiveness since I should've provided the same example I did on the forums here. I guess I assumed you would correlate both and just pick the files/examples I provided on the forum.

Example

These are the project and JSON file I', using:
Server-JSON-RPC-v0.2.zip
RPC-Request-test.zip

and here's the cURL command that will do the trick:

$ curl -X POST --data-binary '@rpc-request-test.json' http://localhost:6969

The problem here is that if you don't specify a Content-Type, then cURL will assume application/x-www-form-urlencoded by default.

Cheers,
Gus

@rlebeau
Copy link
Member

rlebeau commented Jul 7, 2021

It would be useful to see the result of your logging. Or better, a capture of the actual raw HTTP request, from a packet sniffer like Wireshark, or by assigning one of Indy's TIdLog... components to the connection's IOHandler on the server side.

Small nitpick - in your OnCommandGet handler, if ARequestInfo.HasContentLength then should be if Assigned(ARequestInfo.PostStream) then, since HasContentLength is not the only condition that can cause a PostStream to be created.

@gcarreno
Copy link
Author

gcarreno commented Jul 9, 2021

Hey Remy(@rlebeau)

I have to admit, you drive a bloody hard bargain 😉 😝

Let's see if I can comply with all your demands:

Logging

I wasn't sure if I had logging turned on in the first file that I sent you, so I made sure it was ON and even did a little bash script to run the server in the background, run the correct and incorrect cURL commands and then kill the server.

This is what the logging and the bash script spits out:

### Starting the server
JSON RPC Server on port 6969
2021-07-09 20:16:45:[INFO] Activating

### Testing with correct Content-Type
2021-07-09 20:16:46:[INFO] Create Post Stream
2021-07-09 20:16:46:[INFO] Command Get Method: POST
2021-07-09 20:16:46:[INFO] Content Type is JSON
2021-07-09 20:16:46:[INFO] HasContentLength is True
2021-07-09 20:16:46:[INFO] == Content ==
2021-07-09 20:16:46:[INFO] { "jsonrpc" : "2.0", "method" : "test", "params" : [], "id" : 69 }
2021-07-09 20:16:46:[INFO] Method: test
{"jsonrpc":"2.0","response":"Test OK","id":69}

### Testing with no Content-Type
2021-07-09 20:16:46:[INFO] Create Post Stream
2021-07-09 20:16:46:[INFO] Command Get Method: POST
2021-07-09 20:16:46:[ERROR] Bad Request
{"jsonrpc":"2.0","error":{"code":400,"message":"Bad Request"},"id":null}

### Killing the server

And the set of files that I used for this:
Server-JSON-RPC-v0.3.tar.gz

WireShark

ServerJSONRPC-Wireshark.tar.gz

On the nitpicking

This is throw away code. It's kinda me in a pitch black room, with a blind fold, trying to feel myself out of it.

I'm very thankful for that nitpicking, since it will improve my future code.

Cheers,
Gus

@gcarreno
Copy link
Author

gcarreno commented Jul 9, 2021

Hey Remy(@rlebeau),

I now have egg on my face!!!! 🥚 and I'm very sorry for wasting your time!!!

I was re-reading the post I made and I looked at the Logging with more attention and I noticed that both had:

### Testing with correct Content-Type
2021-07-09 20:16:46:[INFO] Create Post Stream
...
### Testing with no Content-Type
2021-07-09 20:16:46:[INFO] Create Post Stream

This means that the latest version on OPM is behaving correctly and that it was the previous version that I had installed that was in the wrong.

Again, Remy, MANY apologies for wasting your time on this matter.
If only I'd had a better look at my OWN logging and not be a clutz!!!

Many thanks for your patience!!

Cheers,
Gus

@rlebeau rlebeau closed this as completed Jul 10, 2021
@IndySockets IndySockets deleted a comment from ezurschmiede Jul 10, 2021
@rlebeau rlebeau added the Status: Completed Issue has been closed, no further work needed label Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Element: HTTP Issues related to HTTP handling, TIdHTTP, TIdHTTPServer, TIdHTTPProxyServer, etc Status: Completed Issue has been closed, no further work needed Type: Bug Issue is a bug in existing code
Projects
None yet
Development

No branches or pull requests

2 participants