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

POST request with body not working #114

Closed
sugarjig opened this issue Oct 23, 2023 · 3 comments · Fixed by #115
Closed

POST request with body not working #114

sugarjig opened this issue Oct 23, 2023 · 3 comments · Fixed by #115

Comments

@sugarjig
Copy link

I have a very simple web service running locally. It has a POST endpoint at /hello that accepts a JSON body of the form

{
  "name": "John"
}

and it responds with a body like

{
  "message": "Hello John"
}

When I try using Aperture to proxy the request, I get an error. Here is the curl command I'm using

% curl -X POST -H "Content-Type: application/json" -d '{"name": "John"}' -k --http1.1 https://localhost:8081/hello

and the error I get is

curl: (18) transfer closed with 16 bytes remaining to read

However, if I don't send a body to the endpoint, I get a 402 as expected:

% curl -X POST -k --http1.1 https://localhost:8081/hello
payment required

FWIW, I am able to dump the request details right before the call to sendDirectResponse in the handlePaymentRequired method, and I can see the body I'm expecting.

POST /hello HTTP/1.1
Host: localhost:8081
Accept: */*
Access-Control-Allow-Headers: Authorization, Grpc-Metadata-macaroon, WWW-Authenticate
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: WWW-Authenticate
Content-Length: 16
Content-Type: application/json
User-Agent: curl/8.1.2
Www-Authenticate: LSAT macaroon="...", invoice="..."

{"name": "John"}

Am I missing something in my request?

@sugarjig
Copy link
Author

sugarjig commented Oct 23, 2023

Forgot to mention that when I try the same request in Postman, I get Error: aborted. Trying it in the JetBrains HTTP client, I get org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 20; received: 17)

@guggero
Copy link
Member

guggero commented Oct 24, 2023

Hey. Thanks for the report. Looks like this was caused by the request headers being blindly copied when sending the L402 challenge header. Created a quick PR here: #114. Will need to make sure nothing else breaks with that, but it should fix your issue.

@sugarjig
Copy link
Author

Thanks for the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants