[Bug-wget] Patch: new option --content-on-error: do not skip content on http server error

2011-10-02 Thread Henrik Holst
This patch adds an option to not skip the content sent by the HTTP server
when the server responds with a status code in the 4xx and 5xx range.

This is quite useful when dealing with RESTful web services since they often
use the http status code to indicate an error and then add content with an
extended explanation of the error in question.
I noticed that cURL by default shows the content on error and has instead an
option to disable it but I guess that changing the default behavior of wget
is kind of out of the question :-)

And besides beeing useful, RFC2616 states that User agents SHOULD display
any included entity to the user. for client errors (4xx).

I have attached the patch since I know that Gmail sometimes does tricks with
inline patches.

/Henrik Holst

diff -u wget-1.13_orig/src/http.c wget-1.13/src/http.c
--- wget-1.13_orig/src/http.c2011-10-02 00:59:05.949926929 +0200
+++ wget-1.13/src/http.c2011-10-01 01:29:52.740942125 +0200
@@ -2448,7 +2448,7 @@
   type = NULL;/* We don't need it any more.  */

   /* Return if we have no intention of further downloading.  */
-  if (!(*dt  RETROKF) || head_only)
+  if ((!(*dt  RETROKF)  !opt.content_on_error) || head_only)
 {
   /* In case the caller cares to look...  */
   hs-len = 0;
diff -u wget-1.13_orig/src/init.c wget-1.13/src/init.c
--- wget-1.13_orig/src/init.c2011-10-02 00:59:05.979926929 +0200
+++ wget-1.13/src/init.c2011-10-01 01:34:02.810941982 +0200
@@ -139,6 +139,7 @@
   { chooseconfig, opt.choose_config,cmd_file },
   { connecttimeout,   opt.connect_timeout,   cmd_time },
   { contentdisposition, opt.content_disposition, cmd_boolean },
+  { contentonerror,   opt.content_on_error,  cmd_boolean },
   { continue, opt.always_rest,   cmd_boolean },
   { convertlinks, opt.convert_links, cmd_boolean },
   { cookies,  opt.cookies,   cmd_boolean },
diff -u wget-1.13_orig/src/main.c wget-1.13/src/main.c
--- wget-1.13_orig/src/main.c2011-10-02 00:59:05.859926929 +0200
+++ wget-1.13/src/main.c2011-10-01 01:50:05.760941442 +0200
@@ -178,6 +178,7 @@
 { continue, 'c', OPT_BOOLEAN, continue, -1 },
 { convert-links, 'k', OPT_BOOLEAN, convertlinks, -1 },
 { content-disposition, 0, OPT_BOOLEAN, contentdisposition, -1 },
+{ content-on-error, 0, OPT_BOOLEAN, contentonerror, -1 },
 { cookies, 0, OPT_BOOLEAN, cookies, -1 },
 { cut-dirs, 0, OPT_VALUE, cutdirs, -1 },
 { WHEN_DEBUG (debug), 'd', OPT_BOOLEAN, debug, -1 },
@@ -595,6 +596,8 @@
--content-disposition   honor the Content-Disposition header when\n\
choosing local file names
(EXPERIMENTAL).\n),
 N_(\
+   --content-on-error  output the received content on server
errors.\n),
+N_(\
--auth-no-challenge send Basic HTTP authentication
information\n\
without first waiting for the server's\n\
challenge.\n),
diff -u wget-1.13_orig/src/options.h wget-1.13/src/options.h
--- wget-1.13_orig/src/options.h2011-10-02 00:59:05.949926929 +0200
+++ wget-1.13/src/options.h2011-10-01 01:46:34.520941561 +0200
@@ -130,6 +130,8 @@
   bool server_response;/* Do we print server response? */
   bool save_headers;/* Do we save headers together with
file? */
+  bool content_on_error;/* Do we output the content when the HTTP
+   status code indicates a server error */

 #ifdef ENABLE_DEBUG
   bool debug;/* Debugging on/off */
diff -u wget-1.13_orig/doc/wget.info wget-1.13/doc/wget.info
--- wget-1.13_orig/doc/wget.info2011-10-02 00:59:06.769926929 +0200
+++ wget-1.13/doc/wget.info2011-10-02 00:58:26.139926946 +0200
@@ -1288,6 +1288,10 @@
  use `Content-Disposition' headers to describe what the name of a
  downloaded file should be.

+`--content-on-error'
+ If this is set to on, wget will not skip the content when the
+ server responds with a http status code that indicates error.
+
 `--trust-server-names'
  If this is set to on, on a redirect the last component of the
  redirection URL will be used as the local file name.  By default
diff -u wget-1.13_orig/doc/wget.texi wget-1.13/doc/wget.texi
--- wget-1.13_orig/doc/wget.texi2011-10-02 00:59:06.769926929 +0200
+++ wget-1.13/doc/wget.texi2011-10-02 00:58:21.869926947 +0200
@@ -1506,6 +1506,12 @@
 @code{Content-Disposition} headers to describe what the name of a
 downloaded file should be.

+@cindex Content On Error
+@item --content-on-error
+
+If this is set to on, wget will not skip the content when the server
responds
+with a http status code that indicates error.
+
 @cindex Trust server names
 @item --trust-server-names
diff -u wget-1.13_orig/src/http.c wget-1.13/src/http.c
--- wget-1.13_orig/src/http.c	2011-10-02 00:59:05.949926929 +0200
+++ wget-1.13/src/http.c	2011-10-01 01:29:52.740942125 +0200
@@ -2448,7 

Re: [Bug-wget] Wget 1.13.4 v. VMS -- Various problems

2011-10-02 Thread Steven M. Schweda
   And a (very) minor typo:

ALP $ gdiff -u  src/utils.c_orig src/utils.c
--- src/utils.c_orig2011-08-29 03:01:24 -0500
+++ src/utils.c 2011-10-02 23:22:29 -0500
@@ -769,8 +769,7 @@
   open_id = 13;
   fd = open( fname, /* File name. */
flags,   /* Flags. */
-   0777,/* Mode for default protection.
-*/
+   0777,/* Mode for default protection. */
rfm=stmlf, /* Stream_LF. */
OPEN_OPT_ARGS);  /* Access callback. */
 }



   Steven M. Schweda   sms@antinode-info
   382 South Warwick Street(+1) 651-699-9818
   Saint Paul  MN  55105-2547