diff -r 339eca7f76c5 doc/wget.texi
--- a/doc/wget.texi	Sat Aug 09 09:35:45 2008 -0700
+++ b/doc/wget.texi	Mon Aug 11 15:30:17 2008 +0900
@@ -1402,6 +1402,13 @@
 some few obscure servers, which never send HTTP authentication
 challenges, but accept unsolicited auth info, say, in addition to
 form-based authentication.
+
+@cindex content-type
+@item --content-type @var{acclist}
+@itemx --content-type-exclude @var{rejlist}
+Specify comma-separated lists of content type patterns to
+accept or reject. This will be matched against the content-type header, if
+present.
 
 @end table
 
diff -r 339eca7f76c5 src/http.c
--- a/src/http.c	Sat Aug 09 09:35:45 2008 -0700
+++ b/src/http.c	Mon Aug 11 15:30:17 2008 +0900
@@ -2212,8 +2212,15 @@
             logputs (LOG_VERBOSE, "\n");
         }
     }
+  bool is_acceptable_content_type = true;
+  if (type) is_acceptable_content_type = acceptable_content_type (type);
   xfree_null (type);
   type = NULL;                        /* We don't need it any more.  */
+  if (!is_acceptable_content_type)
+    {
+        CLOSE_FINISH (sock);
+	return CTYPEREJECTED;
+    }
 
   /* Return if we have no intention of further downloading.  */
   if (!(*dt & RETROKF) || head_only)
@@ -2414,6 +2421,10 @@
       && !opt.content_disposition
       && file_exists_p (url_file_name (u)))
     send_head_first = true;
+
+  /* Send a preliminary HEAD request if we're filtering on the MIME type. */
+  if (opt.content_accepts || opt.content_rejects)
+    send_head_first = true;
   
   /* THE loop */
   do
@@ -2508,6 +2519,10 @@
              whether the number of tries was exceeded.  */
           printwhat (count, opt.ntry);
           continue;
+	case CTYPEREJECTED:
+	  ret = err;
+	  logprintf (LOG_NOTQUIET, _("Not downloading, content type rejected.\n"));
+	  goto exit;
         case FWRITEERR: case FOPENERR:
           /* Another fatal error.  */
           logputs (LOG_VERBOSE, "\n");
diff -r 339eca7f76c5 src/init.c
--- a/src/init.c	Sat Aug 09 09:35:45 2008 -0700
+++ b/src/init.c	Mon Aug 11 15:30:17 2008 +0900
@@ -132,7 +132,9 @@
   { "checkcertificate", &opt.check_cert,        cmd_boolean },
 #endif
   { "connecttimeout",   &opt.connect_timeout,   cmd_time },
+  { "contentaccepts",   &opt.content_accepts,   cmd_vector },
   { "contentdisposition", &opt.content_disposition, cmd_boolean },
+  { "contentrejects",   &opt.content_rejects,   cmd_vector },
   { "continue",         &opt.always_rest,       cmd_boolean },
   { "convertlinks",     &opt.convert_links,     cmd_boolean },
   { "cookies",          &opt.cookies,           cmd_boolean },
@@ -1519,6 +1521,8 @@
   xfree_null (opt.output_document);
   free_vec (opt.accepts);
   free_vec (opt.rejects);
+  free_vec (opt.content_accepts);
+  free_vec (opt.content_rejects);
   free_vec (opt.excludes);
   free_vec (opt.includes);
   free_vec (opt.domains);
diff -r 339eca7f76c5 src/main.c
--- a/src/main.c	Sat Aug 09 09:35:45 2008 -0700
+++ b/src/main.c	Mon Aug 11 15:30:17 2008 +0900
@@ -160,6 +160,8 @@
     { "continue", 'c', OPT_BOOLEAN, "continue", -1 },
     { "convert-links", 'k', OPT_BOOLEAN, "convertlinks", -1 },
     { "content-disposition", 0, OPT_BOOLEAN, "contentdisposition", -1 },
+    { "content-type", 0, OPT_VALUE, "contentaccepts", -1 },
+    { "content-type-exclude", 0, OPT_VALUE, "contentrejects", -1 },
     { "cookies", 0, OPT_BOOLEAN, "cookies", -1 },
     { "cut-dirs", 0, OPT_VALUE, "cutdirs", -1 },
     { WHEN_DEBUG ("debug"), 'd', OPT_BOOLEAN, "debug", -1 },
@@ -552,6 +554,10 @@
     N_("\
        --content-disposition   honor the Content-Disposition header when\n\
                                choosing local file names (EXPERIMENTAL).\n"),
+    N_("\
+       --content-type=LIST     comma-separated list of accepted content-types.\n"),
+    N_("\
+       --content-type-exclude=LIST  comma-separated list of rejected content-types.\n"),
     N_("\
        --auth-no-challenge     Send Basic HTTP authentication information\n\
                                without first waiting for the server's\n\
diff -r 339eca7f76c5 src/options.h
--- a/src/options.h	Sat Aug 09 09:35:45 2008 -0700
+++ b/src/options.h	Mon Aug 11 15:30:17 2008 +0900
@@ -62,6 +62,9 @@
   char *default_page;           /* Alternative default page (index file) */
 
   bool spider;			/* Is Wget in spider mode? */
+
+  char **content_accepts;	/* List of content-type patterns to accept. */
+  char **content_rejects;	/* List of content-type patterns to reject. */
 
   char **accepts;		/* List of patterns to accept. */
   char **rejects;		/* List of patterns to reject. */
diff -r 339eca7f76c5 src/utils.c
--- a/src/utils.c	Sat Aug 09 09:35:45 2008 -0700
+++ b/src/utils.c	Mon Aug 11 15:30:17 2008 +0900
@@ -715,6 +715,24 @@
     }
   else if (opt.rejects)
     return !in_acclist ((const char *const *)opt.rejects, s, true);
+  return true;
+}
+
+/* Determine whether a content type is acceptable to be downloaded, according to
+ * commandline options. */
+bool
+acceptable_content_type (const char *type)
+{
+  if (opt.content_accepts)
+    {
+      if (opt.content_rejects)
+	return (in_acclist ((const char *const *)opt.content_accepts, type, true)
+		&& !in_acclist ((const char *const *)opt.content_rejects, type, true));
+      else
+	return in_acclist ((const char *const *)opt.content_accepts, type, true);
+    }
+  else if (opt.content_rejects)
+    return !in_acclist ((const char *const *)opt.content_rejects, type, true);
   return true;
 }
 
diff -r 339eca7f76c5 src/utils.h
--- a/src/utils.h	Sat Aug 09 09:35:45 2008 -0700
+++ b/src/utils.h	Mon Aug 11 15:30:17 2008 +0900
@@ -89,6 +89,7 @@
 
 int fnmatch_nocase (const char *, const char *, int);
 bool acceptable (const char *);
+bool acceptable_content_type (const char *);
 bool accdir (const char *s);
 char *suffix (const char *s);
 bool match_tail (const char *, const char *, bool);
diff -r 339eca7f76c5 src/wget.h
--- a/src/wget.h	Sat Aug 09 09:35:45 2008 -0700
+++ b/src/wget.h	Mon Aug 11 15:30:17 2008 +0900
@@ -342,7 +342,7 @@
   READERR, TRYLIMEXC, URLBADPATTERN, FILEBADFILE, RANGEERR, 
   RETRBADPATTERN, RETNOTSUP, ROBOTSOK, NOROBOTS, PROXERR, 
   /* 50  */
-  AUTHFAILED, QUOTEXC, WRITEFAILED, SSLINITFAILED
+  AUTHFAILED, QUOTEXC, WRITEFAILED, SSLINITFAILED, CTYPEREJECTED
 } uerr_t;
 
 #endif /* WGET_H */
diff -r 339eca7f76c5 tests/Test-content-type.px
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/Test-content-type.px	Mon Aug 11 15:30:17 2008 +0900
@@ -0,0 +1,78 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use HTTPTest;
+
+
+###############################################################################
+
+my $dummyfile = <<EOF;
+<html/>
+EOF
+
+# code, msg, headers, content
+my %urls = (
+    '/dummy.html' => {
+        code => "200",
+        msg => "OK",
+        headers => {
+            "Content-type" => "text/html",
+        },
+        content => $dummyfile,
+    },
+);
+
+my $wget_url = "http://localhost:{{port}}/dummy.html";
+
+my %expected_downloaded_files = (
+    'dummy.html' => {
+        content => $dummyfile,
+    }
+);
+
+###############################################################################
+
+my @the_tests = (HTTPTest->new (name => "Test-content-type-accept",
+                              input => \%urls, 
+                              cmdline => $WgetTest::WGETPATH . " --content-type=text/html " . $wget_url,
+                              errcode => 0,
+                              output => \%expected_downloaded_files),
+                HTTPTest->new (name => "Test-content-type-accept-wildcard",
+                              input => \%urls, 
+                              cmdline => $WgetTest::WGETPATH . " --content-type=text/* " . $wget_url,
+                              errcode => 0,
+                              output => \%expected_downloaded_files),
+                HTTPTest->new (name => "Test-content-type-not-accept",
+                              input => \%urls, 
+                              cmdline => $WgetTest::WGETPATH . " --content-type=text " . $wget_url,
+                              errcode => 256,
+                              output => undef),
+                HTTPTest->new (name => "Test-content-type-exclude",
+                              input => \%urls, 
+                              cmdline => $WgetTest::WGETPATH . " --content-type-exclude=text/html " . $wget_url,
+                              errcode => 256,
+                              output => undef),
+                HTTPTest->new (name => "Test-content-type-exclude-wildcard",
+                              input => \%urls, 
+                              cmdline => $WgetTest::WGETPATH . " --content-type-exclude=text/* " . $wget_url,
+                              errcode => 256,
+                              output => undef),
+                HTTPTest->new (name => "Test-content-type-not-exclude",
+                              input => \%urls, 
+                              cmdline => $WgetTest::WGETPATH . " --content-type-exclude=text/xml " . $wget_url,
+                              errcode => 0,
+                              output => \%expected_downloaded_files),
+                HTTPTest->new (name => "Test-content-type-no-header",
+                              input => {'/dummy.html' => { code => "200", msg => "OK", content => $dummyfile}},
+                              cmdline => $WgetTest::WGETPATH . " --content-type-exclude=* " . $wget_url,
+                              errcode => 0,
+                              output => \%expected_downloaded_files));
+
+foreach my $test(@the_tests) {
+    $test->run();
+}
+exit
+
+# vim: et ts=4 sw=4
+
diff -r 339eca7f76c5 tests/run-px
--- a/tests/run-px	Sat Aug 09 09:35:45 2008 -0700
+++ b/tests/run-px	Mon Aug 11 15:30:17 2008 +0900
@@ -43,6 +43,7 @@
     'Test--spider-r--no-content-disposition.px',
     'Test--spider-r--no-content-disposition-trivial.px',
     'Test--spider-r.px',
+    'Test-content-type.px',
 );
 
 my @results;
