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

Support of --method, --body-data and --body-file #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

stokito
Copy link

@stokito stokito commented Jul 13, 2024

The PR allows to set a custom method e.g. PUT, DELETE but only that supported by the request_type enum.
This opens a way to use most of modern REST APIs:

wget -O - -q \
--method=DELETE \
http://api.example.com/

You may send a body:

wget -O - -q \
--method=PUT \
--body-data='{"id": 42}' \
--header='Content-Type: application/json' \
http://api.example.com/

@dhewg @dangowrt @mans0n @efahl @ynezz please review

stokito and others added 3 commits July 13, 2024 12:48
The var means that ether --post-data or --post-file was set.

Remove duplicated code to set the Content-Type header.

Signed-off-by: Sergey Ponomarev <[email protected]>
In GNU wget the --spider first issues a HEAD request, then if HEAD fails, issues a GET request.
In uclient, only a GET request is sent.
The patch changes GET to HEAD e.g. get the file size without downloading it first.

This is still not totally compatible with GNU wget because it does not retry with GET if HEAD fails.
Someone may use the --spider to call a GET only API, so they may be affected.
But this is incorrect usage while others may expect that the spider uses HEAD and don't expect a download.

Signed-off-by: Sungbo Eo <[email protected]>
Signed-off-by: Sergey Ponomarev <[email protected]>
The --method allows executing PUT, DELETE, OPTIONS, HEAD e.g.:

    wget -O - -q \
    --method=PUT \
    --body-data='{"id": 42}' \
    --header='Content-Type: application/json' \
    http://api.example.com/

To avoid clashes with the --post-data/file options,
the separate --body-data/file must be used.
They are stored to the same post_data and post_data vars.
Mutual usage of the options is not allowed, same as in GNU wget.

Signed-off-by: Sergey Ponomarev <[email protected]>
@stokito
Copy link
Author

stokito commented Sep 5, 2024

@dhewg @dangowrt @mans0n @efahl @ynezz please review if you'll have a minute

@efahl
Copy link

efahl commented Sep 5, 2024

Looks good to me! I like how it cleans up the Content-Type header logic.

I noticed that no_output relies on implicit initialization, which bugs me, but it's been like that for 9 years, so...

@Neustradamus
Copy link

@dangowrt, @nbd168: What do you think?

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 this pull request may close these issues.

4 participants