[PATCH 1/4] uclient-fetch: --header option to pass additional raw HTTP headers

Jo-Philipp Wich jo at mein.io
Tue May 10 02:11:01 PDT 2022


Hi Sergey,

a minor nitpick inline below.

On 5/9/22 11:59 PM, Sergey Ponomarev wrote:
> You can add a custom HTTP header(s) to request:
> 
>     wget --header='Authorization: Bearer TOKEN' \
>         --header='If-Modified-Since: Wed, 9 May 2021 12:16:00 GMT' \
>         https://example.com/
> 
> Some headers like Authorization or User-Agent may be already set by --password or --user-agent.
> We may override them but it's a protection from user itself.
> To keep code concise the logic omitted.
> 
> Signed-off-by: Sergey Ponomarev <stokito at gmail.com>
> ---
> [...]
> +			case L_HEADER:
> +				if (!raw_headers) {
> +					/* Max possible count of headers is the count of args (argc) - 2
> +					 Since the first arg is program and last is a URL.
> +					 But user may forget the URL and raw_headers is null terminated so allocate argc */
> +					raw_headers = calloc(argc, sizeof(char *));

Please handle a possible calloc() error here. Maybe consider introducing an
"xalloc()" or similar helper which wraps calloc() and invokes abort() on NULL
return.

> +				}
> +				raw_headers[raw_headers_count] = optarg;
> +				raw_headers_count++;
> +				break;
>  			case L_POST_DATA:
>  				post_data = optarg;
>  				break;
> [...]

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20220510/79c44d30/attachment.sig>


More information about the openwrt-devel mailing list