aperture
aperture copied to clipboard
POST request with body not working
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?
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)
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: https://github.com/lightninglabs/aperture/issues/114. Will need to make sure nothing else breaks with that, but it should fix your issue.
Thanks for the quick response!