To keep that body, we'd have to define what happens if the authorization
that follows proves to be successful.

I have prepared a simple workaround patch and the current behavior would
be to save the "error" body as eg. index.html and then to append ".1" to
the file name if the authorization happens. (As is usually done when the
file exists.) Perhaps we would rather like to overwrite the
unauthorized-body if the authorization succeeds.

And by the way I am thinking of a refactorization in gethttp/http_loop;
so that gethttp returns to http_loop on auth error. So that
HTTP_STATUS_UNAUTHORIZED is no longer a special case. (Then, in
particular, the code duplication for file write could be avoided.)
But it seems to be a little bit more of hacking.

W dniu 20.04.2015 o 17:29, Stefan Heid pisze:
> Dear GNU-Team,
> 
> wget seems not to download the Http-body on a 401 error. The
> Webdeveloper-tools of firefox show clearly that there is a body on the
> response.
> 
> wget --content-on-error
> https://koala.uni-paderborn.de/signin/semester/SS15/355827044861529/units/
> 
> 
> The Content-on-error option makes no difference at all.
> 
> Greetings Stefan
> 
From 0f08d9bbd9e48c62ab15652316948329317b3e01 Mon Sep 17 00:00:00 2001
From: Hubert Tarasiuk <[email protected]>
Date: Wed, 22 Apr 2015 19:04:22 +0200
Subject: [PATCH] Handle --content-on-error on http authorization.

* src/http.c (gethttp): Save response body to file if
authorization "error" is encountered.
---
 src/http.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/http.c b/src/http.c
index f543957..09b1d2e 100644
--- a/src/http.c
+++ b/src/http.c
@@ -2766,15 +2766,32 @@ gethttp (struct url *u, struct http_stat *hs, int *dt, struct url *proxy,
       bool retry;
       /* Normally we are not interested in the response body.
          But if we are writing a WARC file we are: we like to keep everyting.  */
-      if (warc_enabled)
+      if (warc_enabled || opt.content_on_error)
         {
           int _err;
           type = resp_header_strdup (resp, "Content-Type");
-          _err = read_response_body (hs, sock, NULL, contlen, 0,
+
+          fp = NULL;
+          if (opt.content_on_error)
+            {
+              _err = open_output_stream (hs, count, &fp);
+              if (_err != RETROK)
+                {
+                  CLOSE_INVALIDATE (sock);
+                  retval = _err;
+                  goto cleanup;
+                }
+            }
+
+          _err = read_response_body (hs, sock, fp, contlen, 0,
                                     chunked_transfer_encoding,
                                     u->url, warc_timestamp_str,
                                     warc_request_uuid, warc_ip, type,
                                     statcode, head);
+
+          if (fp)
+            fclose (fp);
+
           xfree (type);
 
           if (_err != RETRFINISHED || hs->res < 0)
-- 
2.3.5

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to