The -S is useful for debugging.
With --spider or --method=HEAD it allows check size before download by 
Content-Length header.

TODO currently the uclient-http must somehow to call a callback to print.

Signed-off-by: Sergey Ponomarev <[email protected]>
---
 uclient-fetch.c | 12 +++++++++++-
 uclient-http.c  |  3 +++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/uclient-fetch.c b/uclient-fetch.c
index 282092e..f11ecd9 100644
--- a/uclient-fetch.c
+++ b/uclient-fetch.c
@@ -47,6 +47,7 @@ static const char *post_file;
 static struct ustream_ssl_ctx *ssl_ctx;
 static const struct ustream_ssl_ops *ssl_ops;
 static int quiet = false;
+static bool show_server_response = false;
 static bool verify = true;
 static bool proxy = true;
 static bool default_certs = false;
@@ -478,6 +479,7 @@ static int usage(const char *progname)
                "       -O <file>                       Redirect output to file 
(use \"-\" for stdout)\n"
                "       -P <dir>                        Set directory for 
output files\n"
                "       --quiet | -q                    Turn off status 
messages\n"
+               "       --server-response | -S                  Show response 
headers\n"
                "       --continue | -c                 Continue a 
partially-downloaded file\n"
                "       --user=<user>                   HTTP authentication 
username\n"
                "       --password=<password>           HTTP authentication 
password\n"
@@ -550,6 +552,7 @@ enum {
        L_PROXY,
        L_NO_PROXY,
        L_QUIET,
+       L_SERVER_RESPONSE,
 };
 
 static const struct option longopts[] = {
@@ -567,6 +570,7 @@ static const struct option longopts[] = {
        [L_PROXY] = { "proxy", required_argument, NULL, 0 },
        [L_NO_PROXY] = { "no-proxy", no_argument, NULL, 0 },
        [L_QUIET] = { "quiet", no_argument, NULL, 0 },
+       [L_SERVER_RESPONSE] = { "server-response", no_argument, NULL, 0 },
        {}
 };
 
@@ -588,7 +592,7 @@ int main(int argc, char **argv)
        signal(SIGPIPE, SIG_IGN);
        init_ustream_ssl();
 
-       while ((ch = getopt_long(argc, argv, "46cO:P:qsT:U:Y:", longopts, 
&longopt_idx)) != -1) {
+       while ((ch = getopt_long(argc, argv, "46cO:P:qSsT:U:Y:", longopts, 
&longopt_idx)) != -1) {
                switch(ch) {
                case 0:
                        switch (longopt_idx) {
@@ -651,6 +655,9 @@ int main(int argc, char **argv)
                        case L_QUIET:
                                quiet = true;
                                break;
+                       case L_SERVER_RESPONSE:
+                               show_server_response = true;
+                               break;
                        default:
                                return usage(progname);
                        }
@@ -683,6 +690,9 @@ int main(int argc, char **argv)
                case 's':
                        no_output = true;
                        break;
+               case 'S':
+                       show_server_response = true;
+                       break;
                case 'T':
                        timeout = atoi(optarg);
                        break;
diff --git a/uclient-http.c b/uclient-http.c
index c2bba6b..be67281 100644
--- a/uclient-http.c
+++ b/uclient-http.c
@@ -757,6 +757,9 @@ static void __uclient_notify_read(struct uclient_http *uh)
 
                        *sep = 0;
                        cur_len = next - data;
+//                     if (show_server_response) {
+                               fprintf(stderr, "  %s\n", data);
+//                     }
                        uclient_parse_http_line(uh, data);
                        if (seq != uh->seq)
                                return;
-- 
2.34.1


_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to