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

Using -d arg doesn't automatically make the request method POST #144

Open
gopuneet opened this issue Jul 11, 2022 · 2 comments
Open

Using -d arg doesn't automatically make the request method POST #144

gopuneet opened this issue Jul 11, 2022 · 2 comments

Comments

@gopuneet
Copy link

gopuneet commented Jul 11, 2022

Using -d arg doesn't automatically make the request method POST and sends a GET request which is unexpected behaviour since curl automatically makes the method POST when using -d arg (Refer curl -d manpage & curl tutorial example for post).

Reproducible Example

Here, we are using Neptune Statistics API which uses the same endpoint for getting status, disabling/enabling autoCompute, manually triggering stats generation etc.

  1. Statistics status (GET request)
% awscurl -k --service neptune-db --profile test https://${ENDPOINT}:8182/pg/statistics
{
    "status" : "200 OK",
    "payload" : {
        "autoCompute" : false,
        "active" : true,
        "statisticsId" : 1657533072688,
        "date" : "2022-07-11T09:51Z",
        "summary" : {
            "signatureCount" : 3,
            "instanceCount" : 3,
            "predicateCount" : 5
        }
    }
}
  1. Enable AutoCompute (-d is specified so it should automatically become a POST request but a GET request is sent which can be verified by adding -v)
% awscurl -k --service neptune-db --profile test https://${ENDPOINT}:8182/pg/statistics \
-d '{ "mode" : "enableAutoCompute" }'
{
    "status" : "200 OK",
    "payload" : {
        "autoCompute" : false,
        "active" : true,
        "statisticsId" : 1657533072688,
        "date" : "2022-07-11T09:51Z",
        "summary" : {
            "signatureCount" : 3,
            "instanceCount" : 3,
            "predicateCount" : 5
        }
    }
}
  1. Enable AutoCompute (explicitely specifying -X POST)
% awscurl -k --service neptune-db --profile test https://${ENDPOINT}:8182/pg/statistics \
-d '{ "mode" : "enableAutoCompute" }' -X POST
{
    "status" : "200 OK"
}
@gopuneet gopuneet changed the title Using -d arg doesn' Using -d arg doesn't make the request POST Jul 11, 2022
@gopuneet gopuneet changed the title Using -d arg doesn't make the request POST Using -d arg doesn't automatically make the request method POST Jul 11, 2022
@gopuneet
Copy link
Author

awscurl/awscurl/awscurl.py

Lines 467 to 473 in b4d4807

data = args.data
if data is not None and data.startswith("@"):
filename = data[1:]
with open(filename, "r") as post_data_file:
data = post_data_file.read()

After going through the code, I think the issue can be fixed near the above code block by adding:

data = args.data

if data is not None and args.request != 'POST':
    args.request = 'POST'

# rest same from Line 469

@okigan
Copy link
Owner

okigan commented Jul 20, 2022

Cool, thanks for the find, keeping consistency with curl make it very convenient - please send PR

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

No branches or pull requests

2 participants