diff -u -r -N squid-4.0.7/ChangeLog squid-4.0.8/ChangeLog
--- squid-4.0.7/ChangeLog	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/ChangeLog	2016-04-02 10:04:07.000000000 +1300
@@ -1,3 +1,22 @@
+Changes to squid-4.0.8 (02 Apr 2016):
+
+	- Bug 4459: FHS compliance: move netdb.state and ssl_db to /var/cache/squid
+	- Bug 4458: Behaviour change with external ACL arguments
+	- Bug 4450: wait() related cleanup
+	- Bug 4438: SIGSEGV in memFreeString() destructing SBuf globals on shutdown/restart
+	- Bug 4312: Support disabling collapsed forwarding SMP cooperation
+	- Bug 3826: SMP compatibility with systemd and --foreground option
+	- Bug 1979: Add ACL-driven server_pconn_for_nonretriable squid.conf directive
+	- Bug 7 (partial): Update cached entries on 304 responses
+	- Add reply_header_add directive
+	- HTTP/1.1: Do not prohibit updating Last-Modified on 304 responses
+	- Fix memory leaks of lastAclData and AccessLogentry::url
+	- Fix clang -Winconsistent-missing-override warning
+	- Tests: update test suite for GnuTLS
+	- ... and some documentation updates
+	- ... and some code cleanup and polishing
+	- ... and all fixes from squid 3.5.16
+
 Changes to squid-4.0.7 (23 Feb 2016):
 
 	- Regression Fix: external_acl parameters separated by %20 instead of space
@@ -120,6 +139,24 @@
 	- ... and many documentation changes
 	- ... and much code cleanup and polishing
 
+Changes to squid-3.5.16 (02 Apr 2016):
+
+	- Bug 4476: Removed duplicated #include lines
+	- Bug 4452: squid -z segfaults with ufs
+	- Bug 4447:FwdState.cc:447 "serverConnection() == conn" assertion
+	- Bug 4423: adding stdio: prefix to cache_log directive produces FATAL error
+	- Bug 4409: compile error when two Heimdal libraries are installed
+	- Bug 2831: Cache-control: max-age not sent on TCP_IMS_HIT/304
+	- pinger: Fix buffer overflow in Icmp6::Recv
+	- pinger: Fix select(2) to actually use max_fd
+	- pinger: drop capabilities on Linux
+	- Fix memory leak of HttpRequest objects
+	- Fix memory leak when the cache of sslcrtvalidator_program is disabled via ttl=0
+	- Fix assertion failed: Write.cc:41: "!ccb->active()"
+	- Fix crash on shutdown while cleaning up idle ICAP connections
+	- RFC 7725: Add registry entry for 451 status text
+	- ... and some build issues
+
 Changes to squid-3.5.15 (23 Feb 2016):
 
 	- Bug 3870: assertion failed: String.cc: 'len_ + len <65536' in ESI::CustomParser
diff -u -r -N squid-4.0.7/compat/Makefile.in squid-4.0.8/compat/Makefile.in
--- squid-4.0.7/compat/Makefile.in	2016-02-24 06:48:59.000000000 +1300
+++ squid-4.0.8/compat/Makefile.in	2016-04-02 10:06:12.000000000 +1300
@@ -703,6 +703,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/configure squid-4.0.8/configure
--- squid-4.0.7/configure	2016-02-24 06:49:58.000000000 +1300
+++ squid-4.0.8/configure	2016-04-02 10:08:39.000000000 +1300
@@ -1,7 +1,7 @@
 #! /bin/sh
 # From configure.ac Revision.
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.69 for Squid Web Proxy 4.0.7.
+# Generated by GNU Autoconf 2.69 for Squid Web Proxy 4.0.8.
 #
 # Report bugs to <http://bugs.squid-cache.org/>.
 #
@@ -595,8 +595,8 @@
 # Identity of this package.
 PACKAGE_NAME='Squid Web Proxy'
 PACKAGE_TARNAME='squid'
-PACKAGE_VERSION='4.0.7'
-PACKAGE_STRING='Squid Web Proxy 4.0.7'
+PACKAGE_VERSION='4.0.8'
+PACKAGE_STRING='Squid Web Proxy 4.0.8'
 PACKAGE_BUGREPORT='http://bugs.squid-cache.org/'
 PACKAGE_URL=''
 
@@ -1650,7 +1650,7 @@
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures Squid Web Proxy 4.0.7 to adapt to many kinds of systems.
+\`configure' configures Squid Web Proxy 4.0.8 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1721,7 +1721,7 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of Squid Web Proxy 4.0.7:";;
+     short | recursive ) echo "Configuration of Squid Web Proxy 4.0.8:";;
    esac
   cat <<\_ACEOF
 
@@ -2148,7 +2148,7 @@
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-Squid Web Proxy configure 4.0.7
+Squid Web Proxy configure 4.0.8
 generated by GNU Autoconf 2.69
 
 Copyright (C) 2012 Free Software Foundation, Inc.
@@ -3252,7 +3252,7 @@
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by Squid Web Proxy $as_me 4.0.7, which was
+It was created by Squid Web Proxy $as_me 4.0.8, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
@@ -4119,7 +4119,7 @@
 
 # Define the identity of the package.
  PACKAGE='squid'
- VERSION='4.0.7'
+ VERSION='4.0.8'
 
 
 cat >>confdefs.h <<_ACEOF
@@ -20703,7 +20703,7 @@
     SQUID_CFLAGS="$squid_cv_cc_option_wall -Wpointer-arith -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wcomments -Wshadow"
     ;;
   esac
-  SQUID_CXXFLAGS="$squid_cv_cc_option_wall -Wpointer-arith -Wwrite-strings -Wcomments -Wshadow"
+  SQUID_CXXFLAGS="$squid_cv_cc_option_wall -Wpointer-arith -Wwrite-strings -Wcomments -Wshadow -Woverloaded-virtual"
 else
   SQUID_CFLAGS=
   SQUID_CXXFLAGS=
@@ -21949,15 +21949,18 @@
       fi
       ;;
     rock)
-	if test "x$squid_disk_module_candidates_IpcIo" != "xyes" -a \
-	  "x$squid_disk_module_candidates_Blocking" != "xyes"; then
-	  as_fn_error $? "Storage module Rock requires IpcIo or Blocking DiskIO module" "$LINENO" 5
-	fi
-	squid_do_build_rock=true
-	;;
+      if test "x$squid_disk_module_candidates_IpcIo" != "xyes" -a \
+        "x$squid_disk_module_candidates_Blocking" != "xyes"; then
+         as_fn_error $? "Storage module Rock requires DiskIO module: Blocking or IpcIo" "$LINENO" 5
+      fi
+      squid_do_build_rock=true
+      ;;
     ufs)
-	squid_do_build_ufs=true
-	;;
+      if test "x$squid_disk_module_candidates_Blocking" != "xyes"; then
+        as_fn_error $? "Storage module ufs requires DiskIO module: Blocking" "$LINENO" 5
+      fi
+      squid_do_build_ufs=true
+      ;;
     esac
 done
 
@@ -27979,7 +27982,7 @@
     if test "x$ac_cv_path_krb5_config" != "xno" ; then
       krb5confpath="`dirname $ac_cv_path_krb5_config`"
       ac_heimdal="`$ac_cv_path_krb5_config --version 2>/dev/null | grep -c -i heimdal`"
-      if test "x$with_heimdal_krb5" = "xyes"; then
+      if test "x$with_heimdal_krb5" = "xyes" -a $ac_heimdal = 0; then
         as_fn_error $? "Could not find pkg-config or krb5-config for Heimdal Kerberos" "$LINENO" 5
       fi
     else
@@ -41724,7 +41727,7 @@
 
 rm -f core
 
-ac_config_files="$ac_config_files Makefile compat/Makefile contrib/Makefile doc/Makefile doc/manuals/Makefile doc/release-notes/Makefile errors/Makefile icons/Makefile lib/Makefile lib/libTrie/Makefile lib/libTrie/test/Makefile lib/ntlmauth/Makefile lib/profiler/Makefile lib/rfcnb/Makefile lib/smblib/Makefile lib/snmplib/Makefile scripts/Makefile src/Makefile src/acl/Makefile src/acl/external/Makefile src/acl/external/AD_group/Makefile src/acl/external/delayer/Makefile src/acl/external/eDirectory_userip/Makefile src/acl/external/file_userip/Makefile src/acl/external/kerberos_ldap_group/Makefile src/acl/external/LDAP_group/Makefile src/acl/external/LM_group/Makefile src/acl/external/session/Makefile src/acl/external/SQL_session/Makefile src/acl/external/unix_group/Makefile src/acl/external/wbinfo_group/Makefile src/acl/external/time_quota/Makefile src/adaptation/Makefile src/adaptation/icap/Makefile src/adaptation/ecap/Makefile src/anyp/Makefile src/auth/Makefile src/auth/basic/Makefile src/auth/basic/DB/Makefile src/auth/basic/fake/Makefile src/auth/basic/getpwnam/Makefile src/auth/basic/LDAP/Makefile src/auth/basic/NCSA/Makefile src/auth/basic/NIS/Makefile src/auth/basic/PAM/Makefile src/auth/basic/POP3/Makefile src/auth/basic/RADIUS/Makefile src/auth/basic/SASL/Makefile src/auth/basic/SMB/Makefile src/auth/basic/SMB_LM/Makefile src/auth/basic/SSPI/Makefile src/auth/digest/Makefile src/auth/digest/eDirectory/Makefile src/auth/digest/file/Makefile src/auth/digest/LDAP/Makefile src/auth/negotiate/Makefile src/auth/negotiate/kerberos/Makefile src/auth/negotiate/SSPI/Makefile src/auth/negotiate/wrapper/Makefile src/auth/ntlm/Makefile src/auth/ntlm/fake/Makefile src/auth/ntlm/SMB_LM/Makefile src/auth/ntlm/SSPI/Makefile src/base/Makefile src/clients/Makefile src/comm/Makefile src/dns/Makefile src/DiskIO/Makefile src/DiskIO/AIO/Makefile src/DiskIO/Blocking/Makefile src/DiskIO/DiskDaemon/Makefile src/DiskIO/DiskThreads/Makefile src/DiskIO/IpcIo/Makefile src/DiskIO/Mmapped/Makefile src/esi/Makefile src/eui/Makefile src/format/Makefile src/fs/Makefile src/ftp/Makefile src/helper/Makefile src/http/Makefile src/http/one/Makefile src/http/url_rewriters/Makefile src/http/url_rewriters/fake/Makefile src/http/url_rewriters/LFS/Makefile src/icmp/Makefile src/ident/Makefile src/ip/Makefile src/ipc/Makefile src/log/Makefile src/log/DB/Makefile src/log/file/Makefile src/mem/Makefile src/mgr/Makefile src/parser/Makefile src/repl/Makefile src/security/Makefile src/security/cert_generators/Makefile src/security/cert_generators/file/Makefile src/security/cert_validators/Makefile src/security/cert_validators/fake/Makefile src/servers/Makefile src/snmp/Makefile src/ssl/Makefile src/store/Makefile src/store/id_rewriters/Makefile src/store/id_rewriters/file/Makefile test-suite/Makefile tools/Makefile tools/helper-mux/Makefile tools/purge/Makefile tools/squidclient/Makefile tools/systemd/Makefile tools/sysvinit/Makefile"
+ac_config_files="$ac_config_files Makefile compat/Makefile contrib/Makefile doc/Makefile doc/manuals/Makefile doc/release-notes/Makefile errors/Makefile icons/Makefile lib/Makefile lib/libTrie/Makefile lib/libTrie/test/Makefile lib/ntlmauth/Makefile lib/profiler/Makefile lib/rfcnb/Makefile lib/smblib/Makefile lib/snmplib/Makefile scripts/Makefile src/Makefile src/acl/Makefile src/acl/external/Makefile src/acl/external/AD_group/Makefile src/acl/external/delayer/Makefile src/acl/external/eDirectory_userip/Makefile src/acl/external/file_userip/Makefile src/acl/external/kerberos_ldap_group/Makefile src/acl/external/LDAP_group/Makefile src/acl/external/LM_group/Makefile src/acl/external/session/Makefile src/acl/external/SQL_session/Makefile src/acl/external/unix_group/Makefile src/acl/external/wbinfo_group/Makefile src/acl/external/time_quota/Makefile src/adaptation/Makefile src/adaptation/icap/Makefile src/adaptation/ecap/Makefile src/anyp/Makefile src/auth/Makefile src/auth/basic/Makefile src/auth/basic/DB/Makefile src/auth/basic/fake/Makefile src/auth/basic/getpwnam/Makefile src/auth/basic/LDAP/Makefile src/auth/basic/NCSA/Makefile src/auth/basic/NIS/Makefile src/auth/basic/PAM/Makefile src/auth/basic/POP3/Makefile src/auth/basic/RADIUS/Makefile src/auth/basic/SASL/Makefile src/auth/basic/SMB/Makefile src/auth/basic/SMB_LM/Makefile src/auth/basic/SSPI/Makefile src/auth/digest/Makefile src/auth/digest/eDirectory/Makefile src/auth/digest/file/Makefile src/auth/digest/LDAP/Makefile src/auth/negotiate/Makefile src/auth/negotiate/kerberos/Makefile src/auth/negotiate/SSPI/Makefile src/auth/negotiate/wrapper/Makefile src/auth/ntlm/Makefile src/auth/ntlm/fake/Makefile src/auth/ntlm/SMB_LM/Makefile src/auth/ntlm/SSPI/Makefile src/base/Makefile src/clients/Makefile src/comm/Makefile src/dns/Makefile src/DiskIO/Makefile src/DiskIO/AIO/Makefile src/DiskIO/Blocking/Makefile src/DiskIO/DiskDaemon/Makefile src/DiskIO/DiskThreads/Makefile src/DiskIO/IpcIo/Makefile src/DiskIO/Mmapped/Makefile src/esi/Makefile src/eui/Makefile src/format/Makefile src/fs/Makefile src/ftp/Makefile src/helper/Makefile src/http/Makefile src/http/one/Makefile src/http/url_rewriters/Makefile src/http/url_rewriters/fake/Makefile src/http/url_rewriters/LFS/Makefile src/icmp/Makefile src/ident/Makefile src/ip/Makefile src/ipc/Makefile src/log/Makefile src/log/DB/Makefile src/log/file/Makefile src/mem/Makefile src/mgr/Makefile src/parser/Makefile src/repl/Makefile src/sbuf/Makefile src/security/Makefile src/security/cert_generators/Makefile src/security/cert_generators/file/Makefile src/security/cert_validators/Makefile src/security/cert_validators/fake/Makefile src/servers/Makefile src/snmp/Makefile src/ssl/Makefile src/store/Makefile src/store/id_rewriters/Makefile src/store/id_rewriters/file/Makefile test-suite/Makefile tools/Makefile tools/helper-mux/Makefile tools/purge/Makefile tools/squidclient/Makefile tools/systemd/Makefile tools/sysvinit/Makefile"
 
 
 # must configure libltdl subdir unconditionally for "make distcheck" to work
@@ -42470,7 +42473,7 @@
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by Squid Web Proxy $as_me 4.0.7, which was
+This file was extended by Squid Web Proxy $as_me 4.0.8, which was
 generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -42536,7 +42539,7 @@
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-Squid Web Proxy config.status 4.0.7
+Squid Web Proxy config.status 4.0.8
 configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 
@@ -43145,6 +43148,7 @@
     "src/mgr/Makefile") CONFIG_FILES="$CONFIG_FILES src/mgr/Makefile" ;;
     "src/parser/Makefile") CONFIG_FILES="$CONFIG_FILES src/parser/Makefile" ;;
     "src/repl/Makefile") CONFIG_FILES="$CONFIG_FILES src/repl/Makefile" ;;
+    "src/sbuf/Makefile") CONFIG_FILES="$CONFIG_FILES src/sbuf/Makefile" ;;
     "src/security/Makefile") CONFIG_FILES="$CONFIG_FILES src/security/Makefile" ;;
     "src/security/cert_generators/Makefile") CONFIG_FILES="$CONFIG_FILES src/security/cert_generators/Makefile" ;;
     "src/security/cert_generators/file/Makefile") CONFIG_FILES="$CONFIG_FILES src/security/cert_generators/file/Makefile" ;;
diff -u -r -N squid-4.0.7/configure.ac squid-4.0.8/configure.ac
--- squid-4.0.7/configure.ac	2016-02-24 06:49:58.000000000 +1300
+++ squid-4.0.8/configure.ac	2016-04-02 10:08:38.000000000 +1300
@@ -5,7 +5,7 @@
 ## Please see the COPYING and CONTRIBUTORS files for details.
 ##
 
-AC_INIT([Squid Web Proxy],[4.0.7],[http://bugs.squid-cache.org/],[squid])
+AC_INIT([Squid Web Proxy],[4.0.8],[http://bugs.squid-cache.org/],[squid])
 AC_PREREQ(2.61)
 AC_CONFIG_HEADERS([include/autoconf.h])
 AC_CONFIG_AUX_DIR(cfgaux)
@@ -345,7 +345,7 @@
     SQUID_CFLAGS="$squid_cv_cc_option_wall -Wpointer-arith -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wcomments -Wshadow"
     ;;
   esac
-  SQUID_CXXFLAGS="$squid_cv_cc_option_wall -Wpointer-arith -Wwrite-strings -Wcomments -Wshadow"
+  SQUID_CXXFLAGS="$squid_cv_cc_option_wall -Wpointer-arith -Wwrite-strings -Wcomments -Wshadow -Woverloaded-virtual"
 else
   SQUID_CFLAGS=
   SQUID_CXXFLAGS=
@@ -788,15 +788,18 @@
       fi
       ;;
     rock)
-	if test "x$squid_disk_module_candidates_IpcIo" != "xyes" -a \
-	  "x$squid_disk_module_candidates_Blocking" != "xyes"; then
-	  AC_MSG_ERROR([Storage module Rock requires IpcIo or Blocking DiskIO module])
-	fi
-	squid_do_build_rock=true
-	;;
+      if test "x$squid_disk_module_candidates_IpcIo" != "xyes" -a \
+        "x$squid_disk_module_candidates_Blocking" != "xyes"; then
+         AC_MSG_ERROR([Storage module Rock requires DiskIO module: Blocking or IpcIo])
+      fi
+      squid_do_build_rock=true
+      ;;
     ufs)
-	squid_do_build_ufs=true
-	;;
+      if test "x$squid_disk_module_candidates_Blocking" != "xyes"; then
+        AC_MSG_ERROR([Storage module ufs requires DiskIO module: Blocking])
+      fi
+      squid_do_build_ufs=true
+      ;;
     esac
 done
 
@@ -1626,7 +1629,7 @@
     if test "x$ac_cv_path_krb5_config" != "xno" ; then
       krb5confpath="`dirname $ac_cv_path_krb5_config`"
       ac_heimdal="`$ac_cv_path_krb5_config --version 2>/dev/null | grep -c -i heimdal`"
-      if test "x$with_heimdal_krb5" = "xyes"; then
+      if test "x$with_heimdal_krb5" = "xyes" -a $ac_heimdal = 0; then
         AC_MSG_ERROR([Could not find pkg-config or krb5-config for Heimdal Kerberos])
       fi
     else
@@ -3881,6 +3884,7 @@
 	src/mgr/Makefile
 	src/parser/Makefile
 	src/repl/Makefile
+	src/sbuf/Makefile
 	src/security/Makefile
 	src/security/cert_generators/Makefile
 	src/security/cert_generators/file/Makefile
diff -u -r -N squid-4.0.7/doc/manuals/Substitute.am squid-4.0.8/doc/manuals/Substitute.am
--- squid-4.0.7/doc/manuals/Substitute.am	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/doc/manuals/Substitute.am	2016-04-02 10:04:07.000000000 +1300
@@ -11,6 +11,8 @@
 SUBSTITUTE=sed "\
 	s%@DEFAULT_ERROR_DIR@%$(DEFAULT_ERROR_DIR)%g;\
 	s%@DEFAULT_MIME_TABLE@%$(DEFAULT_MIME_TABLE)%g;\
+	s%@DEFAULT_SSL_CRTD@%$(DEFAULT_SSL_CRTD)%g;\
+	s%@DEFAULT_SSL_DB_DIR@%$(DEFAULT_SSL_DB_DIR)%g;\
 	s%@""PACKAGE_STRING""@%$(PACKAGE_STRING)%g;\
 	s%@SYSCONFDIR@%$(sysconfdir)%g;\
 	"
diff -u -r -N squid-4.0.7/doc/release-notes/release-4.html squid-4.0.8/doc/release-notes/release-4.html
--- squid-4.0.7/doc/release-notes/release-4.html	2016-02-24 07:38:32.000000000 +1300
+++ squid-4.0.8/doc/release-notes/release-4.html	2016-04-02 11:47:00.000000000 +1300
@@ -2,10 +2,10 @@
 <HTML>
 <HEAD>
  <META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.71">
- <TITLE>Squid 4.0.7 release notes</TITLE>
+ <TITLE>Squid 4.0.8 release notes</TITLE>
 </HEAD>
 <BODY>
-<H1>Squid 4.0.7 release notes</H1>
+<H1>Squid 4.0.8 release notes</H1>
 
 <H2>Squid Developers</H2>
 <HR>
@@ -30,6 +30,7 @@
 <LI><A NAME="toc2.4">2.4</A> <A HREF="#ss2.4">Helper Binary Changes</A>
 <LI><A NAME="toc2.5">2.5</A> <A HREF="#ss2.5">Secure ICAP</A>
 <LI><A NAME="toc2.6">2.6</A> <A HREF="#ss2.6">Improved SMP support</A>
+<LI><A NAME="toc2.7">2.7</A> <A HREF="#ss2.7">Improved process management</A>
 </UL>
 <P>
 <H2><A NAME="toc3">3.</A> <A HREF="#s3">Changes to squid.conf since Squid-3.5</A></H2>
@@ -60,7 +61,7 @@
 <HR>
 <H2><A NAME="s1">1.</A> <A HREF="#toc1">Notice</A></H2>
 
-<P>The Squid Team are pleased to announce the release of Squid-4.0.7 for testing.</P>
+<P>The Squid Team are pleased to announce the release of Squid-4.0.8 for testing.</P>
 <P>This new release is available for download from 
 <A HREF="http://www.squid-cache.org/Versions/v4/">http://www.squid-cache.org/Versions/v4/</A> or the
 <A HREF="http://www.squid-cache.org/Download/http-mirrors.html">mirrors</A>.</P>
@@ -101,6 +102,7 @@
 <LI>Helper Binary Changes</LI>
 <LI>Secure ICAP</LI>
 <LI>Improved SMP support</LI>
+<LI>Improved process management</LI>
 </UL>
 </P>
 <P>Most user-facing changes are reflected in squid.conf (see below).</P>
@@ -215,6 +217,29 @@
 enables Rock storage on more systems by default than previously.</P>
 
 
+<H2><A NAME="ss2.7">2.7</A> <A HREF="#toc2.7">Improved process management</A>
+</H2>
+
+<P>Squid is traditionally refered to as a daemon. But is actually a combination
+of daemon and daemon manager processes. This has caused significant problems
+integrating it with other third-party daemon managers.</P>
+
+<P>The Squid process which places its PID into the squid.pid file has always
+been the process to which control signals are sent. The manager process is
+now taking on signal handling instead of the main daemon process. Enabling
+integration with daemon managers such as Upstart or systemd which assume the
+process they initiated is the daemon with a PID to control.</P>
+
+<P>The squid binary now has a new <EM>--foreground</EM> command line option
+which prevents the process from exiting early while background workers
+continue their processing. When run with this option Squid will now wait
+for the worker(s) to finish before exiting. Unlike the old <EM>-N</EM> option
+<EM>--foreground</EM> supports SMP workers and multi-process features.
+<EM>--foreground</EM> is particularly useful for use with <EM>-z</EM> (disk
+cache structures creation), as it allows the caller to wait until Squid has
+finished.</P>
+
+
 <H2><A NAME="s3">3.</A> <A HREF="#toc3">Changes to squid.conf since Squid-3.5</A></H2>
 
 <P>There have been changes to Squid's configuration file since Squid-3.5.</P>
@@ -236,6 +261,25 @@
 
 <P>
 <DL>
+<DT><B>collapsed_forwarding_shared_entries_limit</B><DD>
+<P>New directive to limit the size of a table used for sharing information
+about collapsible entries among SMP workers.</P>
+
+<DT><B>reply_header_add</B><DD>
+<P>New directive to add header fields to outgoing HTTP responses to
+the client.</P>
+
+<DT><B>server_pconn_for_nonretriable</B><DD>
+<P>New directive to provide fine-grained control over persistent connection
+reuse when forwarding HTTP requests that Squid cannot retry. It is useful
+in environments where opening new connections is very expensive
+and race conditions associated with persistent connections are very rare
+and/or only cause minor problems.</P>
+
+<DT><B>shared_memory_locking</B><DD>
+<P>New directive to ensure shared memory is all available immediately
+on startup. Protects against SIGBUS errors, but delays startup.</P>
+
 <DT><B>tls_outgoing_options</B><DD>
 <P>New directive to define TLS security context options for outgoing
 connections. For example to HTTPS servers.</P>
diff -u -r -N squid-4.0.7/include/version.h squid-4.0.8/include/version.h
--- squid-4.0.7/include/version.h	2016-02-24 06:49:58.000000000 +1300
+++ squid-4.0.8/include/version.h	2016-04-02 10:08:39.000000000 +1300
@@ -7,7 +7,7 @@
  */
 
 #ifndef SQUID_RELEASE_TIME
-#define SQUID_RELEASE_TIME 1456249662
+#define SQUID_RELEASE_TIME 1459544634
 #endif
 
 /*
diff -u -r -N squid-4.0.7/lib/libTrie/Makefile.in squid-4.0.8/lib/libTrie/Makefile.in
--- squid-4.0.7/lib/libTrie/Makefile.in	2016-02-24 06:49:01.000000000 +1300
+++ squid-4.0.8/lib/libTrie/Makefile.in	2016-04-02 10:06:17.000000000 +1300
@@ -734,6 +734,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/lib/libTrie/test/Makefile.in squid-4.0.8/lib/libTrie/test/Makefile.in
--- squid-4.0.7/lib/libTrie/test/Makefile.in	2016-02-24 06:49:01.000000000 +1300
+++ squid-4.0.8/lib/libTrie/test/Makefile.in	2016-04-02 10:06:18.000000000 +1300
@@ -665,6 +665,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/lib/Makefile.in squid-4.0.8/lib/Makefile.in
--- squid-4.0.7/lib/Makefile.in	2016-02-24 06:49:00.000000000 +1300
+++ squid-4.0.8/lib/Makefile.in	2016-04-02 10:06:16.000000000 +1300
@@ -772,6 +772,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/lib/ntlmauth/Makefile.in squid-4.0.8/lib/ntlmauth/Makefile.in
--- squid-4.0.7/lib/ntlmauth/Makefile.in	2016-02-24 06:49:02.000000000 +1300
+++ squid-4.0.8/lib/ntlmauth/Makefile.in	2016-04-02 10:06:19.000000000 +1300
@@ -685,6 +685,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/lib/profiler/Makefile.in squid-4.0.8/lib/profiler/Makefile.in
--- squid-4.0.7/lib/profiler/Makefile.in	2016-02-24 06:49:02.000000000 +1300
+++ squid-4.0.8/lib/profiler/Makefile.in	2016-04-02 10:06:19.000000000 +1300
@@ -689,6 +689,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/lib/rfcnb/Makefile.in squid-4.0.8/lib/rfcnb/Makefile.in
--- squid-4.0.7/lib/rfcnb/Makefile.in	2016-02-24 06:49:03.000000000 +1300
+++ squid-4.0.8/lib/rfcnb/Makefile.in	2016-04-02 10:06:20.000000000 +1300
@@ -665,6 +665,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/lib/smblib/Makefile.in squid-4.0.8/lib/smblib/Makefile.in
--- squid-4.0.7/lib/smblib/Makefile.in	2016-02-24 06:49:03.000000000 +1300
+++ squid-4.0.8/lib/smblib/Makefile.in	2016-04-02 10:06:21.000000000 +1300
@@ -666,6 +666,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/RELEASENOTES.html squid-4.0.8/RELEASENOTES.html
--- squid-4.0.7/RELEASENOTES.html	2016-02-24 07:38:32.000000000 +1300
+++ squid-4.0.8/RELEASENOTES.html	2016-04-02 11:47:00.000000000 +1300
@@ -2,10 +2,10 @@
 <HTML>
 <HEAD>
  <META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.71">
- <TITLE>Squid 4.0.7 release notes</TITLE>
+ <TITLE>Squid 4.0.8 release notes</TITLE>
 </HEAD>
 <BODY>
-<H1>Squid 4.0.7 release notes</H1>
+<H1>Squid 4.0.8 release notes</H1>
 
 <H2>Squid Developers</H2>
 <HR>
@@ -30,6 +30,7 @@
 <LI><A NAME="toc2.4">2.4</A> <A HREF="#ss2.4">Helper Binary Changes</A>
 <LI><A NAME="toc2.5">2.5</A> <A HREF="#ss2.5">Secure ICAP</A>
 <LI><A NAME="toc2.6">2.6</A> <A HREF="#ss2.6">Improved SMP support</A>
+<LI><A NAME="toc2.7">2.7</A> <A HREF="#ss2.7">Improved process management</A>
 </UL>
 <P>
 <H2><A NAME="toc3">3.</A> <A HREF="#s3">Changes to squid.conf since Squid-3.5</A></H2>
@@ -60,7 +61,7 @@
 <HR>
 <H2><A NAME="s1">1.</A> <A HREF="#toc1">Notice</A></H2>
 
-<P>The Squid Team are pleased to announce the release of Squid-4.0.7 for testing.</P>
+<P>The Squid Team are pleased to announce the release of Squid-4.0.8 for testing.</P>
 <P>This new release is available for download from 
 <A HREF="http://www.squid-cache.org/Versions/v4/">http://www.squid-cache.org/Versions/v4/</A> or the
 <A HREF="http://www.squid-cache.org/Download/http-mirrors.html">mirrors</A>.</P>
@@ -101,6 +102,7 @@
 <LI>Helper Binary Changes</LI>
 <LI>Secure ICAP</LI>
 <LI>Improved SMP support</LI>
+<LI>Improved process management</LI>
 </UL>
 </P>
 <P>Most user-facing changes are reflected in squid.conf (see below).</P>
@@ -215,6 +217,29 @@
 enables Rock storage on more systems by default than previously.</P>
 
 
+<H2><A NAME="ss2.7">2.7</A> <A HREF="#toc2.7">Improved process management</A>
+</H2>
+
+<P>Squid is traditionally refered to as a daemon. But is actually a combination
+of daemon and daemon manager processes. This has caused significant problems
+integrating it with other third-party daemon managers.</P>
+
+<P>The Squid process which places its PID into the squid.pid file has always
+been the process to which control signals are sent. The manager process is
+now taking on signal handling instead of the main daemon process. Enabling
+integration with daemon managers such as Upstart or systemd which assume the
+process they initiated is the daemon with a PID to control.</P>
+
+<P>The squid binary now has a new <EM>--foreground</EM> command line option
+which prevents the process from exiting early while background workers
+continue their processing. When run with this option Squid will now wait
+for the worker(s) to finish before exiting. Unlike the old <EM>-N</EM> option
+<EM>--foreground</EM> supports SMP workers and multi-process features.
+<EM>--foreground</EM> is particularly useful for use with <EM>-z</EM> (disk
+cache structures creation), as it allows the caller to wait until Squid has
+finished.</P>
+
+
 <H2><A NAME="s3">3.</A> <A HREF="#toc3">Changes to squid.conf since Squid-3.5</A></H2>
 
 <P>There have been changes to Squid's configuration file since Squid-3.5.</P>
@@ -236,6 +261,25 @@
 
 <P>
 <DL>
+<DT><B>collapsed_forwarding_shared_entries_limit</B><DD>
+<P>New directive to limit the size of a table used for sharing information
+about collapsible entries among SMP workers.</P>
+
+<DT><B>reply_header_add</B><DD>
+<P>New directive to add header fields to outgoing HTTP responses to
+the client.</P>
+
+<DT><B>server_pconn_for_nonretriable</B><DD>
+<P>New directive to provide fine-grained control over persistent connection
+reuse when forwarding HTTP requests that Squid cannot retry. It is useful
+in environments where opening new connections is very expensive
+and race conditions associated with persistent connections are very rare
+and/or only cause minor problems.</P>
+
+<DT><B>shared_memory_locking</B><DD>
+<P>New directive to ensure shared memory is all available immediately
+on startup. Protects against SIGBUS errors, but delays startup.</P>
+
 <DT><B>tls_outgoing_options</B><DD>
 <P>New directive to define TLS security context options for outgoing
 connections. For example to HTTPS servers.</P>
diff -u -r -N squid-4.0.7/SPONSORS squid-4.0.8/SPONSORS
--- squid-4.0.7/SPONSORS	2016-02-24 06:49:57.000000000 +1300
+++ squid-4.0.8/SPONSORS	2016-04-02 10:08:35.000000000 +1300
@@ -7,6 +7,11 @@
 	Augur TBBS has funded development work towards HTTP/2 support in
 	Squid-4.
 
+Bloomberg L.P.
+
+	Bloomberg L.P. has funded development work towards stabilizing
+	Squid-4.
+
 LaunchPad - http://launchpad.net/
 
 	Provide Bazaar mirroring services and host the Squid-3+ developer
diff -u -r -N squid-4.0.7/src/AccessLogEntry.cc squid-4.0.8/src/AccessLogEntry.cc
--- squid-4.0.7/src/AccessLogEntry.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/AccessLogEntry.cc	2016-04-02 10:04:07.000000000 +1300
@@ -76,7 +76,6 @@
     HTTPMSGUNLOCK(adapted_request);
 
     safe_free(lastAclName);
-    safe_free(lastAclData);
 
     HTTPMSGUNLOCK(reply);
     HTTPMSGUNLOCK(request);
diff -u -r -N squid-4.0.7/src/AccessLogEntry.h squid-4.0.8/src/AccessLogEntry.h
--- squid-4.0.7/src/AccessLogEntry.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/AccessLogEntry.h	2016-04-02 10:04:07.000000000 +1300
@@ -21,6 +21,7 @@
 #include "LogTags.h"
 #include "MessageSizes.h"
 #include "Notes.h"
+#include "sbuf/SBuf.h"
 #if ICAP_CLIENT
 #include "adaptation/icap/Elements.h"
 #endif
@@ -42,7 +43,6 @@
     AccessLogEntry() :
         url(nullptr),
         lastAclName(nullptr),
-        lastAclData(nullptr),
         reply(nullptr),
         request(nullptr),
         adapted_request(nullptr)
@@ -57,7 +57,7 @@
     /// Fetch the transaction method string (ICP opcode, HTCP opcode or HTTP method)
     SBuf getLogMethod() const;
 
-    const char *url;
+    SBuf url;
 
     /// TCP/IP level details about the client connection
     Comm::ConnectionPointer tcpClient;
@@ -207,7 +207,7 @@
 #endif
 
     const char *lastAclName; ///< string for external_acl_type %ACL format code
-    const char *lastAclData; ///< string for external_acl_type %DATA format code
+    SBuf lastAclData; ///< string for external_acl_type %DATA format code
 
     HierarchyLogEntry hier;
     HttpReply *reply;
diff -u -r -N squid-4.0.7/src/acl/Acl.h squid-4.0.8/src/acl/Acl.h
--- squid-4.0.7/src/acl/Acl.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/acl/Acl.h	2016-04-02 10:04:07.000000000 +1300
@@ -14,7 +14,7 @@
 #include "cbdata.h"
 #include "defines.h"
 #include "dlink.h"
-#include "SBufList.h"
+#include "sbuf/List.h"
 
 #include <map>
 #include <ostream>
diff -u -r -N squid-4.0.7/src/acl/Data.h squid-4.0.8/src/acl/Data.h
--- squid-4.0.7/src/acl/Data.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/acl/Data.h	2016-04-02 10:04:07.000000000 +1300
@@ -9,7 +9,7 @@
 #ifndef SQUID_ACLDATA_H
 #define SQUID_ACLDATA_H
 
-#include "SBufList.h"
+#include "sbuf/List.h"
 
 /// \ingroup ACLAPI
 template <class M>
diff -u -r -N squid-4.0.7/src/acl/external/AD_group/Makefile.in squid-4.0.8/src/acl/external/AD_group/Makefile.in
--- squid-4.0.7/src/acl/external/AD_group/Makefile.in	2016-02-24 06:49:10.000000000 +1300
+++ squid-4.0.8/src/acl/external/AD_group/Makefile.in	2016-04-02 10:06:37.000000000 +1300
@@ -675,6 +675,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/acl/external/delayer/ext_delayer_acl.8 squid-4.0.8/src/acl/external/delayer/ext_delayer_acl.8
--- squid-4.0.7/src/acl/external/delayer/ext_delayer_acl.8	2016-02-24 07:39:12.000000000 +1300
+++ squid-4.0.8/src/acl/external/delayer/ext_delayer_acl.8	2016-04-02 11:48:10.000000000 +1300
@@ -133,7 +133,7 @@
 .\" ========================================================================
 .\"
 .IX Title "EXT_DELAYER_ACL 8"
-.TH EXT_DELAYER_ACL 8 "2016-02-23" "perl v5.22.1" "User Contributed Perl Documentation"
+.TH EXT_DELAYER_ACL 8 "2016-04-01" "perl v5.22.1" "User Contributed Perl Documentation"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
diff -u -r -N squid-4.0.7/src/acl/external/delayer/Makefile.in squid-4.0.8/src/acl/external/delayer/Makefile.in
--- squid-4.0.7/src/acl/external/delayer/Makefile.in	2016-02-24 06:49:12.000000000 +1300
+++ squid-4.0.8/src/acl/external/delayer/Makefile.in	2016-04-02 10:06:41.000000000 +1300
@@ -624,6 +624,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = ext_delayer_acl $(am__append_2)
diff -u -r -N squid-4.0.7/src/acl/external/eDirectory_userip/Makefile.in squid-4.0.8/src/acl/external/eDirectory_userip/Makefile.in
--- squid-4.0.7/src/acl/external/eDirectory_userip/Makefile.in	2016-02-24 06:49:12.000000000 +1300
+++ squid-4.0.8/src/acl/external/eDirectory_userip/Makefile.in	2016-04-02 10:06:42.000000000 +1300
@@ -678,6 +678,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/acl/external/file_userip/Makefile.in squid-4.0.8/src/acl/external/file_userip/Makefile.in
--- squid-4.0.7/src/acl/external/file_userip/Makefile.in	2016-02-24 06:49:13.000000000 +1300
+++ squid-4.0.8/src/acl/external/file_userip/Makefile.in	2016-04-02 10:06:43.000000000 +1300
@@ -676,6 +676,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/acl/external/kerberos_ldap_group/Makefile.in squid-4.0.8/src/acl/external/kerberos_ldap_group/Makefile.in
--- squid-4.0.7/src/acl/external/kerberos_ldap_group/Makefile.in	2016-02-24 06:49:13.000000000 +1300
+++ squid-4.0.8/src/acl/external/kerberos_ldap_group/Makefile.in	2016-04-02 10:06:44.000000000 +1300
@@ -706,6 +706,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/acl/external/LDAP_group/Makefile.in squid-4.0.8/src/acl/external/LDAP_group/Makefile.in
--- squid-4.0.7/src/acl/external/LDAP_group/Makefile.in	2016-02-24 06:49:10.000000000 +1300
+++ squid-4.0.8/src/acl/external/LDAP_group/Makefile.in	2016-04-02 10:06:38.000000000 +1300
@@ -678,6 +678,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/acl/external/LM_group/Makefile.in squid-4.0.8/src/acl/external/LM_group/Makefile.in
--- squid-4.0.7/src/acl/external/LM_group/Makefile.in	2016-02-24 06:49:11.000000000 +1300
+++ squid-4.0.8/src/acl/external/LM_group/Makefile.in	2016-04-02 10:06:39.000000000 +1300
@@ -676,6 +676,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/acl/external/session/Makefile.in squid-4.0.8/src/acl/external/session/Makefile.in
--- squid-4.0.7/src/acl/external/session/Makefile.in	2016-02-24 06:49:13.000000000 +1300
+++ squid-4.0.8/src/acl/external/session/Makefile.in	2016-04-02 10:06:46.000000000 +1300
@@ -675,6 +675,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/acl/external/SQL_session/ext_sql_session_acl.8 squid-4.0.8/src/acl/external/SQL_session/ext_sql_session_acl.8
--- squid-4.0.7/src/acl/external/SQL_session/ext_sql_session_acl.8	2016-02-24 07:39:20.000000000 +1300
+++ squid-4.0.8/src/acl/external/SQL_session/ext_sql_session_acl.8	2016-04-02 11:48:18.000000000 +1300
@@ -133,7 +133,7 @@
 .\" ========================================================================
 .\"
 .IX Title "EXT_SQL_SESSION_ACL 8"
-.TH EXT_SQL_SESSION_ACL 8 "2016-02-23" "perl v5.22.1" "User Contributed Perl Documentation"
+.TH EXT_SQL_SESSION_ACL 8 "2016-04-01" "perl v5.22.1" "User Contributed Perl Documentation"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
diff -u -r -N squid-4.0.7/src/acl/external/SQL_session/Makefile.in squid-4.0.8/src/acl/external/SQL_session/Makefile.in
--- squid-4.0.7/src/acl/external/SQL_session/Makefile.in	2016-02-24 06:49:11.000000000 +1300
+++ squid-4.0.8/src/acl/external/SQL_session/Makefile.in	2016-04-02 10:06:41.000000000 +1300
@@ -624,6 +624,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = ext_sql_session_acl $(am__append_2)
diff -u -r -N squid-4.0.7/src/acl/external/time_quota/Makefile.in squid-4.0.8/src/acl/external/time_quota/Makefile.in
--- squid-4.0.7/src/acl/external/time_quota/Makefile.in	2016-02-24 06:49:14.000000000 +1300
+++ squid-4.0.8/src/acl/external/time_quota/Makefile.in	2016-04-02 10:06:47.000000000 +1300
@@ -676,6 +676,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/acl/external/unix_group/Makefile.in squid-4.0.8/src/acl/external/unix_group/Makefile.in
--- squid-4.0.7/src/acl/external/unix_group/Makefile.in	2016-02-24 06:49:14.000000000 +1300
+++ squid-4.0.8/src/acl/external/unix_group/Makefile.in	2016-04-02 10:06:48.000000000 +1300
@@ -676,6 +676,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/acl/external/wbinfo_group/ext_wbinfo_group_acl.8 squid-4.0.8/src/acl/external/wbinfo_group/ext_wbinfo_group_acl.8
--- squid-4.0.7/src/acl/external/wbinfo_group/ext_wbinfo_group_acl.8	2016-02-24 07:39:24.000000000 +1300
+++ squid-4.0.8/src/acl/external/wbinfo_group/ext_wbinfo_group_acl.8	2016-04-02 11:48:22.000000000 +1300
@@ -133,7 +133,7 @@
 .\" ========================================================================
 .\"
 .IX Title "EXT_WBINFO_GROUP_ACL 8"
-.TH EXT_WBINFO_GROUP_ACL 8 "2016-02-23" "perl v5.22.1" "User Contributed Perl Documentation"
+.TH EXT_WBINFO_GROUP_ACL 8 "2016-04-01" "perl v5.22.1" "User Contributed Perl Documentation"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
diff -u -r -N squid-4.0.7/src/acl/external/wbinfo_group/Makefile.in squid-4.0.8/src/acl/external/wbinfo_group/Makefile.in
--- squid-4.0.7/src/acl/external/wbinfo_group/Makefile.in	2016-02-24 06:49:15.000000000 +1300
+++ squid-4.0.8/src/acl/external/wbinfo_group/Makefile.in	2016-04-02 10:06:48.000000000 +1300
@@ -624,6 +624,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = ext_wbinfo_group_acl $(am__append_2)
diff -u -r -N squid-4.0.7/src/acl/FilledChecklist.cc squid-4.0.8/src/acl/FilledChecklist.cc
--- squid-4.0.7/src/acl/FilledChecklist.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/acl/FilledChecklist.cc	2016-04-02 10:04:07.000000000 +1300
@@ -103,9 +103,9 @@
             HTTPMSGLOCK(al->adapted_request);
         }
 
-        if (!al->url) {
+        if (al->url.isEmpty()) {
             showDebugWarning("URL");
-            al->url = xstrdup(request->url.absolute().c_str());
+            al->url = request->url.absolute();
         }
     }
 
diff -u -r -N squid-4.0.7/src/acl/HttpHeaderData.cc squid-4.0.8/src/acl/HttpHeaderData.cc
--- squid-4.0.7/src/acl/HttpHeaderData.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/acl/HttpHeaderData.cc	2016-04-02 10:04:07.000000000 +1300
@@ -17,7 +17,8 @@
 #include "ConfigParser.h"
 #include "Debug.h"
 #include "HttpHeaderTools.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
+#include "sbuf/StringConvert.h"
 
 /* Construct an ACLHTTPHeaderData that uses an ACLRegex rule with the value of the
  * selected header from a given request.
@@ -51,7 +52,7 @@
             return false;
     }
 
-    SBuf cvalue(value);
+    auto cvalue = StringToSBuf(value);
     return regex_rule->match(cvalue.c_str());
 }
 
diff -u -r -N squid-4.0.7/src/acl/HttpHeaderData.h squid-4.0.8/src/acl/HttpHeaderData.h
--- squid-4.0.7/src/acl/HttpHeaderData.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/acl/HttpHeaderData.h	2016-04-02 10:04:07.000000000 +1300
@@ -11,7 +11,7 @@
 
 #include "acl/Data.h"
 #include "HttpHeader.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "SquidString.h"
 
 class ACLHTTPHeaderData : public ACLData<HttpHeader*>
diff -u -r -N squid-4.0.7/src/acl/Makefile.in squid-4.0.8/src/acl/Makefile.in
--- squid-4.0.7/src/acl/Makefile.in	2016-02-24 06:49:09.000000000 +1300
+++ squid-4.0.8/src/acl/Makefile.in	2016-04-02 10:06:36.000000000 +1300
@@ -790,6 +790,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/acl/Note.cc squid-4.0.8/src/acl/Note.cc
--- squid-4.0.7/src/acl/Note.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/acl/Note.cc	2016-04-02 10:04:07.000000000 +1300
@@ -14,6 +14,7 @@
 #include "HttpRequest.h"
 #include "Notes.h"
 #include "parser/Tokenizer.h"
+#include "sbuf/StringConvert.h"
 
 int
 ACLNoteStrategy::match(ACLData<MatchType> * &data, ACLFilledChecklist *checklist, ACLFlags &flags)
@@ -36,7 +37,7 @@
     for (auto &entry: note->entries) {
         if (delimiters) {
             NotePairs::Entry e(entry->name.termedBuf(), "");
-            Parser::Tokenizer t(SBuf(entry->value));
+            Parser::Tokenizer t(StringToSBuf(entry->value));
             SBuf s;
             while (t.token(s, *delimiters)) {
                 e.value = s.c_str();
diff -u -r -N squid-4.0.7/src/acl/NoteData.cc squid-4.0.8/src/acl/NoteData.cc
--- squid-4.0.7/src/acl/NoteData.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/acl/NoteData.cc	2016-04-02 10:04:07.000000000 +1300
@@ -13,6 +13,7 @@
 #include "acl/StringData.h"
 #include "ConfigParser.h"
 #include "Debug.h"
+#include "sbuf/StringConvert.h"
 #include "wordlist.h"
 
 ACLNoteData::ACLNoteData() : values(new ACLStringData)
@@ -38,7 +39,7 @@
 ACLNoteData::dump() const
 {
     SBufList sl;
-    sl.push_back(SBuf(name));
+    sl.push_back(StringToSBuf(name));
 #if __cplusplus >= 201103L
     sl.splice(sl.end(), values->dump());
 #else
diff -u -r -N squid-4.0.7/src/acl/StringData.h squid-4.0.8/src/acl/StringData.h
--- squid-4.0.7/src/acl/StringData.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/acl/StringData.h	2016-04-02 10:04:07.000000000 +1300
@@ -11,7 +11,7 @@
 
 #include "acl/Acl.h"
 #include "acl/Data.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 #include <set>
 
diff -u -r -N squid-4.0.7/src/acl/Tree.h squid-4.0.8/src/acl/Tree.h
--- squid-4.0.7/src/acl/Tree.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/acl/Tree.h	2016-04-02 10:04:07.000000000 +1300
@@ -10,7 +10,7 @@
 #define SQUID_ACL_TREE_H
 
 #include "acl/BoolOps.h"
-#include "SBufList.h"
+#include "sbuf/List.h"
 
 namespace Acl
 {
diff -u -r -N squid-4.0.7/src/acl/UserData.cc squid-4.0.8/src/acl/UserData.cc
--- squid-4.0.7/src/acl/UserData.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/acl/UserData.cc	2016-04-02 10:04:07.000000000 +1300
@@ -14,7 +14,7 @@
 #include "ConfigParser.h"
 #include "Debug.h"
 #include "globals.h"
-#include "SBufAlgos.h"
+#include "sbuf/Algorithms.h"
 #include "util.h"
 
 bool
diff -u -r -N squid-4.0.7/src/acl/UserData.h squid-4.0.8/src/acl/UserData.h
--- squid-4.0.7/src/acl/UserData.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/acl/UserData.h	2016-04-02 10:04:07.000000000 +1300
@@ -11,7 +11,7 @@
 
 #include "acl/Acl.h"
 #include "acl/Data.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 #include <set>
 
diff -u -r -N squid-4.0.7/src/adaptation/ecap/Makefile.in squid-4.0.8/src/adaptation/ecap/Makefile.in
--- squid-4.0.7/src/adaptation/ecap/Makefile.in	2016-02-24 06:49:16.000000000 +1300
+++ squid-4.0.8/src/adaptation/ecap/Makefile.in	2016-04-02 10:06:51.000000000 +1300
@@ -692,6 +692,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/adaptation/History.h squid-4.0.8/src/adaptation/History.h
--- squid-4.0.7/src/adaptation/History.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/adaptation/History.h	2016-04-02 10:04:07.000000000 +1300
@@ -13,7 +13,7 @@
 #include "base/RefCount.h"
 #include "HttpHeader.h"
 #include "Notes.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "SquidString.h"
 
 namespace Adaptation
diff -u -r -N squid-4.0.7/src/adaptation/icap/Makefile.in squid-4.0.8/src/adaptation/icap/Makefile.in
--- squid-4.0.7/src/adaptation/icap/Makefile.in	2016-02-24 06:49:16.000000000 +1300
+++ squid-4.0.8/src/adaptation/icap/Makefile.in	2016-04-02 10:06:52.000000000 +1300
@@ -687,6 +687,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/adaptation/icap/Xaction.h squid-4.0.8/src/adaptation/icap/Xaction.h
--- squid-4.0.7/src/adaptation/icap/Xaction.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/adaptation/icap/Xaction.h	2016-04-02 10:04:07.000000000 +1300
@@ -15,7 +15,7 @@
 #include "comm/ConnOpener.h"
 #include "HttpReply.h"
 #include "ipcache.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #if USE_OPENSSL
 #include "ssl/PeerConnector.h"
 #endif
diff -u -r -N squid-4.0.7/src/adaptation/Iterator.cc squid-4.0.8/src/adaptation/Iterator.cc
--- squid-4.0.7/src/adaptation/Iterator.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/adaptation/Iterator.cc	2016-04-02 10:04:07.000000000 +1300
@@ -19,6 +19,7 @@
 #include "HttpMsg.h"
 #include "HttpReply.h"
 #include "HttpRequest.h"
+#include "sbuf/StringConvert.h"
 
 Adaptation::Iterator::Iterator(
     HttpMsg *aMsg, HttpRequest *aCause,
@@ -62,7 +63,7 @@
             request = theCause;
         Must(request);
         Adaptation::History::Pointer ah = request->adaptHistory(true);
-        SBuf gid(theGroup->id);
+        auto gid = StringToSBuf(theGroup->id);
         ah->recordAdaptationService(gid);
     }
 
@@ -102,7 +103,7 @@
 
     if (Adaptation::Config::needHistory) {
         Adaptation::History::Pointer ah = request->adaptHistory(true);
-        SBuf uid(thePlan.current()->cfg().key);
+        auto uid = StringToSBuf(thePlan.current()->cfg().key);
         ah->recordAdaptationService(uid);
     }
 
diff -u -r -N squid-4.0.7/src/adaptation/Makefile.in squid-4.0.8/src/adaptation/Makefile.in
--- squid-4.0.7/src/adaptation/Makefile.in	2016-02-24 06:49:15.000000000 +1300
+++ squid-4.0.8/src/adaptation/Makefile.in	2016-04-02 10:06:50.000000000 +1300
@@ -731,6 +731,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/anyp/Makefile.in squid-4.0.8/src/anyp/Makefile.in
--- squid-4.0.7/src/anyp/Makefile.in	2016-02-24 06:49:17.000000000 +1300
+++ squid-4.0.8/src/anyp/Makefile.in	2016-04-02 10:06:53.000000000 +1300
@@ -685,6 +685,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders ProtocolType.cc
diff -u -r -N squid-4.0.7/src/anyp/PortCfg.h squid-4.0.8/src/anyp/PortCfg.h
--- squid-4.0.7/src/anyp/PortCfg.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/anyp/PortCfg.h	2016-04-02 10:04:07.000000000 +1300
@@ -13,7 +13,7 @@
 #include "anyp/ProtocolVersion.h"
 #include "anyp/TrafficMode.h"
 #include "comm/Connection.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "security/ServerOptions.h"
 
 #if USE_OPENSSL
diff -u -r -N squid-4.0.7/src/auth/basic/DB/basic_db_auth.8 squid-4.0.8/src/auth/basic/DB/basic_db_auth.8
--- squid-4.0.7/src/auth/basic/DB/basic_db_auth.8	2016-02-24 07:39:46.000000000 +1300
+++ squid-4.0.8/src/auth/basic/DB/basic_db_auth.8	2016-04-02 11:48:45.000000000 +1300
@@ -133,7 +133,7 @@
 .\" ========================================================================
 .\"
 .IX Title "BASIC_DB_AUTH 8"
-.TH BASIC_DB_AUTH 8 "2016-02-23" "perl v5.22.1" "User Contributed Perl Documentation"
+.TH BASIC_DB_AUTH 8 "2016-04-01" "perl v5.22.1" "User Contributed Perl Documentation"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
diff -u -r -N squid-4.0.7/src/auth/basic/DB/Makefile.in squid-4.0.8/src/auth/basic/DB/Makefile.in
--- squid-4.0.7/src/auth/basic/DB/Makefile.in	2016-02-24 06:49:18.000000000 +1300
+++ squid-4.0.8/src/auth/basic/DB/Makefile.in	2016-04-02 10:06:55.000000000 +1300
@@ -624,6 +624,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = basic_db_auth $(am__append_2)
diff -u -r -N squid-4.0.7/src/auth/basic/fake/Makefile.in squid-4.0.8/src/auth/basic/fake/Makefile.in
--- squid-4.0.7/src/auth/basic/fake/Makefile.in	2016-02-24 06:49:23.000000000 +1300
+++ squid-4.0.8/src/auth/basic/fake/Makefile.in	2016-04-02 10:07:09.000000000 +1300
@@ -670,6 +670,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/basic/getpwnam/Makefile.in squid-4.0.8/src/auth/basic/getpwnam/Makefile.in
--- squid-4.0.7/src/auth/basic/getpwnam/Makefile.in	2016-02-24 06:49:23.000000000 +1300
+++ squid-4.0.8/src/auth/basic/getpwnam/Makefile.in	2016-04-02 10:07:10.000000000 +1300
@@ -676,6 +676,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/basic/LDAP/Makefile.in squid-4.0.8/src/auth/basic/LDAP/Makefile.in
--- squid-4.0.7/src/auth/basic/LDAP/Makefile.in	2016-02-24 06:49:18.000000000 +1300
+++ squid-4.0.8/src/auth/basic/LDAP/Makefile.in	2016-04-02 10:06:56.000000000 +1300
@@ -676,6 +676,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/basic/Makefile.in squid-4.0.8/src/auth/basic/Makefile.in
--- squid-4.0.7/src/auth/basic/Makefile.in	2016-02-24 06:49:19.000000000 +1300
+++ squid-4.0.8/src/auth/basic/Makefile.in	2016-04-02 10:06:57.000000000 +1300
@@ -725,6 +725,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/auth/basic/NCSA/Makefile.in squid-4.0.8/src/auth/basic/NCSA/Makefile.in
--- squid-4.0.7/src/auth/basic/NCSA/Makefile.in	2016-02-24 06:49:19.000000000 +1300
+++ squid-4.0.8/src/auth/basic/NCSA/Makefile.in	2016-04-02 10:06:58.000000000 +1300
@@ -697,6 +697,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/basic/NIS/Makefile.in squid-4.0.8/src/auth/basic/NIS/Makefile.in
--- squid-4.0.7/src/auth/basic/NIS/Makefile.in	2016-02-24 06:49:19.000000000 +1300
+++ squid-4.0.8/src/auth/basic/NIS/Makefile.in	2016-04-02 10:07:00.000000000 +1300
@@ -692,6 +692,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/basic/PAM/Makefile.in squid-4.0.8/src/auth/basic/PAM/Makefile.in
--- squid-4.0.7/src/auth/basic/PAM/Makefile.in	2016-02-24 06:49:20.000000000 +1300
+++ squid-4.0.8/src/auth/basic/PAM/Makefile.in	2016-04-02 10:07:01.000000000 +1300
@@ -675,6 +675,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/basic/POP3/basic_pop3_auth.8 squid-4.0.8/src/auth/basic/POP3/basic_pop3_auth.8
--- squid-4.0.7/src/auth/basic/POP3/basic_pop3_auth.8	2016-02-24 07:39:53.000000000 +1300
+++ squid-4.0.8/src/auth/basic/POP3/basic_pop3_auth.8	2016-04-02 11:48:52.000000000 +1300
@@ -133,7 +133,7 @@
 .\" ========================================================================
 .\"
 .IX Title "BASIC_POP3_AUTH 8"
-.TH BASIC_POP3_AUTH 8 "2016-02-23" "perl v5.22.1" "User Contributed Perl Documentation"
+.TH BASIC_POP3_AUTH 8 "2016-04-01" "perl v5.22.1" "User Contributed Perl Documentation"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
diff -u -r -N squid-4.0.7/src/auth/basic/POP3/Makefile.in squid-4.0.8/src/auth/basic/POP3/Makefile.in
--- squid-4.0.7/src/auth/basic/POP3/Makefile.in	2016-02-24 06:49:20.000000000 +1300
+++ squid-4.0.8/src/auth/basic/POP3/Makefile.in	2016-04-02 10:07:02.000000000 +1300
@@ -624,6 +624,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = basic_pop3_auth $(am__append_2)
diff -u -r -N squid-4.0.7/src/auth/basic/RADIUS/Makefile.in squid-4.0.8/src/auth/basic/RADIUS/Makefile.in
--- squid-4.0.7/src/auth/basic/RADIUS/Makefile.in	2016-02-24 06:49:21.000000000 +1300
+++ squid-4.0.8/src/auth/basic/RADIUS/Makefile.in	2016-04-02 10:07:03.000000000 +1300
@@ -697,6 +697,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/basic/SASL/Makefile.in squid-4.0.8/src/auth/basic/SASL/Makefile.in
--- squid-4.0.7/src/auth/basic/SASL/Makefile.in	2016-02-24 06:49:21.000000000 +1300
+++ squid-4.0.8/src/auth/basic/SASL/Makefile.in	2016-04-02 10:07:04.000000000 +1300
@@ -676,6 +676,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/basic/SMB/Makefile.in squid-4.0.8/src/auth/basic/SMB/Makefile.in
--- squid-4.0.7/src/auth/basic/SMB/Makefile.in	2016-02-24 06:49:22.000000000 +1300
+++ squid-4.0.8/src/auth/basic/SMB/Makefile.in	2016-04-02 10:07:05.000000000 +1300
@@ -680,6 +680,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/basic/SMB_LM/Makefile.in squid-4.0.8/src/auth/basic/SMB_LM/Makefile.in
--- squid-4.0.7/src/auth/basic/SMB_LM/Makefile.in	2016-02-24 06:49:22.000000000 +1300
+++ squid-4.0.8/src/auth/basic/SMB_LM/Makefile.in	2016-04-02 10:07:06.000000000 +1300
@@ -693,6 +693,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/basic/SSPI/Makefile.in squid-4.0.8/src/auth/basic/SSPI/Makefile.in
--- squid-4.0.7/src/auth/basic/SSPI/Makefile.in	2016-02-24 06:49:22.000000000 +1300
+++ squid-4.0.8/src/auth/basic/SSPI/Makefile.in	2016-04-02 10:07:08.000000000 +1300
@@ -701,6 +701,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/CredentialsCache.h squid-4.0.8/src/auth/CredentialsCache.h
--- squid-4.0.7/src/auth/CredentialsCache.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/auth/CredentialsCache.h	2016-04-02 10:04:07.000000000 +1300
@@ -11,7 +11,7 @@
 
 #include "auth/User.h"
 #include "cbdata.h"
-#include "SBufAlgos.h"
+#include "sbuf/Algorithms.h"
 
 #include <unordered_map>
 
@@ -20,12 +20,8 @@
 /// Cache of Auth::User credentials, keyed by Auth::User::userKey
 class CredentialsCache
 {
-private:
     CBDATA_CLASS(CredentialsCache);
 
-    /// key is User::userKey(), mapped value is User::Pointer
-    typedef std::unordered_map<SBuf, Auth::User::Pointer> StoreType;
-
 public:
     explicit CredentialsCache(const char *name, const char * const eventName);
 
@@ -70,6 +66,8 @@
     /// whether a cleanup (garbage collection) event has been scheduled
     bool gcScheduled_;
 
+    /// key is User::userKey(), mapped value is User::Pointer
+    typedef std::unordered_map<SBuf, Auth::User::Pointer> StoreType;
     StoreType store_;
 
     // c-string raw pointer used as event name
diff -u -r -N squid-4.0.7/src/auth/digest/Config.cc squid-4.0.8/src/auth/digest/Config.cc
--- squid-4.0.7/src/auth/digest/Config.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/auth/digest/Config.cc	2016-04-02 10:04:07.000000000 +1300
@@ -30,7 +30,7 @@
 #include "HttpRequest.h"
 #include "mgr/Registration.h"
 #include "rfc2617.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "SquidTime.h"
 #include "Store.h"
 #include "StrList.h"
diff -u -r -N squid-4.0.7/src/auth/digest/eDirectory/Makefile.in squid-4.0.8/src/auth/digest/eDirectory/Makefile.in
--- squid-4.0.7/src/auth/digest/eDirectory/Makefile.in	2016-02-24 06:49:25.000000000 +1300
+++ squid-4.0.8/src/auth/digest/eDirectory/Makefile.in	2016-04-02 10:07:14.000000000 +1300
@@ -694,6 +694,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/digest/file/Makefile.in squid-4.0.8/src/auth/digest/file/Makefile.in
--- squid-4.0.7/src/auth/digest/file/Makefile.in	2016-02-24 06:49:25.000000000 +1300
+++ squid-4.0.8/src/auth/digest/file/Makefile.in	2016-04-02 10:07:15.000000000 +1300
@@ -697,6 +697,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/digest/LDAP/Makefile.in squid-4.0.8/src/auth/digest/LDAP/Makefile.in
--- squid-4.0.7/src/auth/digest/LDAP/Makefile.in	2016-02-24 06:49:24.000000000 +1300
+++ squid-4.0.8/src/auth/digest/LDAP/Makefile.in	2016-04-02 10:07:11.000000000 +1300
@@ -694,6 +694,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/digest/Makefile.in squid-4.0.8/src/auth/digest/Makefile.in
--- squid-4.0.7/src/auth/digest/Makefile.in	2016-02-24 06:49:24.000000000 +1300
+++ squid-4.0.8/src/auth/digest/Makefile.in	2016-04-02 10:07:12.000000000 +1300
@@ -725,6 +725,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/auth/Makefile.in squid-4.0.8/src/auth/Makefile.in
--- squid-4.0.7/src/auth/Makefile.in	2016-02-24 06:49:17.000000000 +1300
+++ squid-4.0.8/src/auth/Makefile.in	2016-04-02 10:06:54.000000000 +1300
@@ -730,6 +730,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders CredentialState.cc Type.cc
diff -u -r -N squid-4.0.7/src/auth/negotiate/kerberos/Makefile.in squid-4.0.8/src/auth/negotiate/kerberos/Makefile.in
--- squid-4.0.7/src/auth/negotiate/kerberos/Makefile.in	2016-02-24 06:49:27.000000000 +1300
+++ squid-4.0.8/src/auth/negotiate/kerberos/Makefile.in	2016-04-02 10:07:18.000000000 +1300
@@ -718,6 +718,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/negotiate/Makefile.in squid-4.0.8/src/auth/negotiate/Makefile.in
--- squid-4.0.7/src/auth/negotiate/Makefile.in	2016-02-24 06:49:26.000000000 +1300
+++ squid-4.0.8/src/auth/negotiate/Makefile.in	2016-04-02 10:07:16.000000000 +1300
@@ -726,6 +726,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/auth/negotiate/SSPI/Makefile.in squid-4.0.8/src/auth/negotiate/SSPI/Makefile.in
--- squid-4.0.7/src/auth/negotiate/SSPI/Makefile.in	2016-02-24 06:49:26.000000000 +1300
+++ squid-4.0.8/src/auth/negotiate/SSPI/Makefile.in	2016-04-02 10:07:17.000000000 +1300
@@ -673,6 +673,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/negotiate/wrapper/Makefile.in squid-4.0.8/src/auth/negotiate/wrapper/Makefile.in
--- squid-4.0.7/src/auth/negotiate/wrapper/Makefile.in	2016-02-24 06:49:27.000000000 +1300
+++ squid-4.0.8/src/auth/negotiate/wrapper/Makefile.in	2016-04-02 10:07:20.000000000 +1300
@@ -673,6 +673,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/ntlm/fake/Makefile.in squid-4.0.8/src/auth/ntlm/fake/Makefile.in
--- squid-4.0.7/src/auth/ntlm/fake/Makefile.in	2016-02-24 06:49:29.000000000 +1300
+++ squid-4.0.8/src/auth/ntlm/fake/Makefile.in	2016-04-02 10:07:25.000000000 +1300
@@ -675,6 +675,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/ntlm/Makefile.in squid-4.0.8/src/auth/ntlm/Makefile.in
--- squid-4.0.7/src/auth/ntlm/Makefile.in	2016-02-24 06:49:28.000000000 +1300
+++ squid-4.0.8/src/auth/ntlm/Makefile.in	2016-04-02 10:07:21.000000000 +1300
@@ -725,6 +725,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/auth/ntlm/SMB_LM/Makefile.in squid-4.0.8/src/auth/ntlm/SMB_LM/Makefile.in
--- squid-4.0.7/src/auth/ntlm/SMB_LM/Makefile.in	2016-02-24 06:49:28.000000000 +1300
+++ squid-4.0.8/src/auth/ntlm/SMB_LM/Makefile.in	2016-04-02 10:07:22.000000000 +1300
@@ -677,6 +677,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/ntlm/SSPI/Makefile.in squid-4.0.8/src/auth/ntlm/SSPI/Makefile.in
--- squid-4.0.7/src/auth/ntlm/SSPI/Makefile.in	2016-02-24 06:49:28.000000000 +1300
+++ squid-4.0.8/src/auth/ntlm/SSPI/Makefile.in	2016-04-02 10:07:24.000000000 +1300
@@ -678,6 +678,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/auth/User.h squid-4.0.8/src/auth/User.h
--- squid-4.0.7/src/auth/User.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/auth/User.h	2016-04-02 10:04:07.000000000 +1300
@@ -18,7 +18,7 @@
 #include "dlink.h"
 #include "ip/Address.h"
 #include "Notes.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 class StoreEntry;
 
diff -u -r -N squid-4.0.7/src/base/AsyncJob.h squid-4.0.8/src/base/AsyncJob.h
--- squid-4.0.7/src/base/AsyncJob.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/base/AsyncJob.h	2016-04-02 10:04:07.000000000 +1300
@@ -11,6 +11,7 @@
 
 #include "base/AsyncCall.h"
 #include "base/InstanceId.h"
+#include "cbdata.h"
 
 template <class Cbc>
 class CbcPointer;
@@ -27,7 +28,7 @@
 
 /// \ingroup AsyncJobAPI
 /// Base class for all asynchronous jobs
-class AsyncJob
+class AsyncJob: public CbdataParent
 {
 public:
     typedef CbcPointer<AsyncJob> Pointer;
@@ -36,8 +37,6 @@
     AsyncJob(const char *aTypeName);
     virtual ~AsyncJob();
 
-    virtual void *toCbdata() = 0;
-
     /// starts a freshly created job (i.e., makes the job asynchronous)
     static Pointer Start(AsyncJob *job);
 
diff -u -r -N squid-4.0.7/src/base/LookupTable.h squid-4.0.8/src/base/LookupTable.h
--- squid-4.0.7/src/base/LookupTable.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/base/LookupTable.h	2016-04-02 10:04:07.000000000 +1300
@@ -9,8 +9,8 @@
 #ifndef SQUID_LOOKUPTABLE_H_
 #define SQUID_LOOKUPTABLE_H_
 
-#include "SBuf.h"
-#include "SBufAlgos.h"
+#include "sbuf/Algorithms.h"
+#include "sbuf/SBuf.h"
 
 #include <unordered_map>
 
diff -u -r -N squid-4.0.7/src/base/Makefile.in squid-4.0.8/src/base/Makefile.in
--- squid-4.0.7/src/base/Makefile.in	2016-02-24 06:49:29.000000000 +1300
+++ squid-4.0.8/src/base/Makefile.in	2016-04-02 10:07:26.000000000 +1300
@@ -687,6 +687,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/base/Packable.h squid-4.0.8/src/base/Packable.h
--- squid-4.0.7/src/base/Packable.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/base/Packable.h	2016-04-02 10:04:07.000000000 +1300
@@ -45,6 +45,9 @@
  * Thus, one can write just one function that will take a Packable object
  * and either "pack" things for Comm::Write or "append" things to Store,
  * depending on actual Packable object supplied.
+ *
+ * XXX: Misnamed. This is a Packer or Packager API (i.e., "something that packs
+ * or packages others"); this is not a "something that can be packed" API.
  */
 class Packable
 {
@@ -67,6 +70,12 @@
      *
      * \note arguments may be evaluated more than once, be careful
      *       of side-effects
+     *
+     * XXX: This method either should not exist or should not be virtual.
+     * Kids should not be forced to re-implement vappendf() logic.
+     * That logic should be implemented once, using other [Packable] APIs.
+     * Packable is not about providing a printf(3) service. Packable
+     * is about writing opaque data to various custom destinations.
      */
     virtual void vappendf(const char *fmt, va_list ap) = 0;
 
diff -u -r -N squid-4.0.7/src/base/TidyPointer.h squid-4.0.8/src/base/TidyPointer.h
--- squid-4.0.7/src/base/TidyPointer.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/base/TidyPointer.h	2016-04-02 10:04:07.000000000 +1300
@@ -27,8 +27,7 @@
     explicit operator bool() const { return raw; }
     /// Returns raw and possibly NULL pointer
     T *get() const { return raw; }
-    /// Address of the raw pointer, for pointer-setting functions
-    T **addr() { return &raw; }
+
     /// Reset raw pointer - delete last one and save new one.
     void reset(T *t) {
         deletePointer();
diff -u -r -N squid-4.0.7/src/cache_cf.cc squid-4.0.8/src/cache_cf.cc
--- squid-4.0.7/src/cache_cf.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/cache_cf.cc	2016-04-02 10:04:07.000000000 +1300
@@ -52,7 +52,7 @@
 #include "redirect.h"
 #include "RefreshPattern.h"
 #include "rfc1738.h"
-#include "SBufList.h"
+#include "sbuf/List.h"
 #include "SquidConfig.h"
 #include "SquidString.h"
 #include "ssl/ProxyCerts.h"
@@ -808,8 +808,6 @@
     // TODO: replace with a dedicated "purge" ACL option?
     Config2.onoff.enable_purge = (ACLMethodData::ThePurgeCount > 0);
 
-    Config2.onoff.mangle_request_headers = (Config.request_header_access != NULL);
-
     if (geteuid() == 0) {
         if (NULL != Config.effectiveUser) {
 
@@ -2455,6 +2453,26 @@
 {
     *var = 0;
 }
+
+static void
+dump_int64_t(StoreEntry * entry, const char *name, int64_t var)
+{
+    storeAppendPrintf(entry, "%s %" PRId64 "\n", name, var);
+}
+
+void
+parse_int64_t(int64_t *var)
+{
+    int64_t i;
+    i = GetInteger64();
+    *var = i;
+}
+
+static void
+free_int64_t(int64_t *var)
+{
+    *var = 0;
+}
 
 static void
 dump_onoff(StoreEntry * entry, const char *name, int var)
diff -u -r -N squid-4.0.7/src/cache_manager.cc squid-4.0.8/src/cache_manager.cc
--- squid-4.0.7/src/cache_manager.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/cache_manager.cc	2016-04-02 10:04:07.000000000 +1300
@@ -462,17 +462,12 @@
     return NULL;
 }
 
-CacheManager* CacheManager::instance=0;
-
-/**
- \ingroup CacheManagerAPI
- * Singleton accessor method.
- */
 CacheManager*
 CacheManager::GetInstance()
 {
-    if (instance == 0) {
-        debugs(16, 6, "CacheManager::GetInstance: starting cachemanager up");
+    static CacheManager *instance = nullptr;
+    if (!instance) {
+        debugs(16, 6, "starting cachemanager up");
         instance = new CacheManager;
         Mgr::RegisterBasics();
     }
diff -u -r -N squid-4.0.7/src/cbdata.h squid-4.0.8/src/cbdata.h
--- squid-4.0.7/src/cbdata.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/cbdata.h	2016-04-02 10:04:07.000000000 +1300
@@ -272,11 +272,8 @@
  */
 cbdata_type cbdataInternalAddType(cbdata_type type, const char *label, int size);
 
-/**
- * This needs to be defined FIRST in the class definition.
- * It plays with private/public states in C++.
- */
-#define CBDATA_CLASS(type) \
+/// declaration-generator used internally by CBDATA_CLASS() and CBDATA_CHILD()
+#define CBDATA_DECL_(type, methodSpecifiers) \
     public: \
         void *operator new(size_t size) { \
           assert(size == sizeof(type)); \
@@ -286,10 +283,29 @@
         void operator delete (void *address) { \
           if (address) cbdataInternalFree(address,__FILE__,__LINE__); \
         } \
-        void *toCbdata() { return this; } \
+        void *toCbdata() methodSpecifiers { return this; } \
     private: \
        static cbdata_type CBDATA_##type;
 
+/// Starts cbdata-protection in a class hierarchy.
+/// Child classes in the same hierarchy should use CBDATA_CHILD().
+class CbdataParent
+{
+public:
+    virtual ~CbdataParent() {}
+    virtual void *toCbdata() = 0;
+};
+
+/// cbdata-enables a stand-alone class that is not a CbdataParent child
+/// sets the class declaration section to "private"
+/// use this at the start of your class declaration for consistency sake
+#define CBDATA_CLASS(type) CBDATA_DECL_(type, noexcept)
+
+/// cbdata-enables a CbdataParent child class (including grandchildren)
+/// sets the class declaration section to "private"
+/// use this at the start of your class declaration for consistency sake
+#define CBDATA_CHILD(type) CBDATA_DECL_(type, override final)
+
 /**
  * Creates a global instance pointer for the CBDATA memory allocator
  * to allocate and free objects for the matching CBDATA_CLASS().
diff -u -r -N squid-4.0.7/src/cf.data.depend squid-4.0.8/src/cf.data.depend
--- squid-4.0.7/src/cf.data.depend	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/cf.data.depend	2016-04-02 10:04:07.000000000 +1300
@@ -51,6 +51,7 @@
 icmp
 ecap_service_type
 int
+int64_t
 kb_int64_t
 kb_size_t
 logformat
diff -u -r -N squid-4.0.7/src/cf.data.pre squid-4.0.8/src/cf.data.pre
--- squid-4.0.7/src/cf.data.pre	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/cf.data.pre	2016-04-02 10:04:07.000000000 +1300
@@ -109,6 +109,21 @@
 	${service_name} expands into the current Squid service instance
 	name identifier which is provided by -n on the command line.
 
+  Logformat Macros
+
+	Logformat macros can be used in many places outside of the logformat
+	directive. In theory, all of the logformat codes can be used as %macros,
+	where they are supported. In practice, a %macro expands as a dash (-) when
+	the transaction does not yet have enough information and a value is needed.
+
+	There is no definitive list of what tokens are available at the various
+	stages of the transaction.
+
+	And some information may already be available to Squid but not yet
+	committed where the macro expansion code can access it (report
+	such instances!). The macro will be expanded into a single dash
+	('-') in such cases. Not all macros have been tested.
+
 COMMENT_END
 
 # options still not yet ported from 2.7 to 3.x
@@ -419,6 +434,39 @@
 	See also: workers
 DOC_END
 
+NAME: shared_memory_locking
+TYPE: YesNoNone
+COMMENT: on|off
+LOC: Config.shmLocking
+DEFAULT: off
+DOC_START
+	Whether to ensure that all required shared memory is available by
+	"locking" that shared memory into RAM when Squid starts. The
+	alternative is faster startup time followed by slightly slower
+	performance and, if not enough RAM is actually available during
+	runtime, mysterious crashes.
+
+	SMP Squid uses many shared memory segments. These segments are
+	brought into Squid memory space using an mmap(2) system call. During
+	Squid startup, the mmap() call often succeeds regardless of whether
+	the system has enough RAM. In general, Squid cannot tell whether the
+	kernel applies this "optimistic" memory allocation policy (but
+	popular modern kernels usually use it).
+
+	Later, if Squid attempts to actually access the mapped memory
+	regions beyond what the kernel is willing to allocate, the
+	"optimistic" kernel simply kills Squid kid with a SIGBUS signal.
+	Some of the memory limits enforced by the kernel are currently
+	poorly understood: We do not know how to detect and check them. This
+	option ensures that the mapped memory will be available. 
+
+	This option may have a positive performance side-effect: Locking
+	memory at start avoids runtime paging I/O. Paging slows Squid down.
+
+	Locking memory may require a large enough RLIMIT_MEMLOCK OS limit,
+	CAP_IPC_LOCK capability, or equivalent.
+DOC_END
+
 COMMENT_START
  OPTIONS FOR AUTHENTICATION
  -----------------------------------------------------------------------------
@@ -774,8 +822,14 @@
 
 	  %ACL		The name of the ACL being tested.
 
-	  %DATA		The ACL arguments separated by spaces (an
-			"argument string").
+	  %DATA		The ACL arguments specified in the referencing config
+			'acl ... external' line, separated by spaces (an
+			"argument string"). see acl external.
+
+			If there are no ACL arguments %DATA expands to '-'.
+
+			If you do not specify a DATA macro inside FORMAT,
+			Squid automatically appends %DATA to your FORMAT.
 
 			By default, Squid applies URL-encoding to each ACL
 			argument inside the argument string. If an explicit
@@ -784,9 +838,6 @@
 			(e.g., with %#DATA, spaces between arguments become
 			%20).
 
-			If you do not specify a DATA macro inside FORMAT,
-			Squid automatically appends %DATA to your FORMAT.
-
 	If SSL is enabled, the following formating codes become available:
 
 	  %USER_CERT		SSL User certificate in PEM format
@@ -801,16 +852,13 @@
 
 	General request syntax:
 
-	  [channel-ID] FORMAT-values [acl-values ...]
+	  [channel-ID] FORMAT-values
 
 
 	FORMAT-values consists of transaction details expanded with
 	whitespace separation per the config file FORMAT specification
 	using the FORMAT macros listed above.
 
-	acl-values consists of any string specified in the referencing
-	config 'acl ... external' line. see the "acl external" directive.
-
 	Request values sent to the helper are URL escaped to protect
 	each value in requests against whitespaces.
 
@@ -6066,7 +6114,7 @@
 LOC: Config.request_header_add
 DEFAULT: none
 DOC_START
-	Usage:   request_header_add field-name field-value acl1 [acl2] ...
+	Usage:   request_header_add field-name field-value [ acl ... ]
 	Example: request_header_add X-Client-CA "CA=%ssl::>cert_issuer" all
 
 	This option adds header fields to outgoing HTTP requests (i.e.,
@@ -6086,20 +6134,45 @@
 	string format is used, then the surrounding quotes are removed
 	while escape sequences and %macros are processed.
 
-	In theory, all of the logformat codes can be used as %macros.
-	However, unlike logging (which happens at the very end of
-	transaction lifetime), the transaction may not yet have enough
-	information to expand a macro when the new header value is needed.
-	And some information may already be available to Squid but not yet
-	committed where the macro expansion code can access it (report
-	such instances!). The macro will be expanded into a single dash
-	('-') in such cases. Not all macros have been tested.
-
 	One or more Squid ACLs may be specified to restrict header
 	injection to matching requests. As always in squid.conf, all
-	ACLs in an option ACL list must be satisfied for the insertion
-	to happen. The request_header_add option supports fast ACLs
-	only.
+	ACLs in the ACL list must be satisfied for the insertion to
+	happen. The request_header_add supports fast ACLs only.
+
+	See also: reply_header_add.
+DOC_END
+
+NAME: reply_header_add
+TYPE: HeaderWithAclList
+LOC: Config.reply_header_add
+DEFAULT: none
+DOC_START
+	Usage:   reply_header_add field-name field-value [ acl ... ]
+	Example: reply_header_add X-Client-CA "CA=%ssl::>cert_issuer" all
+
+	This option adds header fields to outgoing HTTP responses (i.e., response
+	headers delivered by Squid to the client). This option has no effect on
+	cache hit detection. The equivalent adaptation vectoring point in
+	ICAP terminology is post-cache RESPMOD. This option does not apply to
+	successful CONNECT replies.
+
+	Field-name is a token specifying an HTTP header name. If a
+	standard HTTP header name is used, Squid does not check whether
+	the new header conflicts with any existing headers or violates
+	HTTP rules. If the response to be modified already contains a
+	field with the same name, the old field is preserved but the
+	header field values are not merged.
+
+	Field-value is either a token or a quoted string. If quoted
+	string format is used, then the surrounding quotes are removed
+	while escape sequences and %macros are processed.
+
+	One or more Squid ACLs may be specified to restrict header
+	injection to matching responses. As always in squid.conf, all
+	ACLs in the ACL list must be satisfied for the insertion to
+	happen. The reply_header_add option supports fast ACLs only.
+
+	See also: request_header_add.
 DOC_END
 
 NAME: note
@@ -6156,6 +6229,27 @@
        simultenous refresh requests] outweigh losses from such delays.
 DOC_END
 
+NAME: collapsed_forwarding_shared_entries_limit
+COMMENT: (number of entries)
+TYPE: int64_t
+LOC: Config.collapsed_forwarding_shared_entries_limit
+DEFAULT: 16384
+DOC_START
+	This limits the size of a table used for sharing information
+	about collapsible entries among SMP workers. Limiting sharing
+	too much results in cache content duplication and missed
+	collapsing opportunities. Using excessively large values
+	wastes shared memory.
+
+	The limit should be significantly larger then the number of
+	concurrent collapsible entries one wants to share. For a cache
+	that handles less than 5000 concurrent requests, the default
+	setting of 16384 should be plenty.
+
+	If the limit is set to zero, it disables sharing of collapsed
+	forwarding between SMP workers.
+DOC_END
+
 COMMENT_START
  TIMEOUTS
  -----------------------------------------------------------------------------
@@ -9632,4 +9726,42 @@
 	that the request body is needed. Delaying is the default behavior.
 DOC_END
 
+NAME: server_pconn_for_nonretriable
+TYPE: acl_access
+DEFAULT: none
+DEFAULT_DOC: Open new connections for forwarding requests Squid cannot retry safely.
+LOC: Config.accessList.serverPconnForNonretriable
+DOC_START
+	This option provides fine-grained control over persistent connection
+	reuse when forwarding HTTP requests that Squid cannot retry. It is useful
+	in environments where opening new connections is very expensive
+	(e.g., all connections are secured with TLS with complex client and server
+	certificate validation) and race conditions associated with persistent
+	connections are very rare and/or only cause minor problems.
+
+	HTTP prohibits retrying unsafe and non-idempotent requests (e.g., POST).
+	Squid limitations also prohibit retrying all requests with bodies (e.g., PUT).
+	By default, when forwarding such "risky" requests, Squid opens a new
+	connection to the server or cache_peer, even if there is an idle persistent
+	connection available. When Squid is configured to risk sending a non-retriable
+	request on a previously used persistent connection, and the server closes
+	the connection before seeing that risky request, the user gets an error response
+	from Squid. In most cases, that error response will be HTTP 502 (Bad Gateway)
+	with ERR_ZERO_SIZE_OBJECT or ERR_WRITE_ERROR (peer connection reset) error detail.
+
+	If an allow rule matches, Squid reuses an available idle persistent connection
+	(if any) for the request that Squid cannot retry. If a deny rule matches, then
+	Squid opens a new connection for the request that Squid cannot retry.
+
+	This option does not affect requests that Squid can retry. They will reuse idle
+	persistent connections (if any).
+
+	This clause only supports fast acl types.
+	See http://wiki.squid-cache.org/SquidFaq/SquidAcl for details.
+
+	Example:
+		acl SpeedIsWorthTheRisk method POST
+		server_pconn_for_nonretriable allow SpeedIsWorthTheRisk
+DOC_END
+
 EOF
diff -u -r -N squid-4.0.7/src/clients/Client.h squid-4.0.8/src/clients/Client.h
--- squid-4.0.7/src/clients/Client.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/clients/Client.h	2016-04-02 10:04:07.000000000 +1300
@@ -104,7 +104,9 @@
     virtual void sentRequestBody(const CommIoCbParams &io) = 0;
     virtual void doneSendingRequestBody() = 0;
 
-    virtual void closeServer() = 0;            /**< end communication with the server */
+    /// Use this to end communication with the server. The call cancels our
+    /// closure handler and tells FwdState to forget about the connection.
+    virtual void closeServer() = 0;
     virtual bool doneWithServer() const = 0;   /**< did we end communication? */
     /// whether we may receive more virgin response body bytes
     virtual bool mayReadVirginReplyBody() const = 0;
diff -u -r -N squid-4.0.7/src/clients/forward.h squid-4.0.8/src/clients/forward.h
--- squid-4.0.7/src/clients/forward.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/clients/forward.h	2016-04-02 10:04:07.000000000 +1300
@@ -9,9 +9,10 @@
 #ifndef SQUID_CLIENTS_FORWARD_H
 #define SQUID_CLIENTS_FORWARD_H
 
+#include "sbuf/forward.h"
+
 class FwdState;
 class HttpRequest;
-class SBuf;
 
 class AsyncJob;
 template <class Cbc> class CbcPointer;
diff -u -r -N squid-4.0.7/src/clients/FtpRelay.cc squid-4.0.8/src/clients/FtpRelay.cc
--- squid-4.0.7/src/clients/FtpRelay.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/clients/FtpRelay.cc	2016-04-02 10:04:07.000000000 +1300
@@ -18,7 +18,7 @@
 #include "http/Stream.h"
 #include "HttpHdrCc.h"
 #include "HttpRequest.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "servers/FtpServer.h"
 #include "SquidTime.h"
 #include "Store.h"
@@ -45,7 +45,7 @@
     void serverState(const Ftp::ServerState newState);
 
     /* Ftp::Client API */
-    virtual void failed(err_type error = ERR_NONE, int xerrno = 0);
+    virtual void failed(err_type error = ERR_NONE, int xerrno = 0, ErrorState *ftperr = nullptr);
     virtual void dataChannelConnected(const CommConnectCbParams &io);
 
     /* Client API */
@@ -59,6 +59,7 @@
 
     /* AsyncJob API */
     virtual void start();
+    virtual void swanSong();
 
     void forwardReply();
     void forwardError(err_type error = ERR_NONE, int xerrno = 0);
@@ -90,12 +91,18 @@
     void readUserOrPassReply();
 
     void scheduleReadControlReply();
-    void finalizeDataDownload();
+
+    /// Inform Ftp::Server that we are done if originWaitInProgress
+    void stopOriginWait(int code);
 
     static void abort(void *d); // TODO: Capitalize this and FwdState::abort().
 
     bool forwardingCompleted; ///< completeForwarding() has been called
 
+    /// whether we are between Ftp::Server::startWaitingForOrigin() and
+    /// Ftp::Server::stopWaitingForOrigin() calls
+    bool originWaitInProgress;
+
     struct {
         wordlist *message; ///< reply message, one  wordlist entry per message line
         char *lastCommand; ///< the command caused the reply
@@ -143,7 +150,8 @@
     AsyncJob("Ftp::Relay"),
     Ftp::Client(fwdState),
     thePreliminaryCb(NULL),
-    forwardingCompleted(false)
+    forwardingCompleted(false),
+    originWaitInProgress(false)
 {
     savedReply.message = NULL;
     savedReply.lastCommand = NULL;
@@ -179,11 +187,20 @@
         sendCommand();
 }
 
+void
+Ftp::Relay::swanSong()
+{
+    stopOriginWait(0);
+    Ftp::Client::swanSong();
+}
+
 /// Keep control connection for future requests, after we are done with it.
 /// Similar to COMPLETE_PERSISTENT_MSG handling in http.cc.
 void
 Ftp::Relay::serverComplete()
 {
+    stopOriginWait(ctrl.replycode);
+
     CbcPointer<ConnStateData> &mgr = fwd->request->clientConnectionManager;
     if (mgr.valid()) {
         if (Comm::IsConnOpen(ctrl.conn)) {
@@ -256,7 +273,7 @@
 }
 
 void
-Ftp::Relay::failed(err_type error, int xerrno)
+Ftp::Relay::failed(err_type error, int xerrno, ErrorState *ftpErr)
 {
     if (!doneWithServer())
         serverState(fssError);
@@ -265,7 +282,7 @@
     if (entry->isEmpty())
         failedErrorMessage(error, xerrno); // as a reply
 
-    Ftp::Client::failed(error, xerrno);
+    Ftp::Client::failed(error, xerrno, ftpErr);
 }
 
 void
@@ -531,6 +548,19 @@
         serverState() == fssConnected ? SENT_USER :
         serverState() == fssHandlePass ? SENT_PASS :
         SENT_COMMAND;
+
+    if (state == SENT_DATA_REQUEST) {
+        CbcPointer<ConnStateData> &mgr = fwd->request->clientConnectionManager;
+        if (mgr.valid()) {
+            if (Ftp::Server *srv = dynamic_cast<Ftp::Server*>(mgr.get())) {
+                typedef NullaryMemFunT<Ftp::Server> CbDialer;
+                AsyncCall::Pointer call = JobCallback(11, 3, CbDialer, srv,
+                                                      Ftp::Server::startWaitingForOrigin);
+                ScheduleCallHere(call);
+                originWaitInProgress = true;
+            }
+        }
+    }
 }
 
 void
@@ -689,7 +719,9 @@
                " after reading response data");
     }
 
-    finalizeDataDownload();
+    debugs(9, 2, "Complete data downloading");
+
+    serverComplete();
 }
 
 void
@@ -717,25 +749,6 @@
     Ftp::Client::scheduleReadControlReply(0);
 }
 
-void
-Ftp::Relay::finalizeDataDownload()
-{
-    debugs(9, 2, "Complete data downloading/Uploading");
-
-    updateMaster().waitForOriginData = false;
-
-    CbcPointer<ConnStateData> &mgr = fwd->request->clientConnectionManager;
-    if (mgr.valid()) {
-        if (Ftp::Server *srv = dynamic_cast<Ftp::Server*>(mgr.get())) {
-            typedef NullaryMemFunT<Ftp::Server> CbDialer;
-            AsyncCall::Pointer call = JobCallback(11, 3, CbDialer, srv,
-                                                  Ftp::Server::originDataCompletionCheckpoint);
-            ScheduleCallHere(call);
-        }
-    }
-    serverComplete();
-}
-
 bool
 Ftp::Relay::abortOnData(const char *reason)
 {
@@ -756,6 +769,23 @@
 }
 
 void
+Ftp::Relay::stopOriginWait(int code)
+{
+    if (originWaitInProgress) {
+        CbcPointer<ConnStateData> &mgr = fwd->request->clientConnectionManager;
+        if (mgr.valid()) {
+            if (Ftp::Server *srv = dynamic_cast<Ftp::Server*>(mgr.get())) {
+                typedef UnaryMemFunT<Ftp::Server, int> CbDialer;
+                AsyncCall::Pointer call = asyncCall(11, 3, "Ftp::Server::stopWaitingForOrigin",
+                                                    CbDialer(srv, &Ftp::Server::stopWaitingForOrigin, code));
+                ScheduleCallHere(call);
+            }
+        }
+        originWaitInProgress = false;
+    }
+}
+
+void
 Ftp::Relay::abort(void *d)
 {
     Ftp::Relay *ftpClient = (Ftp::Relay *)d;
diff -u -r -N squid-4.0.7/src/clients/Makefile.in squid-4.0.8/src/clients/Makefile.in
--- squid-4.0.7/src/clients/Makefile.in	2016-02-24 06:49:30.000000000 +1300
+++ squid-4.0.8/src/clients/Makefile.in	2016-04-02 10:07:27.000000000 +1300
@@ -686,6 +686,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/client_side.cc squid-4.0.8/src/client_side.cc
--- squid-4.0.7/src/client_side.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/client_side.cc	2016-04-02 10:04:07.000000000 +1300
@@ -446,6 +446,7 @@
     }
 
     if (request) {
+        HTTPMSGUNLOCK(al->adapted_request);
         al->adapted_request = request;
         HTTPMSGLOCK(al->adapted_request);
     }
@@ -2820,6 +2821,7 @@
         acl_checklist->al->tcpClient = clientConnection;
         acl_checklist->al->cache.port = port;
         acl_checklist->al->cache.caddr = log_addr;
+        HTTPMSGUNLOCK(acl_checklist->al->request);
         acl_checklist->al->request = request;
         HTTPMSGLOCK(acl_checklist->al->request);
         acl_checklist->nonBlockingCheck(httpsSslBumpAccessCheckDone, this);
@@ -3568,7 +3570,7 @@
 int
 varyEvaluateMatch(StoreEntry * entry, HttpRequest * request)
 {
-    const char *vary = request->vary_headers;
+    SBuf vary(request->vary_headers);
     int has_vary = entry->getReply()->header.has(Http::HdrType::VARY);
 #if X_ACCELERATOR_VARY
 
@@ -3576,12 +3578,12 @@
         entry->getReply()->header.has(Http::HdrType::HDR_X_ACCELERATOR_VARY);
 #endif
 
-    if (!has_vary || !entry->mem_obj->vary_headers) {
-        if (vary) {
+    if (!has_vary || entry->mem_obj->vary_headers.isEmpty()) {
+        if (!vary.isEmpty()) {
             /* Oops... something odd is going on here.. */
             debugs(33, DBG_IMPORTANT, "varyEvaluateMatch: Oops. Not a Vary object on second attempt, '" <<
                    entry->mem_obj->urlXXX() << "' '" << vary << "'");
-            safe_free(request->vary_headers);
+            request->vary_headers.clear();
             return VARY_CANCEL;
         }
 
@@ -3595,8 +3597,8 @@
          */
         vary = httpMakeVaryMark(request, entry->getReply());
 
-        if (vary) {
-            request->vary_headers = xstrdup(vary);
+        if (!vary.isEmpty()) {
+            request->vary_headers = vary;
             return VARY_OTHER;
         } else {
             /* Ouch.. we cannot handle this kind of variance */
@@ -3604,18 +3606,18 @@
             return VARY_CANCEL;
         }
     } else {
-        if (!vary) {
+        if (vary.isEmpty()) {
             vary = httpMakeVaryMark(request, entry->getReply());
 
-            if (vary)
-                request->vary_headers = xstrdup(vary);
+            if (!vary.isEmpty())
+                request->vary_headers = vary;
         }
 
-        if (!vary) {
+        if (vary.isEmpty()) {
             /* Ouch.. we cannot handle this kind of variance */
             /* XXX This cannot really happen, but just to be complete */
             return VARY_CANCEL;
-        } else if (strcmp(vary, entry->mem_obj->vary_headers) == 0) {
+        } else if (vary.cmp(entry->mem_obj->vary_headers) == 0) {
             return VARY_MATCH;
         } else {
             /* Oops.. we have already been here and still haven't
diff -u -r -N squid-4.0.7/src/client_side.h squid-4.0.8/src/client_side.h
--- squid-4.0.7/src/client_side.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/client_side.h	2016-04-02 10:04:07.000000000 +1300
@@ -18,7 +18,7 @@
 #include "http/forward.h"
 #include "HttpControlMsg.h"
 #include "ipc/FdNotes.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "servers/Server.h"
 #if USE_AUTH
 #include "auth/UserRequest.h"
diff -u -r -N squid-4.0.7/src/client_side_reply.cc squid-4.0.8/src/client_side_reply.cc
--- squid-4.0.7/src/client_side_reply.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/client_side_reply.cc	2016-04-02 10:04:07.000000000 +1300
@@ -20,7 +20,6 @@
 #include "format/Token.h"
 #include "FwdState.h"
 #include "globals.h"
-#include "globals.h"
 #include "http/Stream.h"
 #include "HttpHeaderTools.h"
 #include "HttpReply.h"
@@ -398,7 +397,7 @@
         sendClientOldEntry();
     }
 
-    HttpReply *old_rep = (HttpReply *) old_entry->getReply();
+    const HttpReply *old_rep = old_entry->getReply();
 
     // origin replied 304
     if (status == Http::scNotModified) {
@@ -406,8 +405,7 @@
         http->request->flags.staleIfHit = false; // old_entry is no longer stale
 
         // update headers on existing entry
-        old_rep->updateOnNotModified(http->storeEntry()->getReply());
-        old_entry->timestampsSet();
+        Store::Root().updateOnNotModified(old_entry, *http->storeEntry());
 
         // if client sent IMS
 
@@ -1008,9 +1006,8 @@
     }
 
     /* And for Vary, release the base URI if none of the headers was included in the request */
-
-    if (http->request->vary_headers
-            && !strstr(http->request->vary_headers, "=")) {
+    if (!http->request->vary_headers.isEmpty()
+            && http->request->vary_headers.find('=') != SBuf::npos) {
         // XXX: performance regression, c_str() reallocates
         SBuf tmp(http->request->effectiveRequestUri());
         StoreEntry *entry = storeGetPublic(tmp.c_str(), Http::METHOD_GET);
@@ -1579,7 +1576,7 @@
         /* TODO: else case: drop any controls intended specifically for our surrogate ID */
     }
 
-    httpHdrMangleList(hdr, request, ROR_REPLY);
+    httpHdrMangleList(hdr, request, http->al, ROR_REPLY);
 }
 
 void
diff -u -r -N squid-4.0.7/src/client_side_request.cc squid-4.0.8/src/client_side_request.cc
--- squid-4.0.7/src/client_side_request.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/client_side_request.cc	2016-04-02 10:04:07.000000000 +1300
@@ -344,7 +344,7 @@
     http->uri = (char *)xcalloc(url_sz, 1);
     strcpy(http->uri, url);
 
-    if ((request = HttpRequest::CreateFromUrlAndMethod(http->uri, method)) == NULL) {
+    if ((request = HttpRequest::CreateFromUrl(http->uri, method)) == NULL) {
         debugs(85, 5, "Invalid URL: " << http->uri);
         return -1;
     }
diff -u -r -N squid-4.0.7/src/comm/ConnOpener.h squid-4.0.8/src/comm/ConnOpener.h
--- squid-4.0.7/src/comm/ConnOpener.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/comm/ConnOpener.h	2016-04-02 10:04:07.000000000 +1300
@@ -26,10 +26,6 @@
 {
     CBDATA_CLASS(ConnOpener);
 
-protected:
-    virtual void start();
-    virtual void swanSong();
-
 public:
     void noteAbort() { mustStop("externally aborted"); }
 
@@ -43,6 +39,10 @@
     void setHost(const char *);    ///< set the hostname note for this connection
     const char * getHost() const;  ///< get the hostname noted for this connection
 
+protected:
+    virtual void start();
+    virtual void swanSong();
+
 private:
     // Undefined because two openers cannot share a connection
     ConnOpener(const ConnOpener &);
diff -u -r -N squid-4.0.7/src/comm/IoCallback.h squid-4.0.8/src/comm/IoCallback.h
--- squid-4.0.7/src/comm/IoCallback.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/comm/IoCallback.h	2016-04-02 10:04:07.000000000 +1300
@@ -13,8 +13,7 @@
 #include "comm/Flag.h"
 #include "comm/forward.h"
 #include "mem/forward.h"
-
-class SBuf;
+#include "sbuf/forward.h"
 
 namespace Comm
 {
diff -u -r -N squid-4.0.7/src/comm/Makefile.in squid-4.0.8/src/comm/Makefile.in
--- squid-4.0.7/src/comm/Makefile.in	2016-02-24 06:49:30.000000000 +1300
+++ squid-4.0.8/src/comm/Makefile.in	2016-04-02 10:07:29.000000000 +1300
@@ -688,6 +688,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/comm/Read.cc squid-4.0.8/src/comm/Read.cc
--- squid-4.0.7/src/comm/Read.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/comm/Read.cc	2016-04-02 10:04:07.000000000 +1300
@@ -18,7 +18,7 @@
 #include "Debug.h"
 #include "fd.h"
 #include "fde.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "StatCounters.h"
 //#include "tools.h"
 
diff -u -r -N squid-4.0.7/src/comm/Read.h squid-4.0.8/src/comm/Read.h
--- squid-4.0.7/src/comm/Read.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/comm/Read.h	2016-04-02 10:04:07.000000000 +1300
@@ -12,8 +12,7 @@
 #include "base/AsyncCall.h"
 #include "comm/forward.h"
 #include "CommCalls.h"
-
-class SBuf;
+#include "sbuf/forward.h"
 
 namespace Comm
 {
diff -u -r -N squid-4.0.7/src/comm.cc squid-4.0.8/src/comm.cc
--- squid-4.0.7/src/comm.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/comm.cc	2016-04-02 10:04:07.000000000 +1300
@@ -31,7 +31,7 @@
 #include "ip/tools.h"
 #include "pconn.h"
 #include "profiler/Profiler.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "SquidConfig.h"
 #include "StatCounters.h"
 #include "StoreIOBuffer.h"
@@ -972,7 +972,7 @@
     return Comm::COMM_ERROR;
 }
 
-void
+AsyncCall::Pointer
 comm_add_close_handler(int fd, CLCB * handler, void *data)
 {
     debugs(5, 5, "comm_add_close_handler: FD " << fd << ", handler=" <<
@@ -981,6 +981,7 @@
     AsyncCall::Pointer call=commCbCall(5,4, "SomeCloseHandler",
                                        CommCloseCbPtrFun(handler, data));
     comm_add_close_handler(fd, call);
+    return call;
 }
 
 void
diff -u -r -N squid-4.0.7/src/comm.h squid-4.0.8/src/comm.h
--- squid-4.0.7/src/comm.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/comm.h	2016-04-02 10:04:07.000000000 +1300
@@ -79,7 +79,7 @@
 void commCloseAllSockets(void);
 void checkTimeouts(void);
 
-void comm_add_close_handler(int fd, CLCB *, void *);
+AsyncCall::Pointer comm_add_close_handler(int fd, CLCB *, void *);
 void comm_add_close_handler(int fd, AsyncCall::Pointer &);
 void comm_remove_close_handler(int fd, CLCB *, void *);
 void comm_remove_close_handler(int fd, AsyncCall::Pointer &);
diff -u -r -N squid-4.0.7/src/Common.am squid-4.0.8/src/Common.am
--- squid-4.0.7/src/Common.am	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/Common.am	2016-04-02 10:04:07.000000000 +1300
@@ -10,6 +10,27 @@
 ## This file should be included first in all src/subdir/Makefile.am
 ## so it must not contain stuff specific to or bad for some subdirectories.
 
+## Default variables
+DEFAULT_HTTP_PORT	= 3128
+DEFAULT_ICP_PORT	= 3130
+DEFAULT_PREFIX		= $(prefix)
+DEFAULT_CONFIG_DIR	= $(sysconfdir)
+DEFAULT_CONFIG_FILE	= $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE	= $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD	= $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX	= $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG	= $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG	= $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG	= $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE	= $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR	= $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER		= $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD		= $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED	= $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD		= $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR	= $(datadir)/icons
+DEFAULT_ERROR_DIR	= $(datadir)/errors
+
 ## TODO: make this set by configure?
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
diff -u -r -N squid-4.0.7/src/debug.cc squid-4.0.8/src/debug.cc
--- squid-4.0.7/src/debug.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/debug.cc	2016-04-02 10:04:07.000000000 +1300
@@ -222,7 +222,14 @@
     if (debug_log && debug_log != stderr)
         fclose(debug_log);
 
-    debug_log = fopen(logfile, "a+");
+    // Bug 4423: ignore the stdio: logging module name if present
+    const char *logfilename;
+    if (strncmp(logfile, "stdio:",6) == 0)
+        logfilename = logfile + 6;
+    else
+        logfilename = logfile;
+
+    debug_log = fopen(logfilename, "a+");
 
     if (!debug_log) {
         fprintf(stderr, "WARNING: Cannot write log file: %s\n", logfile);
diff -u -r -N squid-4.0.7/src/DiskIO/AIO/Makefile.in squid-4.0.8/src/DiskIO/AIO/Makefile.in
--- squid-4.0.7/src/DiskIO/AIO/Makefile.in	2016-02-24 06:49:04.000000000 +1300
+++ squid-4.0.8/src/DiskIO/AIO/Makefile.in	2016-04-02 10:06:24.000000000 +1300
@@ -694,6 +694,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/DiskIO/Blocking/Makefile.in squid-4.0.8/src/DiskIO/Blocking/Makefile.in
--- squid-4.0.7/src/DiskIO/Blocking/Makefile.in	2016-02-24 06:49:04.000000000 +1300
+++ squid-4.0.8/src/DiskIO/Blocking/Makefile.in	2016-04-02 10:06:25.000000000 +1300
@@ -686,6 +686,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/DiskIO/DiskDaemon/Makefile.in squid-4.0.8/src/DiskIO/DiskDaemon/Makefile.in
--- squid-4.0.7/src/DiskIO/DiskDaemon/Makefile.in	2016-02-24 06:49:05.000000000 +1300
+++ squid-4.0.8/src/DiskIO/DiskDaemon/Makefile.in	2016-04-02 10:06:26.000000000 +1300
@@ -702,6 +702,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders time.cc
diff -u -r -N squid-4.0.7/src/DiskIO/DiskThreads/Makefile.in squid-4.0.8/src/DiskIO/DiskThreads/Makefile.in
--- squid-4.0.7/src/DiskIO/DiskThreads/Makefile.in	2016-02-24 06:49:05.000000000 +1300
+++ squid-4.0.8/src/DiskIO/DiskThreads/Makefile.in	2016-04-02 10:06:27.000000000 +1300
@@ -696,6 +696,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/DiskIO/IpcIo/IpcIoFile.cc squid-4.0.8/src/DiskIO/IpcIo/IpcIoFile.cc
--- squid-4.0.7/src/DiskIO/IpcIo/IpcIoFile.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/DiskIO/IpcIo/IpcIoFile.cc	2016-04-02 10:04:07.000000000 +1300
@@ -24,7 +24,7 @@
 #include "ipc/Queue.h"
 #include "ipc/StrandSearch.h"
 #include "ipc/UdsOp.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "SquidConfig.h"
 #include "SquidTime.h"
 #include "StatCounters.h"
diff -u -r -N squid-4.0.7/src/DiskIO/IpcIo/Makefile.in squid-4.0.8/src/DiskIO/IpcIo/Makefile.in
--- squid-4.0.7/src/DiskIO/IpcIo/Makefile.in	2016-02-24 06:49:06.000000000 +1300
+++ squid-4.0.8/src/DiskIO/IpcIo/Makefile.in	2016-04-02 10:06:28.000000000 +1300
@@ -686,6 +686,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/DiskIO/Makefile.in squid-4.0.8/src/DiskIO/Makefile.in
--- squid-4.0.7/src/DiskIO/Makefile.in	2016-02-24 06:49:06.000000000 +1300
+++ squid-4.0.8/src/DiskIO/Makefile.in	2016-04-02 10:06:29.000000000 +1300
@@ -748,6 +748,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/DiskIO/Mmapped/Makefile.in squid-4.0.8/src/DiskIO/Mmapped/Makefile.in
--- squid-4.0.7/src/DiskIO/Mmapped/Makefile.in	2016-02-24 06:49:07.000000000 +1300
+++ squid-4.0.8/src/DiskIO/Mmapped/Makefile.in	2016-04-02 10:06:30.000000000 +1300
@@ -686,6 +686,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/dns/Makefile.in squid-4.0.8/src/dns/Makefile.in
--- squid-4.0.7/src/dns/Makefile.in	2016-02-24 06:49:31.000000000 +1300
+++ squid-4.0.8/src/dns/Makefile.in	2016-04-02 10:07:30.000000000 +1300
@@ -686,6 +686,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/enums.h squid-4.0.8/src/enums.h
--- squid-4.0.7/src/enums.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/enums.h	2016-04-02 10:04:07.000000000 +1300
@@ -179,12 +179,6 @@
     DIGEST_READ_DONE
 } digest_read_state_t;
 
-/* Distinguish between Request and Reply (for header mangling) */
-enum {
-    ROR_REQUEST,
-    ROR_REPLY
-};
-
 /* CygWin & Windows NT Port */
 #if _SQUID_WINDOWS_
 /*
diff -u -r -N squid-4.0.7/src/esi/CustomParser.h squid-4.0.8/src/esi/CustomParser.h
--- squid-4.0.7/src/esi/CustomParser.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/esi/CustomParser.h	2016-04-02 10:04:07.000000000 +1300
@@ -14,7 +14,7 @@
 /* inherits from */
 #include "esi/Parser.h"
 
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "SquidString.h"
 
 /**
diff -u -r -N squid-4.0.7/src/esi/Makefile.in squid-4.0.8/src/esi/Makefile.in
--- squid-4.0.7/src/esi/Makefile.in	2016-02-24 06:49:31.000000000 +1300
+++ squid-4.0.8/src/esi/Makefile.in	2016-04-02 10:07:31.000000000 +1300
@@ -705,6 +705,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/eui/Eui48.cc squid-4.0.8/src/eui/Eui48.cc
--- squid-4.0.7/src/eui/Eui48.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/eui/Eui48.cc	2016-04-02 10:04:07.000000000 +1300
@@ -181,6 +181,7 @@
         close(tmpSocket);
 
         if (arpReq.arp_ha.sa_family != ARPHRD_ETHER) {
+            debugs(28, 4, "id=" << (void*)this << " ... not an Ethernet interface: " << arpReq.arp_ha.sa_data);
             clear();
             return false;
         }
diff -u -r -N squid-4.0.7/src/eui/Makefile.in squid-4.0.8/src/eui/Makefile.in
--- squid-4.0.7/src/eui/Makefile.in	2016-02-24 06:49:32.000000000 +1300
+++ squid-4.0.8/src/eui/Makefile.in	2016-04-02 10:07:33.000000000 +1300
@@ -686,6 +686,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/external_acl.cc squid-4.0.8/src/external_acl.cc
--- squid-4.0.7/src/external_acl.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/external_acl.cc	2016-04-02 10:04:07.000000000 +1300
@@ -742,7 +742,7 @@
                 }
             }
 
-            ch->al->lastAclData = xstrdup(sb.c_str());
+            ch->al->lastAclData = sb;
         }
 
 #if USE_IDENT
diff -u -r -N squid-4.0.7/src/format/Format.cc squid-4.0.8/src/format/Format.cc
--- squid-4.0.7/src/format/Format.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/format/Format.cc	2016-04-02 10:04:07.000000000 +1300
@@ -34,6 +34,8 @@
 /// Convert a string to NULL pointer if it is ""
 #define strOrNull(s) ((s)==NULL||(s)[0]=='\0'?NULL:(s))
 
+const SBuf Format::Dash("-");
+
 Format::Format::Format(const char *n) :
     format(NULL),
     next(NULL)
@@ -1039,7 +1041,11 @@
         break;
 
         case LFT_REQUEST_URI:
-            out = al->url;
+            if (!al->url.isEmpty()) {
+                const SBuf &s = al->url;
+                sb.append(s.rawContent(), s.length());
+                out = sb.termedBuf();
+            }
             break;
 
         case LFT_REQUEST_VERSION_OLD_2X:
@@ -1381,7 +1387,8 @@
             break;
 
         case LFT_EXT_ACL_DATA:
-            out = al->lastAclData;
+            if (!al->lastAclData.isEmpty())
+                out = al->lastAclData.c_str();
             break;
         }
 
diff -u -r -N squid-4.0.7/src/format/Format.h squid-4.0.8/src/format/Format.h
--- squid-4.0.7/src/format/Format.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/format/Format.h	2016-04-02 10:04:07.000000000 +1300
@@ -11,6 +11,7 @@
 
 #include "base/RefCount.h"
 #include "ConfigParser.h"
+#include "sbuf/SBuf.h"
 
 /*
  * Squid configuration allows users to define custom formats in
@@ -32,6 +33,8 @@
 namespace Format
 {
 
+extern const SBuf Dash;
+
 class Token;
 
 // XXX: inherit from linked list
diff -u -r -N squid-4.0.7/src/format/Makefile.in squid-4.0.8/src/format/Makefile.in
--- squid-4.0.7/src/format/Makefile.in	2016-02-24 06:49:33.000000000 +1300
+++ squid-4.0.8/src/format/Makefile.in	2016-04-02 10:07:34.000000000 +1300
@@ -685,6 +685,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/fs/Makefile.am squid-4.0.8/src/fs/Makefile.am
--- squid-4.0.7/src/fs/Makefile.am	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/fs/Makefile.am	2016-04-02 10:04:07.000000000 +1300
@@ -38,6 +38,8 @@
 	rock/forward.h \
 	rock/RockDbCell.cc \
 	rock/RockDbCell.h \
+	rock/RockHeaderUpdater.cc \
+	rock/RockHeaderUpdater.h \
 	rock/RockIoState.cc \
 	rock/RockIoState.h \
 	rock/RockIoRequests.cc \
diff -u -r -N squid-4.0.7/src/fs/Makefile.in squid-4.0.8/src/fs/Makefile.in
--- squid-4.0.7/src/fs/Makefile.in	2016-02-24 06:49:33.000000000 +1300
+++ squid-4.0.8/src/fs/Makefile.in	2016-04-02 10:07:35.000000000 +1300
@@ -177,8 +177,8 @@
 am_libfs_la_OBJECTS = Module.lo
 libfs_la_OBJECTS = $(am_libfs_la_OBJECTS)
 librock_la_LIBADD =
-am_librock_la_OBJECTS = rock/RockDbCell.lo rock/RockIoState.lo \
-	rock/RockIoRequests.lo rock/RockRebuild.lo \
+am_librock_la_OBJECTS = rock/RockDbCell.lo rock/RockHeaderUpdater.lo \
+	rock/RockIoState.lo rock/RockIoRequests.lo rock/RockRebuild.lo \
 	rock/RockStoreFileSystem.lo rock/RockSwapDir.lo
 librock_la_OBJECTS = $(am_librock_la_OBJECTS)
 libufs_la_LIBADD =
@@ -703,6 +703,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
@@ -747,6 +766,8 @@
 	rock/forward.h \
 	rock/RockDbCell.cc \
 	rock/RockDbCell.h \
+	rock/RockHeaderUpdater.cc \
+	rock/RockHeaderUpdater.h \
 	rock/RockIoState.cc \
 	rock/RockIoState.h \
 	rock/RockIoRequests.cc \
@@ -839,6 +860,8 @@
 	@: > rock/$(DEPDIR)/$(am__dirstamp)
 rock/RockDbCell.lo: rock/$(am__dirstamp) \
 	rock/$(DEPDIR)/$(am__dirstamp)
+rock/RockHeaderUpdater.lo: rock/$(am__dirstamp) \
+	rock/$(DEPDIR)/$(am__dirstamp)
 rock/RockIoState.lo: rock/$(am__dirstamp) \
 	rock/$(DEPDIR)/$(am__dirstamp)
 rock/RockIoRequests.lo: rock/$(am__dirstamp) \
@@ -899,6 +922,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote@aufs/$(DEPDIR)/StoreFSaufs.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@diskd/$(DEPDIR)/StoreFSdiskd.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@rock/$(DEPDIR)/RockDbCell.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@rock/$(DEPDIR)/RockHeaderUpdater.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@rock/$(DEPDIR)/RockIoRequests.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@rock/$(DEPDIR)/RockIoState.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@rock/$(DEPDIR)/RockRebuild.Plo@am__quote@
diff -u -r -N squid-4.0.7/src/fs/rock/forward.h squid-4.0.8/src/fs/rock/forward.h
--- squid-4.0.7/src/fs/rock/forward.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/fs/rock/forward.h	2016-04-02 10:04:07.000000000 +1300
@@ -36,6 +36,8 @@
 
 class IoState;
 
+class HeaderUpdater;
+
 class DbCellHeader;
 
 }
diff -u -r -N squid-4.0.7/src/fs/rock/RockHeaderUpdater.cc squid-4.0.8/src/fs/rock/RockHeaderUpdater.cc
--- squid-4.0.7/src/fs/rock/RockHeaderUpdater.cc	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/fs/rock/RockHeaderUpdater.cc	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,267 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "base/AsyncJobCalls.h"
+#include "Debug.h"
+#include "fs/rock/RockHeaderUpdater.h"
+#include "fs/rock/RockIoState.h"
+#include "mime_header.h"
+#include "Store.h"
+#include "StoreMetaUnpacker.h"
+
+CBDATA_NAMESPACED_CLASS_INIT(Rock, HeaderUpdater);
+
+Rock::HeaderUpdater::HeaderUpdater(const Rock::SwapDir::Pointer &aStore, const Ipc::StoreMapUpdate &anUpdate):
+    AsyncJob("Rock::HeaderUpdater"),
+    store(aStore),
+    update(anUpdate),
+    reader(),
+    writer(),
+    bytesRead(0),
+    staleSwapHeaderSize(0),
+    staleSplicingPointNext(-1)
+{
+    // TODO: Consider limiting the number of concurrent store updates.
+}
+
+bool
+Rock::HeaderUpdater::doneAll() const
+{
+    return !reader && !writer && AsyncJob::doneAll();
+}
+
+void
+Rock::HeaderUpdater::swanSong()
+{
+    if (update.stale || update.fresh)
+        store->map->abortUpdating(update);
+
+    if (reader) {
+        reader->close(StoreIOState::readerDone);
+        reader = nullptr;
+    }
+
+    if (writer) {
+        writer->close(StoreIOState::writerGone);
+        // Emulate SwapDir::disconnect() that writeCompleted(err) hopes for.
+        // Also required to avoid IoState destructor assertions.
+        // We can do this because we closed update earlier or aborted it above.
+        dynamic_cast<IoState&>(*writer).writeableAnchor_ = nullptr;
+        writer = nullptr;
+    }
+
+    AsyncJob::swanSong();
+}
+
+void
+Rock::HeaderUpdater::start()
+{
+    Must(update.entry);
+    Must(update.stale);
+    Must(update.fresh);
+    startReading();
+}
+
+void
+Rock::HeaderUpdater::startReading()
+{
+    reader = store->openStoreIO(
+                 *update.entry,
+                 nullptr, // unused; see StoreIOState::file_callback
+                 &NoteDoneReading,
+                 this);
+    readMore("need swap entry metadata");
+}
+
+void
+Rock::HeaderUpdater::stopReading(const char *why)
+{
+    debugs(47, 7, why);
+
+    Must(reader);
+    const IoState &rockReader = dynamic_cast<IoState&>(*reader);
+    update.stale.splicingPoint = rockReader.splicingPoint;
+    staleSplicingPointNext = rockReader.staleSplicingPointNext;
+    debugs(47, 5, "stale chain ends at " << update.stale.splicingPoint <<
+           " body continues at " << staleSplicingPointNext);
+
+    reader->close(StoreIOState::readerDone); // calls noteDoneReading(0)
+    reader = nullptr; // so that swanSong() does not try to close again
+}
+
+void
+Rock::HeaderUpdater::NoteRead(void *data, const char *buf, ssize_t result, StoreIOState::Pointer)
+{
+    // TODO: Avoid Rock::StoreIOStateCb for jobs to protect jobs for "free".
+    CallJobHere1(47, 7,
+                 CbcPointer<HeaderUpdater>(static_cast<HeaderUpdater*>(data)),
+                 Rock::HeaderUpdater,
+                 noteRead,
+                 result);
+}
+
+void
+Rock::HeaderUpdater::noteRead(ssize_t result)
+{
+    debugs(47, 7, result);
+    if (!result) { // EOF
+        stopReading("eof");
+    } else {
+        Must(result > 0);
+        bytesRead += result;
+        readerBuffer.forceSize(readerBuffer.length() + result);
+        exchangeBuffer.append(readerBuffer);
+        debugs(47, 7, "accumulated " << exchangeBuffer.length());
+    }
+
+    parseReadBytes();
+}
+
+void
+Rock::HeaderUpdater::readMore(const char *why)
+{
+    debugs(47, 7, "from " << bytesRead << " because " << why);
+    Must(reader);
+    readerBuffer.clear();
+    storeRead(reader,
+              readerBuffer.rawSpace(store->slotSize),
+              store->slotSize,
+              bytesRead,
+              &NoteRead,
+              this);
+}
+
+void
+Rock::HeaderUpdater::NoteDoneReading(void *data, int errflag, StoreIOState::Pointer)
+{
+    // TODO: Avoid Rock::StoreIOStateCb for jobs to protect jobs for "free".
+    CallJobHere1(47, 7,
+                 CbcPointer<HeaderUpdater>(static_cast<HeaderUpdater*>(data)),
+                 Rock::HeaderUpdater,
+                 noteDoneReading,
+                 errflag);
+}
+
+void
+Rock::HeaderUpdater::noteDoneReading(int errflag)
+{
+    debugs(47, 5, errflag << " writer=" << writer);
+    if (const bool weInitiatedThisClosure = !reader) {
+        Must(!errflag); // we only initiate successful closures
+        Must(writer); // otherwise we would be done() and would not be called
+    } else {
+        reader = nullptr; // we are done reading
+        Must(errflag); // any external closures ought to be errors
+        mustStop("read error");
+    }
+}
+
+void
+Rock::HeaderUpdater::startWriting()
+{
+    writer = store->createUpdateIO(
+                 update,
+                 nullptr, // unused; see StoreIOState::file_callback
+                 &NoteDoneWriting,
+                 this);
+    Must(writer);
+
+    IoState &rockWriter = dynamic_cast<IoState&>(*writer);
+    rockWriter.staleSplicingPointNext = staleSplicingPointNext;
+
+    off_t offset = 0; // current writing offset (for debugging)
+
+    {
+        debugs(20, 7, "fresh store meta for " << *update.entry);
+        const char *freshSwapHeader = update.entry->getSerialisedMetaData();
+        const auto freshSwapHeaderSize = update.entry->mem_obj->swap_hdr_sz;
+        Must(freshSwapHeader);
+        writer->write(freshSwapHeader, freshSwapHeaderSize, 0, nullptr);
+        offset += freshSwapHeaderSize;
+    }
+
+    {
+        debugs(20, 7, "fresh HTTP header @ " << offset);
+        MemBuf *httpHeader = update.entry->mem_obj->getReply()->pack();
+        writer->write(httpHeader->content(), httpHeader->contentSize(), -1, nullptr);
+        offset += httpHeader->contentSize();
+        delete httpHeader;
+    }
+
+    {
+        debugs(20, 7, "moved HTTP body prefix @ " << offset);
+        writer->write(exchangeBuffer.rawContent(), exchangeBuffer.length(), -1, nullptr);
+        offset += exchangeBuffer.length();
+        exchangeBuffer.clear();
+    }
+
+    debugs(20, 7, "wrote " << offset);
+
+    writer->close(StoreIOState::wroteAll); // should call noteDoneWriting()
+}
+
+void
+Rock::HeaderUpdater::NoteDoneWriting(void *data, int errflag, StoreIOState::Pointer)
+{
+    CallJobHere1(47, 7,
+                 CbcPointer<HeaderUpdater>(static_cast<HeaderUpdater*>(data)),
+                 Rock::HeaderUpdater,
+                 noteDoneWriting,
+                 errflag);
+}
+
+void
+Rock::HeaderUpdater::noteDoneWriting(int errflag)
+{
+    debugs(47, 5, errflag << " reader=" << reader);
+    Must(!errflag);
+    Must(!reader); // if we wrote everything, then we must have read everything
+
+    Must(writer);
+    IoState &rockWriter = dynamic_cast<IoState&>(*writer);
+    update.fresh.splicingPoint = rockWriter.splicingPoint;
+    debugs(47, 5, "fresh chain ends at " << update.fresh.splicingPoint);
+    store->map->closeForUpdating(update);
+    rockWriter.writeableAnchor_ = nullptr;
+    writer = nullptr; // we are done writing
+
+    Must(doneAll());
+}
+
+void
+Rock::HeaderUpdater::parseReadBytes()
+{
+    if (!staleSwapHeaderSize) {
+        StoreMetaUnpacker aBuilder(
+            exchangeBuffer.rawContent(),
+            exchangeBuffer.length(),
+            &staleSwapHeaderSize);
+        // Squid assumes that metadata always fits into a single db slot
+        Must(aBuilder.isBufferSane()); // cannot update what we cannot parse
+        debugs(47, 7, "staleSwapHeaderSize=" << staleSwapHeaderSize);
+        Must(staleSwapHeaderSize > 0);
+        exchangeBuffer.consume(staleSwapHeaderSize);
+    }
+
+    const size_t staleHttpHeaderSize = headersEnd(
+                                           exchangeBuffer.rawContent(),
+                                           exchangeBuffer.length());
+    debugs(47, 7, "staleHttpHeaderSize=" << staleHttpHeaderSize);
+    if (!staleHttpHeaderSize) {
+        readMore("need more stale HTTP reply header data");
+        return;
+    }
+
+    exchangeBuffer.consume(staleHttpHeaderSize);
+    debugs(47, 7, "httpBodySizePrefix=" << exchangeBuffer.length());
+
+    stopReading("read the last HTTP header slot");
+    startWriting();
+}
+
diff -u -r -N squid-4.0.7/src/fs/rock/RockHeaderUpdater.h squid-4.0.8/src/fs/rock/RockHeaderUpdater.h
--- squid-4.0.7/src/fs/rock/RockHeaderUpdater.h	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/fs/rock/RockHeaderUpdater.h	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_FS_ROCK_HEADER_UPDATER_H
+#define SQUID_FS_ROCK_HEADER_UPDATER_H
+
+#include "base/AsyncJob.h"
+#include "cbdata.h"
+#include "fs/rock/forward.h"
+#include "fs/rock/RockSwapDir.h"
+#include "ipc/StoreMap.h"
+
+namespace Rock
+{
+
+/// Updates HTTP headers of a single Rock store entry:
+/// * reads old body data in the same slot as the last old headers slot, if any
+/// * writes new headers (1+ slots)
+/// * writes old data (0-2 slots)
+/// * chains the new entry prefix (1+ slots) to the old entry suffix (0+ slots)
+class HeaderUpdater: public AsyncJob
+{
+    CBDATA_CHILD(HeaderUpdater);
+
+public:
+    HeaderUpdater(const Rock::SwapDir::Pointer &aStore, const Ipc::StoreMapUpdate &update);
+    virtual ~HeaderUpdater() override = default;
+
+protected:
+    /* AsyncJob API */
+    virtual void start() override;
+    virtual bool doneAll() const override;
+    virtual void swanSong() override;
+
+private:
+    static StoreIOState::STRCB NoteRead;
+    static StoreIOState::STIOCB NoteDoneReading;
+    static StoreIOState::STIOCB NoteDoneWriting;
+
+    void startReading();
+    void stopReading(const char *why);
+    void readMore(const char *why);
+    void noteRead(ssize_t result);
+    void noteDoneReading(int errflag);
+    void parseReadBytes();
+
+    void startWriting();
+    void noteDoneWriting(int errflag);
+
+    Rock::SwapDir::Pointer store; ///< cache_dir where the entry is stored
+    Ipc::StoreMapUpdate update; ///< Ipc::StoreMap update reservation
+
+    StoreIOState::Pointer reader; ///< reads old headers and old data
+    StoreIOState::Pointer writer; ///< writes new headers and old data
+
+    SBuf readerBuffer; ///< I/O buffer for a single read operation
+    SBuf exchangeBuffer; ///< bytes read but not yet discarded or written
+    uint64_t bytesRead; ///< total entry bytes read from Store so far
+
+    int staleSwapHeaderSize; ///< stored size of the stale entry metadata
+
+    SlotId staleSplicingPointNext; ///< non-updatable old HTTP body suffix start
+};
+
+} // namespace Rock
+
+#endif /* SQUID_FS_ROCK_HEADER_UPDATER_H */
+
diff -u -r -N squid-4.0.7/src/fs/rock/RockIoState.cc squid-4.0.8/src/fs/rock/RockIoState.cc
--- squid-4.0.7/src/fs/rock/RockIoState.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/fs/rock/RockIoState.cc	2016-04-02 10:04:07.000000000 +1300
@@ -30,10 +30,12 @@
     StoreIOState(cbFile, cbIo, data),
     readableAnchor_(NULL),
     writeableAnchor_(NULL),
-    sidCurrent(-1),
+    splicingPoint(-1),
+    staleSplicingPointNext(-1),
     dir(aDir),
     slotSize(dir->slotSize),
     objOffset(0),
+    sidCurrent(-1),
     theBuf(dir->slotSize)
 {
     e = anEntry;
@@ -132,6 +134,11 @@
 Rock::IoState::callReaderBack(const char *buf, int rlen)
 {
     debugs(79, 5, rlen << " bytes for " << *e);
+    splicingPoint = rlen >= 0 ? sidCurrent : -1;
+    if (splicingPoint < 0)
+        staleSplicingPointNext = -1;
+    else
+        staleSplicingPointNext = currentReadableSlice().next;
     StoreIOState::STRCB *callb = read.callback;
     assert(callb);
     read.callback = NULL;
@@ -150,7 +157,7 @@
         success = true;
     } catch (const std::exception &ex) { // TODO: should we catch ... as well?
         debugs(79, 2, "db write error: " << ex.what());
-        dir->writeError(*e);
+        dir->writeError(*this);
         finishedWriting(DISK_ERROR);
         // 'this' might be gone beyond this point; fall through to free buf
     }
@@ -202,7 +209,7 @@
             writeToDisk(sidNext);
         } else if (Store::Root().transientReaders(*e)) {
             // write partial buffer for all remote hit readers to see
-            writeBufToDisk(-1, false);
+            writeBufToDisk(-1, false, false);
         }
     }
 
@@ -231,15 +238,24 @@
 /// write what was buffered during write() calls
 /// negative sidNext means this is the last write request for this entry
 void
-Rock::IoState::writeToDisk(const SlotId sidNext)
+Rock::IoState::writeToDisk(const SlotId sidNextProposal)
 {
     assert(theFile != NULL);
     assert(theBuf.size >= sizeof(DbCellHeader));
 
+    const bool lastWrite = sidNextProposal < 0;
+    const bool eof = lastWrite &&
+                     // either not updating or the updating reader has loaded everything
+                     (touchingStoreEntry() || staleSplicingPointNext < 0);
+    // approve sidNextProposal unless _updating_ the last slot
+    const SlotId sidNext = (!touchingStoreEntry() && lastWrite) ?
+                           staleSplicingPointNext : sidNextProposal;
+    debugs(79, 5, "sidNext:" << sidNextProposal << "=>" << sidNext << " eof=" << eof);
+
     // TODO: if DiskIO module is mmap-based, we should be writing whole pages
     // to avoid triggering read-page;new_head+old_tail;write-page overheads
 
-    writeBufToDisk(sidNext, sidNext < 0);
+    writeBufToDisk(sidNext, eof, lastWrite);
     theBuf.clear();
 
     sidCurrent = sidNext;
@@ -248,7 +264,7 @@
 /// creates and submits a request to write current slot buffer to disk
 /// eof is true if and only this is the last slot
 void
-Rock::IoState::writeBufToDisk(const SlotId sidNext, bool eof)
+Rock::IoState::writeBufToDisk(const SlotId sidNext, const bool eof, const bool lastWrite)
 {
     // no slots after the last/eof slot (but partial slots may have a nil next)
     assert(!eof || sidNext < 0);
@@ -281,7 +297,7 @@
                        memFreeBufFunc(wBufCap)), this);
     r->sidCurrent = sidCurrent;
     r->sidNext = sidNext;
-    r->eof = eof;
+    r->eof = lastWrite;
 
     // theFile->write may call writeCompleted immediatelly
     theFile->write(r);
@@ -307,7 +323,8 @@
 {
     // we incremented offset_ while accumulating data in write()
     // we do not reset writeableAnchor_ here because we still keep the lock
-    CollapsedForwarding::Broadcast(*e);
+    if (touchingStoreEntry())
+        CollapsedForwarding::Broadcast(*e);
     callBack(errFlag);
 }
 
@@ -332,8 +349,7 @@
         return; // writeCompleted() will callBack()
 
     case writerGone:
-        assert(writeableAnchor_);
-        dir->writeError(*e); // abort a partially stored entry
+        dir->writeError(*this); // abort a partially stored entry
         finishedWriting(DISK_ERROR);
         return;
 
diff -u -r -N squid-4.0.7/src/fs/rock/RockIoState.h squid-4.0.8/src/fs/rock/RockIoState.h
--- squid-4.0.7/src/fs/rock/RockIoState.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/fs/rock/RockIoState.h	2016-04-02 10:04:07.000000000 +1300
@@ -10,7 +10,7 @@
 #define SQUID_FS_ROCK_IO_STATE_H
 
 #include "fs/rock/RockSwapDir.h"
-#include "MemBlob.h"
+#include "sbuf/MemBlob.h"
 
 class DiskFile;
 
@@ -51,7 +51,11 @@
     const Ipc::StoreMapAnchor *readableAnchor_; ///< starting point for reading
     Ipc::StoreMapAnchor *writeableAnchor_; ///< starting point for writing
 
-    SlotId sidCurrent; ///< ID of the db slot currently being read or written
+    /// the last db slot successfully read or written
+    SlotId splicingPoint;
+    /// when reading, this is the next slot we are going to read (if asked)
+    /// when writing, this is the next slot to use after the last fresh slot
+    SlotId staleSplicingPointNext;
 
 private:
     const Ipc::StoreMapAnchor &readAnchor() const;
@@ -61,7 +65,7 @@
     void tryWrite(char const *buf, size_t size, off_t offset);
     size_t writeToBuffer(char const *buf, size_t size);
     void writeToDisk(const SlotId nextSlot);
-    void writeBufToDisk(const SlotId nextSlot, const bool eof);
+    void writeBufToDisk(const SlotId nextSlot, const bool eof, const bool lastWrite);
     SlotId reserveSlotForWriting();
 
     void callBack(int errflag);
@@ -69,6 +73,7 @@
     Rock::SwapDir::Pointer dir; ///< swap dir that initiated I/O
     const size_t slotSize; ///< db cell size
     int64_t objOffset; ///< object offset for current db slot
+    SlotId sidCurrent; ///< ID of the db slot currently being read or written
 
     RefCount<DiskFile> theFile; // "file" responsible for this I/O
     MemBlob theBuf; // use for write content accumulation only
diff -u -r -N squid-4.0.7/src/fs/rock/RockRebuild.cc squid-4.0.8/src/fs/rock/RockRebuild.cc
--- squid-4.0.7/src/fs/rock/RockRebuild.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/fs/rock/RockRebuild.cc	2016-04-02 10:04:07.000000000 +1300
@@ -46,17 +46,15 @@
  *  have the same key and version. If that assumption fails, we may serve a
  *  hodgepodge entry during rebuild, until "extra" slots are loaded/noticed.
  \par
+ *  iNode: The very first db slot in an entry slot chain. This slot contains
+ *  at least the beginning of Store Entry metadata, but most 32KB inodes contain
+ *  the entire metadata, HTTP headers, and HTTP body.
+ \par
  *  Db slot: A db record containing a piece of a single store entry and linked
  *  to other slots with the same key and version fields, forming a chain.
  *  Slots are identified by their absolute position in the database file,
  *  which is naturally unique.
  \par
- *  Except for the "mapped", "freed", and "more" fields, LoadingEntry info is
- *  entry-level and is stored at fileno position. In other words, the array of
- *  LoadingEntries should be interpreted as two arrays, one that maps slot ID
- *  to the LoadingEntry::mapped/free/more members, and the second one that maps
- *  fileno to all other LoadingEntry members. StoreMap maps slot key to fileno.
- \par
  *  When information from the newly loaded db slot contradicts the entry-level
  *  information collected so far (e.g., the versions do not match or the total
  *  chain size after the slot contribution exceeds the expected number), the
@@ -76,35 +74,135 @@
 namespace Rock
 {
 
-/// maintains information about the store entry being loaded from disk
-/// used for identifying partially stored/loaded entries
-class LoadingEntry
+/// low-level anti-padding storage class for LoadingEntry and LoadingSlot flags
+class LoadingFlags
 {
 public:
-    LoadingEntry(): size(0), version(0), state(leEmpty), anchored(0),
-        mapped(0), freed(0), more(-1) {}
+    LoadingFlags(): state(0), anchored(0), mapped(0), finalized(0), freed(0) {}
 
-    /* store entry-level information indexed by sfileno */
-    uint64_t size; ///< payload seen so far
-    uint32_t version; ///< DbCellHeader::version to distinguish same-URL chains
-    uint8_t state:3;  ///< current entry state (one of the State values)
+    /* for LoadingEntry */
+    uint8_t state:3;  ///< current entry state (one of the LoadingEntry::State values)
     uint8_t anchored:1;  ///< whether we loaded the inode slot for this entry
 
-    /* db slot-level information indexed by slotId, starting with firstSlot */
-    uint8_t mapped:1;  ///< whether this slot was added to a mapped entry
-    uint8_t freed:1;  ///< whether this slot was marked as free
-    Ipc::StoreMapSliceId more; ///< another slot in some entry chain (unordered)
-    bool used() const { return freed || mapped || more != -1; }
+    /* for LoadingSlot */
+    uint8_t mapped:1;  ///< whether the slot was added to a mapped entry
+    uint8_t finalized:1;  ///< whether finalizeOrThrow() has scanned the slot
+    uint8_t freed:1;  ///< whether the slot was given to the map as free space
+};
+
+/// smart StoreEntry-level info pointer (hides anti-padding LoadingParts arrays)
+class LoadingEntry
+{
+public:
+    LoadingEntry(const sfileno fileNo, LoadingParts &source);
+
+    uint64_t &size; ///< payload seen so far
+    uint32_t &version; ///< DbCellHeader::version to distinguish same-URL chains
 
-    /// possible entry states
+    /// possible store entry states during index rebuild
     typedef enum { leEmpty = 0, leLoading, leLoaded, leCorrupted, leIgnored } State;
+
+    /* LoadingFlags::state */
+    State state() const { return static_cast<State>(flags.state); }
+    void state(State aState) const { flags.state = aState; }
+
+    /* LoadingFlags::anchored */
+    bool anchored() const { return flags.anchored; }
+    void anchored(const bool beAnchored) { flags.anchored = beAnchored; }
+
+private:
+    LoadingFlags &flags; ///< entry flags (see the above accessors) are ours
+};
+
+/// smart db slot-level info pointer (hides anti-padding LoadingParts arrays)
+class LoadingSlot
+{
+public:
+    LoadingSlot(const SlotId slotId, LoadingParts &source);
+
+    /// another slot in some chain belonging to the same entry (unordered!)
+    Ipc::StoreMapSliceId &more;
+
+    /* LoadingFlags::mapped */
+    bool mapped() const { return flags.mapped; }
+    void mapped(const bool beMapped) { flags.mapped = beMapped; }
+
+    /* LoadingFlags::finalized */
+    bool finalized() const { return flags.finalized; }
+    void finalized(const bool beFinalized) { flags.finalized = beFinalized; }
+
+    /* LoadingFlags::freed */
+    bool freed() const { return flags.freed; }
+    void freed(const bool beFreed) { flags.freed = beFreed; }
+
+    bool used() const { return freed() || mapped() || more != -1; }
+
+private:
+    LoadingFlags &flags; ///< slot flags (see the above accessors) are ours
+};
+
+/// information about store entries being loaded from disk (and their slots)
+/// used for identifying partially stored/loaded entries
+class LoadingParts
+{
+public:
+    LoadingParts(int dbSlotLimit, int dbEntryLimit);
+    LoadingParts(LoadingParts&&) = delete; // paranoid (often too huge to copy)
+
+private:
+    friend class LoadingEntry;
+    friend class LoadingSlot;
+
+    /* Anti-padding storage. With millions of entries, padding matters! */
+
+    /* indexed by sfileno */
+    std::vector<uint64_t> sizes; ///< LoadingEntry::size for all entries
+    std::vector<uint32_t> versions; ///< LoadingEntry::version for all entries
+
+    /* indexed by SlotId */
+    std::vector<Ipc::StoreMapSliceId> mores; ///< LoadingSlot::more for all slots
+
+    /* entry flags are indexed by sfileno; slot flags -- by SlotId */
+    std::vector<LoadingFlags> flags; ///< all LoadingEntry and LoadingSlot flags
 };
 
 } /* namespace Rock */
 
+/* LoadingEntry */
+
+Rock::LoadingEntry::LoadingEntry(const sfileno fileNo, LoadingParts &source):
+    size(source.sizes.at(fileNo)),
+    version(source.versions.at(fileNo)),
+    flags(source.flags.at(fileNo))
+{
+}
+
+/* LoadingSlot */
+
+Rock::LoadingSlot::LoadingSlot(const SlotId slotId, LoadingParts &source):
+    more(source.mores.at(slotId)),
+    flags(source.flags.at(slotId))
+{
+}
+
+/* LoadingParts */
+
+Rock::LoadingParts::LoadingParts(const int dbEntryLimit, const int dbSlotLimit):
+    sizes(dbEntryLimit, 0),
+    versions(dbEntryLimit, 0),
+    mores(dbSlotLimit, -1),
+    flags(dbSlotLimit)
+{
+    assert(sizes.size() == versions.size()); // every entry has both fields
+    assert(sizes.size() <= mores.size()); // every entry needs slot(s)
+    assert(mores.size() == flags.size()); // every slot needs a set of flags
+}
+
+/* Rebuild */
+
 Rock::Rebuild::Rebuild(SwapDir *dir): AsyncJob("Rock::Rebuild"),
     sd(dir),
-    entries(NULL),
+    parts(nullptr),
     dbSize(0),
     dbSlotSize(0),
     dbSlotLimit(0),
@@ -127,7 +225,7 @@
 {
     if (fd >= 0)
         file_close(fd);
-    delete[] entries;
+    delete parts;
 }
 
 /// prepares and initiates entry loading sequence
@@ -159,7 +257,7 @@
 
     dbOffset = SwapDir::HeaderSize;
 
-    entries = new LoadingEntry[dbSlotLimit];
+    parts = new LoadingParts(dbEntryLimit, dbSlotLimit);
 
     checkpoint();
 }
@@ -173,10 +271,23 @@
 }
 
 bool
+Rock::Rebuild::doneLoading() const
+{
+    return loadingPos >= dbSlotLimit;
+}
+
+bool
+Rock::Rebuild::doneValidating() const
+{
+    // paranoid slot checking is only enabled with squid -S
+    return validationPos >= dbEntryLimit +
+           (opt_store_doublecheck ? dbSlotLimit : 0);
+}
+
+bool
 Rock::Rebuild::doneAll() const
 {
-    return loadingPos >= dbSlotLimit && validationPos >= dbSlotLimit &&
-           AsyncJob::doneAll();
+    return doneLoading() && doneValidating() && AsyncJob::doneAll();
 }
 
 void
@@ -189,7 +300,7 @@
 void
 Rock::Rebuild::steps()
 {
-    if (loadingPos < dbSlotLimit)
+    if (!doneLoading())
         loadingSteps();
     else
         validationSteps();
@@ -210,7 +321,7 @@
     const timeval loopStart = current_time;
 
     int loaded = 0;
-    while (loadingPos < dbSlotLimit) {
+    while (!doneLoading()) {
         loadOneSlot();
         dbOffset += dbSlotSize;
         ++loadingPos;
@@ -232,6 +343,21 @@
     }
 }
 
+Rock::LoadingEntry
+Rock::Rebuild::loadingEntry(const sfileno fileNo)
+{
+    Must(0 <= fileNo && fileNo < dbEntryLimit);
+    return LoadingEntry(fileNo, *parts);
+}
+
+Rock::LoadingSlot
+Rock::Rebuild::loadingSlot(const SlotId slotId)
+{
+    Must(0 <= slotId && slotId < dbSlotLimit);
+    Must(slotId <= loadingPos); // cannot look ahead
+    return LoadingSlot(slotId, *parts);
+}
+
 void
 Rock::Rebuild::loadOneSlot()
 {
@@ -256,18 +382,18 @@
         debugs(47, DBG_IMPORTANT, "WARNING: cache_dir[" << sd->index << "]: " <<
                "Ignoring truncated " << buf.contentSize() << "-byte " <<
                "cache entry meta data at " << dbOffset);
-        freeSlotIfIdle(slotId, true);
+        freeUnusedSlot(slotId, true);
         return;
     }
     memcpy(&header, buf.content(), sizeof(header));
     if (header.empty()) {
-        freeSlotIfIdle(slotId, false);
+        freeUnusedSlot(slotId, false);
         return;
     }
     if (!header.sane(dbSlotSize, dbSlotLimit)) {
         debugs(47, DBG_IMPORTANT, "WARNING: cache_dir[" << sd->index << "]: " <<
                "Ignoring malformed cache entry meta data at " << dbOffset);
-        freeSlotIfIdle(slotId, true);
+        freeUnusedSlot(slotId, true);
         return;
     }
     buf.consume(sizeof(header)); // optimize to avoid memmove()
@@ -286,9 +412,10 @@
     if (!storeRebuildParseEntry(buf, loadedE, key, counts, knownSize))
         return false;
 
-    // the entry size may still be unknown at this time
+    // the entry size may be unknown, but if it is known, it is authoritative
 
     debugs(47, 8, "importing basics for entry " << fileno <<
+           " inode.entrySize: " << header.entrySize <<
            " swap_file_sz: " << loadedE.swap_file_sz);
     anchor.set(loadedE);
 
@@ -310,8 +437,11 @@
     const timeval loopStart = current_time;
 
     int validated = 0;
-    while (validationPos < dbSlotLimit) {
-        validateOneEntry();
+    while (!doneValidating()) {
+        if (validationPos < dbEntryLimit)
+            validateOneEntry(validationPos);
+        else
+            validateOneSlot(validationPos - dbEntryLimit);
         ++validationPos;
         ++validated;
 
@@ -331,27 +461,78 @@
     }
 }
 
+/// Either make the entry accessible to all or throw.
+/// This method assumes it is called only when no more entry slots are expected.
 void
-Rock::Rebuild::validateOneEntry()
+Rock::Rebuild::finalizeOrThrow(const sfileno fileNo, LoadingEntry &le)
 {
-    LoadingEntry &e = entries[validationPos];
-    switch (e.state) {
+    // walk all map-linked slots, starting from inode, and mark each
+    Ipc::StoreMapAnchor &anchor = sd->map->writeableEntry(fileNo);
+    Must(le.size > 0); // paranoid
+    uint64_t mappedSize = 0;
+    SlotId slotId = anchor.start;
+    while (slotId >= 0 && mappedSize < le.size) {
+        LoadingSlot slot = loadingSlot(slotId); // throws if we have not loaded that slot
+        Must(!slot.finalized()); // no loops or stealing from other entries
+        Must(slot.mapped()); // all our slots should be in the sd->map
+        Must(!slot.freed()); // all our slots should still be present
+        slot.finalized(true);
 
-    case LoadingEntry::leEmpty:
-        break; // no entry hashed to this position
+        Ipc::StoreMapSlice &mapSlice = sd->map->writeableSlice(fileNo, slotId);
+        Must(mapSlice.size > 0); // paranoid
+        mappedSize += mapSlice.size;
+        slotId = mapSlice.next;
+    }
+    /* no hodgepodge entries: one entry - one full chain and no leftovers */
+    Must(slotId < 0);
+    Must(mappedSize == le.size);
+
+    if (!anchor.basics.swap_file_sz)
+        anchor.basics.swap_file_sz = le.size;
+    EBIT_SET(anchor.basics.flags, ENTRY_VALIDATED);
+    le.state(LoadingEntry::leLoaded);
+    sd->map->closeForWriting(fileNo, false);
+    ++counts.objcount;
+}
+
+/// Either make the entry accessible to all or free it.
+/// This method must only be called when no more entry slots are expected.
+void
+Rock::Rebuild::finalizeOrFree(const sfileno fileNo, LoadingEntry &le)
+{
+    try {
+        finalizeOrThrow(fileNo, le);
+    } catch (const std::exception &ex) {
+        freeBadEntry(fileNo, ex.what());
+    }
+}
+
+void
+Rock::Rebuild::validateOneEntry(const sfileno fileNo)
+{
+    LoadingEntry entry = loadingEntry(fileNo);
+    switch (entry.state()) {
 
     case LoadingEntry::leLoading:
-        freeBadEntry(validationPos, "partially stored");
+        finalizeOrFree(fileNo, entry);
         break;
 
-    case LoadingEntry::leLoaded:
-        break; // we have already unlocked this entry
-
-    case LoadingEntry::leCorrupted:
-        break; // we have already removed this entry
+    case LoadingEntry::leEmpty: // no entry hashed to this position
+    case LoadingEntry::leLoaded: // we have already unlocked this entry
+    case LoadingEntry::leCorrupted: // we have already removed this entry
+    case LoadingEntry::leIgnored: // we have already discarded this entry
+        break;
     }
 }
 
+void
+Rock::Rebuild::validateOneSlot(const SlotId slotId)
+{
+    const LoadingSlot slot = loadingSlot(slotId);
+    // there should not be any unprocessed slots left
+    Must(slot.freed() || (slot.mapped() && slot.finalized()));
+}
+
 /// Marks remaining bad entry slots as free and unlocks the entry. The map
 /// cannot do this because Loading entries may have holes in the slots chain.
 void
@@ -360,26 +541,18 @@
     debugs(47, 2, "cache_dir #" << sd->index << ' ' << eDescription <<
            " entry " << fileno << " is ignored during rebuild");
 
-    Ipc::StoreMapAnchor &anchor = sd->map->writeableEntry(fileno);
+    LoadingEntry le = loadingEntry(fileno);
+    le.state(LoadingEntry::leCorrupted);
 
-    bool freedSome = false;
-    // free all loaded non-anchor slots
-    SlotId slotId = entries[anchor.start].more;
-    while (slotId >= 0) {
-        const SlotId next = entries[slotId].more;
-        freeSlot(slotId, false);
+    Ipc::StoreMapAnchor &anchor = sd->map->writeableEntry(fileno);
+    assert(anchor.start < 0 || le.size > 0);
+    for (SlotId slotId = anchor.start; slotId >= 0;) {
+        const SlotId next = loadingSlot(slotId).more;
+        freeSlot(slotId, true);
         slotId = next;
-        freedSome = true;
     }
-    // free anchor slot if it was loaded
-    if (entries[fileno].anchored) {
-        freeSlot(anchor.start, false);
-        freedSome = true;
-    }
-    assert(freedSome);
 
     sd->map->forgetWritingEntry(fileno);
-    ++counts.invalid;
 }
 
 void
@@ -411,9 +584,9 @@
 Rock::Rebuild::freeSlot(const SlotId slotId, const bool invalid)
 {
     debugs(47,5, sd->index << " frees slot " << slotId);
-    LoadingEntry &le = entries[slotId];
-    assert(!le.freed);
-    le.freed = 1;
+    LoadingSlot slot = loadingSlot(slotId);
+    assert(!slot.freed());
+    slot.freed(true);
 
     if (invalid) {
         ++counts.invalid;
@@ -426,27 +599,24 @@
     sd->freeSlots->push(pageId);
 }
 
-/// adds slot to the free slot index but only if the slot is unused
+/// freeSlot() for never-been-mapped slots
 void
-Rock::Rebuild::freeSlotIfIdle(const SlotId slotId, const bool invalid)
+Rock::Rebuild::freeUnusedSlot(const SlotId slotId, const bool invalid)
 {
-    const LoadingEntry &le = entries[slotId];
-
+    LoadingSlot slot = loadingSlot(slotId);
     // mapped slots must be freed via freeBadEntry() to keep the map in sync
-    assert(!le.mapped);
-
-    if (!le.used())
-        freeSlot(slotId, invalid);
+    assert(!slot.mapped());
+    freeSlot(slotId, invalid);
 }
 
 /// adds slot to the entry chain in the map
 void
 Rock::Rebuild::mapSlot(const SlotId slotId, const DbCellHeader &header)
 {
-    LoadingEntry &le = entries[slotId];
-    assert(!le.mapped);
-    assert(!le.freed);
-    le.mapped = 1;
+    LoadingSlot slot = loadingSlot(slotId);
+    assert(!slot.mapped());
+    assert(!slot.freed());
+    slot.mapped(true);
 
     Ipc::StoreMapSlice slice;
     slice.next = header.nextSlot;
@@ -454,73 +624,75 @@
     sd->map->importSlice(slotId, slice);
 }
 
+template <class SlotIdType> // accommodates atomic and simple SlotIds.
+void
+Rock::Rebuild::chainSlots(SlotIdType &from, const SlotId to)
+{
+    LoadingSlot slot = loadingSlot(to);
+    assert(slot.more < 0);
+    slot.more = from; // may still be unset
+    from = to;
+}
+
 /// adds slot to an existing entry chain; caller must check that the slot
 /// belongs to the chain it is being added to
 void
 Rock::Rebuild::addSlotToEntry(const sfileno fileno, const SlotId slotId, const DbCellHeader &header)
 {
-    LoadingEntry &le = entries[fileno];
+    LoadingEntry le = loadingEntry(fileno);
     Ipc::StoreMapAnchor &anchor = sd->map->writeableEntry(fileno);
 
-    assert(le.version == header.version);
-
-    // mark anchor as loaded or add the secondary slot to the chain
-    LoadingEntry &inode = entries[header.firstSlot];
-    if (header.firstSlot == slotId) {
-        debugs(47,5, "adding inode");
-        assert(!inode.freed);
-        le.anchored = 1;
+    debugs(47,9, "adding " << slotId << " to entry " << fileno);
+    // we do not need to preserve the order
+    if (le.anchored()) {
+        LoadingSlot inode = loadingSlot(anchor.start);
+        chainSlots(inode.more, slotId);
     } else {
-        debugs(47,9, "linking " << slotId << " to " << inode.more);
-        // we do not need to preserve the order
-        LoadingEntry &slice = entries[slotId];
-        assert(!slice.freed);
-        assert(slice.more < 0);
-        slice.more = inode.more;
-        inode.more = slotId;
+        chainSlots(anchor.start, slotId);
     }
 
-    if (header.firstSlot == slotId && !importEntry(anchor, fileno, header)) {
-        le.state = LoadingEntry::leCorrupted;
-        freeBadEntry(fileno, "corrupted metainfo");
-        return;
-    }
+    le.size += header.payloadSize; // must precede freeBadEntry() calls
 
-    // set total entry size and/or check it for consistency
-    debugs(47, 8, "header.entrySize: " << header.entrySize << " swap_file_sz: " << anchor.basics.swap_file_sz);
-    uint64_t totalSize = header.entrySize;
-    assert(totalSize != static_cast<uint64_t>(-1));
-    if (!totalSize && anchor.basics.swap_file_sz) {
-        assert(anchor.basics.swap_file_sz != static_cast<uint64_t>(-1));
-        // perhaps we loaded a later slot (with entrySize) earlier
-        totalSize = anchor.basics.swap_file_sz;
-    } else if (totalSize && !anchor.basics.swap_file_sz) {
-        anchor.basics.swap_file_sz = totalSize;
-        assert(anchor.basics.swap_file_sz != static_cast<uint64_t>(-1));
-    } else if (totalSize != anchor.basics.swap_file_sz) {
-        le.state = LoadingEntry::leCorrupted;
-        freeBadEntry(fileno, "size mismatch");
-        return;
+    if (header.firstSlot == slotId) {
+        debugs(47,5, "added inode");
+
+        if (le.anchored()) { // we have already added another inode slot
+            freeBadEntry(fileno, "inode conflict");
+            ++counts.clashcount;
+            return;
+        }
+
+        le.anchored(true);
+
+        if (!importEntry(anchor, fileno, header)) {
+            freeBadEntry(fileno, "corrupted metainfo");
+            return;
+        }
+
+        // set total entry size and/or check it for consistency
+        if (const uint64_t totalSize = header.entrySize) {
+            assert(totalSize != static_cast<uint64_t>(-1));
+            if (!anchor.basics.swap_file_sz) {
+                anchor.basics.swap_file_sz = totalSize;
+                assert(anchor.basics.swap_file_sz != static_cast<uint64_t>(-1));
+            } else if (totalSize != anchor.basics.swap_file_sz) {
+                freeBadEntry(fileno, "size mismatch");
+                return;
+            }
+        }
     }
 
-    le.size += header.payloadSize;
+    const uint64_t totalSize = anchor.basics.swap_file_sz; // may be 0/unknown
 
     if (totalSize > 0 && le.size > totalSize) { // overflow
         debugs(47, 8, "overflow: " << le.size << " > " << totalSize);
-        le.state = LoadingEntry::leCorrupted;
         freeBadEntry(fileno, "overflowing");
         return;
     }
 
     mapSlot(slotId, header);
-    if (totalSize > 0 && le.size == totalSize) {
-        // entry fully loaded, unlock it
-        // we have validated that all db cells for this entry were loaded
-        EBIT_SET(anchor.basics.flags, ENTRY_VALIDATED);
-        le.state = LoadingEntry::leLoaded;
-        sd->map->closeForWriting(fileno, false);
-        ++counts.objcount;
-    }
+    if (totalSize > 0 && le.size == totalSize)
+        finalizeOrFree(fileno, le); // entry is probably fully loaded now
 }
 
 /// initialize housekeeping information for a newly accepted entry
@@ -529,12 +701,12 @@
 {
     anchor.setKey(reinterpret_cast<const cache_key*>(header.key));
     assert(header.firstSlot >= 0);
-    anchor.start = header.firstSlot;
+    anchor.start = -1; // addSlotToEntry() will set it
 
     assert(anchor.basics.swap_file_sz != static_cast<uint64_t>(-1));
 
-    LoadingEntry &le = entries[fileno];
-    le.state = LoadingEntry::leLoading;
+    LoadingEntry le = loadingEntry(fileno);
+    le.state(LoadingEntry::leLoading);
     le.version = header.version;
     le.size = 0;
 }
@@ -543,22 +715,6 @@
 void
 Rock::Rebuild::startNewEntry(const sfileno fileno, const SlotId slotId, const DbCellHeader &header)
 {
-    // If some other from-disk entry is/was using this slot as its inode OR
-    // if some other from-disk entry is/was using our inode slot, then the
-    // entries are conflicting. We cannot identify other entries, so we just
-    // remove ours and hope that the others were/will be handled correctly.
-    const LoadingEntry &slice = entries[slotId];
-    const LoadingEntry &inode = entries[header.firstSlot];
-    if (slice.used() || inode.used()) {
-        debugs(47,8, "slice/inode used: " << slice.used() << inode.used());
-        LoadingEntry &le = entries[fileno];
-        le.state = LoadingEntry::leCorrupted;
-        freeSlotIfIdle(slotId, slotId == header.firstSlot);
-        // if not idle, the other entry will handle its slice
-        ++counts.clashcount;
-        return;
-    }
-
     // A miss may have been stored at our fileno while we were loading other
     // slots from disk. We ought to preserve that entry because it is fresher.
     const bool overwriteExisting = false;
@@ -569,9 +725,9 @@
     } else {
         // A new from-network entry is occupying our map slot; let it be, but
         // save us from the trouble of going through the above motions again.
-        LoadingEntry &le = entries[fileno];
-        le.state = LoadingEntry::leIgnored;
-        freeSlotIfIdle(slotId, false);
+        LoadingEntry le = loadingEntry(fileno);
+        le.state(LoadingEntry::leIgnored);
+        freeUnusedSlot(slotId, false);
     }
 }
 
@@ -579,72 +735,26 @@
 bool
 Rock::Rebuild::sameEntry(const sfileno fileno, const DbCellHeader &header) const
 {
+    // Header updates always result in multi-start chains and often
+    // result in multi-version chains so we can only compare the keys.
     const Ipc::StoreMap::Anchor &anchor = sd->map->writeableEntry(fileno);
-    const LoadingEntry &le = entries[fileno];
-    // any order will work, but do fast comparisons first:
-    return le.version == header.version &&
-           anchor.start == static_cast<Ipc::StoreMapSliceId>(header.firstSlot) &&
-           anchor.sameKey(reinterpret_cast<const cache_key*>(header.key));
-}
-
-/// is the new header consistent with information already loaded?
-bool
-Rock::Rebuild::canAdd(const sfileno fileno, const SlotId slotId, const DbCellHeader &header) const
-{
-    if (!sameEntry(fileno, header)) {
-        debugs(79, 7, "cannot add; wrong entry");
-        return false;
-    }
-
-    const LoadingEntry &le = entries[slotId];
-    // We cannot add a slot that was already declared free or mapped.
-    if (le.freed || le.mapped) {
-        debugs(79, 7, "cannot add; freed/mapped: " << le.freed << le.mapped);
-        return false;
-    }
-
-    if (slotId == header.firstSlot) {
-        // If we are the inode, the anchored flag cannot be set yet.
-        if (entries[fileno].anchored) {
-            debugs(79, 7, "cannot add; extra anchor");
-            return false;
-        }
-
-        // And there should have been some other slot for this entry to exist.
-        if (le.more < 0) {
-            debugs(79, 7, "cannot add; missing slots");
-            return false;
-        }
-
-        return true;
-    }
-
-    // We are the continuation slice so the more field is reserved for us.
-    if (le.more >= 0) {
-        debugs(79, 7, "cannot add; foreign slot");
-        return false;
-    }
-
-    return true;
+    return anchor.sameKey(reinterpret_cast<const cache_key*>(header.key));
 }
 
 /// handle freshly loaded (and validated) db slot header
 void
 Rock::Rebuild::useNewSlot(const SlotId slotId, const DbCellHeader &header)
 {
-    LoadingEntry &slice = entries[slotId];
-    assert(!slice.freed); // we cannot free what was not loaded
-
     const cache_key *const key =
         reinterpret_cast<const cache_key*>(header.key);
-    const sfileno fileno = sd->map->anchorIndexByKey(key);
+    const sfileno fileno = sd->map->fileNoByKey(key);
     assert(0 <= fileno && fileno < dbEntryLimit);
 
-    LoadingEntry &le = entries[fileno];
-    debugs(47,9, "entry " << fileno << " state: " << le.state << ", inode: " <<
+    LoadingEntry le = loadingEntry(fileno);
+    debugs(47,9, "entry " << fileno << " state: " << le.state() << ", inode: " <<
            header.firstSlot << ", size: " << header.payloadSize);
 
-    switch (le.state) {
+    switch (le.state()) {
 
     case LoadingEntry::leEmpty: {
         startNewEntry(fileno, slotId, header);
@@ -652,14 +762,13 @@
     }
 
     case LoadingEntry::leLoading: {
-        if (canAdd(fileno, slotId, header)) {
-            addSlotToEntry(fileno, slotId, header);
+        if (sameEntry(fileno, header)) {
+            addSlotToEntry(fileno, slotId, header); // may fail
         } else {
             // either the loading chain or this slot is stale;
             // be conservative and ignore both (and any future ones)
-            le.state = LoadingEntry::leCorrupted;
             freeBadEntry(fileno, "duplicated");
-            freeSlotIfIdle(slotId, slotId == header.firstSlot);
+            freeUnusedSlot(slotId, true);
             ++counts.dupcount;
         }
         break;
@@ -668,22 +777,22 @@
     case LoadingEntry::leLoaded: {
         // either the previously loaded chain or this slot is stale;
         // be conservative and ignore both (and any future ones)
-        le.state = LoadingEntry::leCorrupted;
+        le.state(LoadingEntry::leCorrupted);
         sd->map->freeEntry(fileno); // may not be immediately successful
-        freeSlotIfIdle(slotId, slotId == header.firstSlot);
+        freeUnusedSlot(slotId, true);
         ++counts.dupcount;
         break;
     }
 
     case LoadingEntry::leCorrupted: {
         // previously seen slots messed things up so we must ignore this one
-        freeSlotIfIdle(slotId, false);
+        freeUnusedSlot(slotId, true);
         break;
     }
 
     case LoadingEntry::leIgnored: {
         // already replaced by a fresher or colliding from-network entry
-        freeSlotIfIdle(slotId, false);
+        freeUnusedSlot(slotId, false);
         break;
     }
     }
diff -u -r -N squid-4.0.7/src/fs/rock/RockRebuild.h squid-4.0.8/src/fs/rock/RockRebuild.h
--- squid-4.0.7/src/fs/rock/RockRebuild.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/fs/rock/RockRebuild.h	2016-04-02 10:04:07.000000000 +1300
@@ -19,22 +19,27 @@
 {
 
 class LoadingEntry;
+class LoadingSlot;
+class LoadingParts;
 
 /// \ingroup Rock
 /// manages store rebuild process: loading meta information from db on disk
 class Rebuild: public AsyncJob
 {
-    CBDATA_CLASS(Rebuild);
+    CBDATA_CHILD(Rebuild);
 
 public:
     Rebuild(SwapDir *dir);
-    ~Rebuild();
+    virtual ~Rebuild() override;
 
 protected:
     /* AsyncJob API */
-    virtual void start();
-    virtual bool doneAll() const;
-    virtual void swanSong();
+    virtual void start() override;
+    virtual bool doneAll() const override;
+    virtual void swanSong() override;
+
+    bool doneLoading() const;
+    bool doneValidating() const;
 
 private:
     void checkpoint();
@@ -42,27 +47,33 @@
     void loadingSteps();
     void validationSteps();
     void loadOneSlot();
-    void validateOneEntry();
+    void validateOneEntry(const sfileno fileNo);
+    void validateOneSlot(const SlotId slotId);
     bool importEntry(Ipc::StoreMapAnchor &anchor, const sfileno slotId, const DbCellHeader &header);
     void freeBadEntry(const sfileno fileno, const char *eDescription);
 
     void failure(const char *msg, int errNo = 0);
 
+    LoadingEntry loadingEntry(const sfileno fileNo);
     void startNewEntry(const sfileno fileno, const SlotId slotId, const DbCellHeader &header);
     void primeNewEntry(Ipc::StoreMapAnchor &anchor, const sfileno fileno, const DbCellHeader &header);
+    void finalizeOrFree(const sfileno fileNo, LoadingEntry &le);
+    void finalizeOrThrow(const sfileno fileNo, LoadingEntry &le);
     void addSlotToEntry(const sfileno fileno, const SlotId slotId, const DbCellHeader &header);
     void useNewSlot(const SlotId slotId, const DbCellHeader &header);
 
+    LoadingSlot loadingSlot(const SlotId slotId);
     void mapSlot(const SlotId slotId, const DbCellHeader &header);
-    void freeSlotIfIdle(const SlotId slotId, const bool invalid);
-    void freeBusySlot(const SlotId slotId, const bool invalid);
+    void freeUnusedSlot(const SlotId slotId, const bool invalid);
     void freeSlot(const SlotId slotId, const bool invalid);
 
-    bool canAdd(const sfileno fileno, const SlotId slotId, const DbCellHeader &header) const;
+    template <class SlotIdType>
+    void chainSlots(SlotIdType &from, const SlotId to);
+
     bool sameEntry(const sfileno fileno, const DbCellHeader &header) const;
 
     SwapDir *sd;
-    LoadingEntry *entries; ///< store entries being loaded from disk
+    LoadingParts *parts; ///< parts of store entries being loaded from disk
 
     int64_t dbSize;
     int dbSlotSize; ///< the size of a db cell, including the cell header
diff -u -r -N squid-4.0.7/src/fs/rock/RockSwapDir.cc squid-4.0.8/src/fs/rock/RockSwapDir.cc
--- squid-4.0.7/src/fs/rock/RockSwapDir.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/fs/rock/RockSwapDir.cc	2016-04-02 10:04:07.000000000 +1300
@@ -16,6 +16,7 @@
 #include "DiskIO/DiskIOStrategy.h"
 #include "DiskIO/ReadRequest.h"
 #include "DiskIO/WriteRequest.h"
+#include "fs/rock/RockHeaderUpdater.h"
 #include "fs/rock/RockIoRequests.h"
 #include "fs/rock/RockIoState.h"
 #include "fs/rock/RockRebuild.h"
@@ -666,6 +667,33 @@
     return sio;
 }
 
+StoreIOState::Pointer
+Rock::SwapDir::createUpdateIO(const Ipc::StoreMapUpdate &update, StoreIOState::STFNCB *cbFile, StoreIOState::STIOCB *cbIo, void *data)
+{
+    if (!theFile || theFile->error()) {
+        debugs(47,4, theFile);
+        return nullptr;
+    }
+
+    Must(update.fresh);
+    Must(update.fresh.fileNo >= 0);
+
+    Rock::SwapDir::Pointer self(this);
+    IoState *sio = new IoState(self, update.entry, cbFile, cbIo, data);
+
+    sio->swap_dirn = index;
+    sio->swap_filen = update.fresh.fileNo;
+    sio->writeableAnchor_ = update.fresh.anchor;
+
+    debugs(47,5, "dir " << index << " updating filen " <<
+           std::setfill('0') << std::hex << std::uppercase << std::setw(8) <<
+           sio->swap_filen << std::dec << " starting at " <<
+           diskOffset(sio->swap_filen));
+
+    sio->file(theFile);
+    return sio;
+}
+
 int64_t
 Rock::SwapDir::diskOffset(const SlotId sid) const
 {
@@ -832,6 +860,8 @@
         return;
     }
 
+    debugs(79, 7, "errflag=" << errflag << " rlen=" << request->len << " eof=" << request->eof);
+
     // TODO: Fail if disk dropped one of the previous write requests.
 
     if (errflag == DISK_OK) {
@@ -846,37 +876,61 @@
         if (request->eof) {
             assert(sio.e);
             assert(sio.writeableAnchor_);
-            sio.e->swap_file_sz = sio.writeableAnchor_->basics.swap_file_sz =
-                                      sio.offset_;
-
-            // close, the entry gets the read lock
-            map->closeForWriting(sio.swap_filen, true);
+            if (sio.touchingStoreEntry()) {
+                sio.e->swap_file_sz = sio.writeableAnchor_->basics.swap_file_sz =
+                                          sio.offset_;
+
+                // close, the entry gets the read lock
+                map->closeForWriting(sio.swap_filen, true);
+            }
             sio.writeableAnchor_ = NULL;
+            sio.splicingPoint = request->sidCurrent;
             sio.finishedWriting(errflag);
         }
     } else {
         noteFreeMapSlice(request->sidNext);
 
-        writeError(*sio.e);
+        writeError(sio);
         sio.finishedWriting(errflag);
         // and hope that Core will call disconnect() to close the map entry
     }
 
-    CollapsedForwarding::Broadcast(*sio.e);
+    if (sio.touchingStoreEntry())
+        CollapsedForwarding::Broadcast(*sio.e);
 }
 
 void
-Rock::SwapDir::writeError(StoreEntry &e)
+Rock::SwapDir::writeError(StoreIOState &sio)
 {
     // Do not abortWriting here. The entry should keep the write lock
     // instead of losing association with the store and confusing core.
-    map->freeEntry(e.swap_filen); // will mark as unusable, just in case
+    map->freeEntry(sio.swap_filen); // will mark as unusable, just in case
 
-    Store::Root().transientsAbandon(e);
+    if (sio.touchingStoreEntry())
+        Store::Root().transientsAbandon(*sio.e);
+    // else noop: a fresh entry update error does not affect stale entry readers
 
     // All callers must also call IoState callback, to propagate the error.
 }
 
+void
+Rock::SwapDir::updateHeaders(StoreEntry *updatedE)
+{
+    if (!map)
+        return;
+
+    Ipc::StoreMapUpdate update(updatedE);
+    if (!map->openForUpdating(update, updatedE->swap_filen))
+        return;
+
+    try {
+        AsyncJob::Start(new HeaderUpdater(this, update));
+    } catch (const std::exception &ex) {
+        debugs(20, 2, "error starting to update entry " << *updatedE << ": " << ex.what());
+        map->abortUpdating(update);
+    }
+}
+
 bool
 Rock::SwapDir::full() const
 {
diff -u -r -N squid-4.0.7/src/fs/rock/RockSwapDir.h squid-4.0.8/src/fs/rock/RockSwapDir.h
--- squid-4.0.7/src/fs/rock/RockSwapDir.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/fs/rock/RockSwapDir.h	2016-04-02 10:04:07.000000000 +1300
@@ -67,7 +67,7 @@
 
     int64_t diskOffset(Ipc::Mem::PageId &pageId) const;
     int64_t diskOffset(int filen) const;
-    void writeError(StoreEntry &e);
+    void writeError(StoreIOState &sio);
 
     /* StoreMapCleaner API */
     virtual void noteFreeMapSlice(const Ipc::StoreMapSliceId fileno);
@@ -91,6 +91,7 @@
     virtual void diskFull();
     virtual void reference(StoreEntry &e);
     virtual bool dereference(StoreEntry &e);
+    virtual void updateHeaders(StoreEntry *e);
     virtual bool unlinkdUseful() const;
     virtual void unlink(StoreEntry &e);
     virtual void statfs(StoreEntry &e) const;
@@ -118,11 +119,15 @@
 
     int64_t diskOffsetLimit() const;
 
+    void updateHeadersOrThrow(Ipc::StoreMapUpdate &update);
+    StoreIOState::Pointer createUpdateIO(const Ipc::StoreMapUpdate &update, StoreIOState::STFNCB *, StoreIOState::STIOCB *, void *);
+
     void anchorEntry(StoreEntry &e, const sfileno filen, const Ipc::StoreMapAnchor &anchor);
     bool updateCollapsedWith(StoreEntry &collapsed, const Ipc::StoreMapAnchor &anchor);
 
     friend class Rebuild;
     friend class IoState;
+    friend class HeaderUpdater;
     const char *filePath; ///< location of cache storage file inside path/
     DirMap *map; ///< entry key/sfileno to MaxExtras/inode mapping
 
diff -u -r -N squid-4.0.7/src/ftp/Elements.cc squid-4.0.8/src/ftp/Elements.cc
--- squid-4.0.7/src/ftp/Elements.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/ftp/Elements.cc	2016-04-02 10:04:07.000000000 +1300
@@ -12,7 +12,7 @@
 #include "ftp/Elements.h"
 #include "HttpHdrCc.h"
 #include "HttpReply.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 // FTP does not have a notion of a "protocol version" but we need something for
 // compatibility with the current HttpMsg wrapping layer. We use version 1.1:
diff -u -r -N squid-4.0.7/src/ftp/Elements.h squid-4.0.8/src/ftp/Elements.h
--- squid-4.0.7/src/ftp/Elements.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/ftp/Elements.h	2016-04-02 10:04:07.000000000 +1300
@@ -10,8 +10,8 @@
 #define SQUID_FTP_ELEMENTS_H
 
 #include "http/StatusCode.h"
+#include "sbuf/forward.h"
 
-class SBuf;
 class HttpReply;
 
 namespace AnyP
diff -u -r -N squid-4.0.7/src/ftp/Makefile.in squid-4.0.8/src/ftp/Makefile.in
--- squid-4.0.7/src/ftp/Makefile.in	2016-02-24 06:49:34.000000000 +1300
+++ squid-4.0.8/src/ftp/Makefile.in	2016-04-02 10:07:36.000000000 +1300
@@ -685,6 +685,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/FwdState.cc squid-4.0.8/src/FwdState.cc
--- squid-4.0.7/src/FwdState.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/FwdState.cc	2016-04-02 10:04:07.000000000 +1300
@@ -123,7 +123,8 @@
 FwdState::closeServerConnection(const char *reason)
 {
     debugs(17, 3, "because " << reason << "; " << serverConn);
-    comm_remove_close_handler(serverConn->fd, fwdServerClosedWrapper, this);
+    comm_remove_close_handler(serverConn->fd, closeHandler);
+    closeHandler = NULL;
     fwdPconnPool->noteUses(fd_table[serverConn->fd].pconn.uses);
     serverConn->close();
 }
@@ -456,7 +457,8 @@
     debugs(17, 3, HERE << entry->url() );
     assert(serverConnection() == conn);
     assert(Comm::IsConnOpen(conn));
-    comm_remove_close_handler(conn->fd, fwdServerClosedWrapper, this);
+    comm_remove_close_handler(conn->fd, closeHandler);
+    closeHandler = NULL;
     serverConn = NULL;
 }
 
@@ -587,14 +589,7 @@
     return true;
 }
 
-/*
- * FwdState::checkRetriable
- *
- * Return TRUE if this is the kind of request that can be retried
- * after a failure.  If the request is not retriable then we don't
- * want to risk sending it on a persistent connection.  Instead we'll
- * force it to go on a new HTTP connection.
- */
+/// Whether we may try sending this request again after a failure.
 bool
 FwdState::checkRetriable()
 {
@@ -687,7 +682,7 @@
     serverConn = conn;
     debugs(17, 3, HERE << serverConnection() << ": '" << entry->url() << "'" );
 
-    comm_add_close_handler(serverConnection()->fd, fwdServerClosedWrapper, this);
+    closeHandler = comm_add_close_handler(serverConnection()->fd, fwdServerClosedWrapper, this);
 
 #if USE_OPENSSL
     if (!request->flags.pinned) {
@@ -865,7 +860,8 @@
             request->flags.pinned = true;
             if (pinned_connection->pinnedAuth())
                 request->flags.auth = true;
-            comm_add_close_handler(serverConn->fd, fwdServerClosedWrapper, this);
+
+            closeHandler = comm_add_close_handler(serverConn->fd,  fwdServerClosedWrapper, this);
 
             syncWithServerConn(pinned_connection->pinning.host);
 
@@ -904,7 +900,7 @@
         debugs(17, 3, HERE << "reusing pconn " << serverConnection());
         ++n_tries;
 
-        comm_add_close_handler(serverConnection()->fd, fwdServerClosedWrapper, this);
+        closeHandler = comm_add_close_handler(serverConnection()->fd,  fwdServerClosedWrapper, this);
 
         syncWithServerConn(request->url.host());
 
@@ -1185,9 +1181,14 @@
 Comm::ConnectionPointer
 FwdState::pconnPop(const Comm::ConnectionPointer &dest, const char *domain)
 {
+    bool retriable = checkRetriable();
+    if (!retriable && Config.accessList.serverPconnForNonretriable) {
+        ACLFilledChecklist ch(Config.accessList.serverPconnForNonretriable, request, NULL);
+        retriable = (ch.fastCheck() == ACCESS_ALLOWED);
+    }
     // always call shared pool first because we need to close an idle
     // connection there if we have to use a standby connection.
-    Comm::ConnectionPointer conn = fwdPconnPool->pop(dest, domain, checkRetriable());
+    Comm::ConnectionPointer conn = fwdPconnPool->pop(dest, domain, retriable);
     if (!Comm::IsConnOpen(conn)) {
         // either there was no pconn to pop or this is not a retriable xaction
         if (CachePeer *peer = dest->getPeer()) {
diff -u -r -N squid-4.0.7/src/FwdState.h squid-4.0.8/src/FwdState.h
--- squid-4.0.7/src/FwdState.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/FwdState.h	2016-04-02 10:04:07.000000000 +1300
@@ -153,6 +153,8 @@
 
     Comm::ConnectionPointer serverConn; ///< a successfully opened connection to a server.
 
+    AsyncCall::Pointer closeHandler; ///< The serverConn close handler
+
     /// possible pconn race states
     typedef enum { raceImpossible, racePossible, raceHappened } PconnRace;
     PconnRace pconnRace; ///< current pconn race state
diff -u -r -N squid-4.0.7/src/globals.h squid-4.0.8/src/globals.h
--- squid-4.0.7/src/globals.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/globals.h	2016-04-02 10:04:07.000000000 +1300
@@ -15,7 +15,7 @@
 #include "hash.h"
 #include "IoStats.h"
 #include "rfc2181.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 extern char *ConfigFile;    /* NULL */
 extern char *IcpOpcodeStr[];
@@ -48,6 +48,7 @@
 extern int opt_reuseaddr;   /* 1 */
 extern int neighbors_do_private_keys;   /* 1 */
 extern int opt_catch_signals;   /* 1 */
+extern int opt_foreground;    /* 0 */
 extern int opt_foreground_rebuild;  /* 0 */
 extern char *opt_forwarded_for; /* NULL */
 extern int opt_reload_hit_only; /* 0 */
diff -u -r -N squid-4.0.7/src/helper/Makefile.in squid-4.0.8/src/helper/Makefile.in
--- squid-4.0.7/src/helper/Makefile.in	2016-02-24 06:49:34.000000000 +1300
+++ squid-4.0.8/src/helper/Makefile.in	2016-04-02 10:07:37.000000000 +1300
@@ -685,6 +685,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/helper.h squid-4.0.8/src/helper.h
--- squid-4.0.7/src/helper.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/helper.h	2016-04-02 10:04:07.000000000 +1300
@@ -19,7 +19,7 @@
 #include "helper/ChildConfig.h"
 #include "helper/forward.h"
 #include "ip/Address.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 #include <list>
 #include <map>
diff -u -r -N squid-4.0.7/src/htcp.cc squid-4.0.8/src/htcp.cc
--- squid-4.0.7/src/htcp.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/htcp.cc	2016-04-02 10:04:07.000000000 +1300
@@ -711,7 +711,7 @@
     // Parse the request
     method.HttpRequestMethodXXX(s->method);
 
-    s->request = HttpRequest::CreateFromUrlAndMethod(s->uri, method == Http::METHOD_NONE ? HttpRequestMethod(Http::METHOD_GET) : method);
+    s->request = HttpRequest::CreateFromUrl(s->uri, method == Http::METHOD_NONE ? HttpRequestMethod(Http::METHOD_GET) : method);
 
     if (s->request)
         HTTPMSGLOCK(s->request);
diff -u -r -N squid-4.0.7/src/http/Makefile.in squid-4.0.8/src/http/Makefile.in
--- squid-4.0.7/src/http/Makefile.in	2016-02-24 06:49:35.000000000 +1300
+++ squid-4.0.8/src/http/Makefile.in	2016-04-02 10:07:39.000000000 +1300
@@ -726,6 +726,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders MethodType.cc
diff -u -r -N squid-4.0.7/src/http/MethodType.cc squid-4.0.8/src/http/MethodType.cc
--- squid-4.0.7/src/http/MethodType.cc	2016-02-24 07:40:11.000000000 +1300
+++ squid-4.0.8/src/http/MethodType.cc	2016-04-02 11:49:10.000000000 +1300
@@ -2,7 +2,7 @@
  * Auto-Generated File. Changes will be destroyed.
  */
 #include "squid.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "http/MethodType.h"
 namespace Http
 {
diff -u -r -N squid-4.0.7/src/http/MethodType.h squid-4.0.8/src/http/MethodType.h
--- squid-4.0.7/src/http/MethodType.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/http/MethodType.h	2016-04-02 10:04:07.000000000 +1300
@@ -9,7 +9,7 @@
 #ifndef SQUID_SRC_HTTP_METHODTYPE_H
 #define SQUID_SRC_HTTP_METHODTYPE_H
 
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 namespace Http
 {
diff -u -r -N squid-4.0.7/src/http/one/Makefile.in squid-4.0.8/src/http/one/Makefile.in
--- squid-4.0.7/src/http/one/Makefile.in	2016-02-24 06:49:35.000000000 +1300
+++ squid-4.0.8/src/http/one/Makefile.in	2016-04-02 10:07:40.000000000 +1300
@@ -686,6 +686,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/http/one/Parser.h squid-4.0.8/src/http/one/Parser.h
--- squid-4.0.7/src/http/one/Parser.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/http/one/Parser.h	2016-04-02 10:04:07.000000000 +1300
@@ -12,7 +12,7 @@
 #include "anyp/ProtocolVersion.h"
 #include "http/one/forward.h"
 #include "http/StatusCode.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 namespace Http {
 namespace One {
diff -u -r -N squid-4.0.7/src/http/RegisteredHeadersHash.cci squid-4.0.8/src/http/RegisteredHeadersHash.cci
--- squid-4.0.7/src/http/RegisteredHeadersHash.cci	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/http/RegisteredHeadersHash.cci	2016-04-02 10:04:07.000000000 +1300
@@ -312,7 +312,7 @@
 #line 56 "RegisteredHeadersHash.gperf"
     {"HTTP2-Settings", Http::HdrType::HTTP2_SETTINGS, Http::HdrFieldType::ftStr, HdrKind::RequestHeader|HdrKind::HopByHopHeader},
 #line 64 "RegisteredHeadersHash.gperf"
-    {"Last-Modified", Http::HdrType::LAST_MODIFIED, Http::HdrFieldType::ftDate_1123, HdrKind::EntityHeader|HdrKind::Denied304Header},
+    {"Last-Modified", Http::HdrType::LAST_MODIFIED, Http::HdrFieldType::ftDate_1123, HdrKind::EntityHeader},
 #line 67 "RegisteredHeadersHash.gperf"
     {"Max-Forwards", Http::HdrType::MAX_FORWARDS, Http::HdrFieldType::ftInt64, HdrKind::RequestHeader},
 #line 99 "RegisteredHeadersHash.gperf"
diff -u -r -N squid-4.0.7/src/http/RegisteredHeadersHash.gperf squid-4.0.8/src/http/RegisteredHeadersHash.gperf
--- squid-4.0.7/src/http/RegisteredHeadersHash.gperf	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/http/RegisteredHeadersHash.gperf	2016-04-02 10:04:07.000000000 +1300
@@ -61,7 +61,7 @@
 If-Unmodified-Since, Http::HdrType::IF_UNMODIFIED_SINCE, Http::HdrFieldType::ftDate_1123, HdrKind::None
 Keep-Alive, Http::HdrType::KEEP_ALIVE, Http::HdrFieldType::ftStr, HdrKind::HopByHopHeader|HdrKind::Denied304Header
 Key, Http::HdrType::KEY, Http::HdrFieldType::ftStr, HdrKind::ListHeader|HdrKind::ReplyHeader
-Last-Modified, Http::HdrType::LAST_MODIFIED, Http::HdrFieldType::ftDate_1123, HdrKind::EntityHeader|HdrKind::Denied304Header
+Last-Modified, Http::HdrType::LAST_MODIFIED, Http::HdrFieldType::ftDate_1123, HdrKind::EntityHeader
 Link, Http::HdrType::LINK, Http::HdrFieldType::ftStr, HdrKind::ListHeader|HdrKind::EntityHeader
 Location, Http::HdrType::LOCATION, Http::HdrFieldType::ftStr, HdrKind::ReplyHeader
 Max-Forwards, Http::HdrType::MAX_FORWARDS, Http::HdrFieldType::ftInt64, HdrKind::RequestHeader
diff -u -r -N squid-4.0.7/src/http/RequestMethod.h squid-4.0.8/src/http/RequestMethod.h
--- squid-4.0.7/src/http/RequestMethod.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/http/RequestMethod.h	2016-04-02 10:04:07.000000000 +1300
@@ -11,7 +11,7 @@
 
 #include "http/forward.h"
 #include "http/MethodType.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 class SquidConfig;
 
diff -u -r -N squid-4.0.7/src/http/StatusCode.cc squid-4.0.8/src/http/StatusCode.cc
--- squid-4.0.7/src/http/StatusCode.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/http/StatusCode.cc	2016-04-02 10:04:07.000000000 +1300
@@ -212,6 +212,10 @@
         return "Request Header Fields Too Large";
         break;
 
+    case scUnavailableForLegalReasons:
+        return "Unavailable For Legal Reasons";
+        break;
+
     // 500-599
     case Http::scInternalServerError:
         return "Internal Server Error";
diff -u -r -N squid-4.0.7/src/http/StatusCode.h squid-4.0.8/src/http/StatusCode.h
--- squid-4.0.7/src/http/StatusCode.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/http/StatusCode.h	2016-04-02 10:04:07.000000000 +1300
@@ -66,6 +66,7 @@
     scPreconditionRequired = 428,   /**< RFC6585 */
     scTooManyRequests = 429,        /**< RFC6585 */
     scRequestHeaderFieldsTooLarge = 431, /**< RFC6585 */
+    scUnavailableForLegalReasons = 451, /**< RFC7725 */
     scInternalServerError = 500,
     scNotImplemented = 501,
     scBadGateway = 502,
diff -u -r -N squid-4.0.7/src/http/url_rewriters/fake/Makefile.in squid-4.0.8/src/http/url_rewriters/fake/Makefile.in
--- squid-4.0.7/src/http/url_rewriters/fake/Makefile.in	2016-02-24 06:49:36.000000000 +1300
+++ squid-4.0.8/src/http/url_rewriters/fake/Makefile.in	2016-04-02 10:07:42.000000000 +1300
@@ -672,6 +672,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/http/url_rewriters/LFS/Makefile.in squid-4.0.8/src/http/url_rewriters/LFS/Makefile.in
--- squid-4.0.7/src/http/url_rewriters/LFS/Makefile.in	2016-02-24 06:49:35.000000000 +1300
+++ squid-4.0.8/src/http/url_rewriters/LFS/Makefile.in	2016-04-02 10:07:41.000000000 +1300
@@ -624,6 +624,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = url_lfs_rewrite $(am__append_2)
diff -u -r -N squid-4.0.7/src/http/url_rewriters/LFS/url_lfs_rewrite.8 squid-4.0.8/src/http/url_rewriters/LFS/url_lfs_rewrite.8
--- squid-4.0.7/src/http/url_rewriters/LFS/url_lfs_rewrite.8	2016-02-24 07:40:16.000000000 +1300
+++ squid-4.0.8/src/http/url_rewriters/LFS/url_lfs_rewrite.8	2016-04-02 11:49:14.000000000 +1300
@@ -133,7 +133,7 @@
 .\" ========================================================================
 .\"
 .IX Title "URL_LFS_REWRITE 8"
-.TH URL_LFS_REWRITE 8 "2016-02-23" "perl v5.22.1" "User Contributed Perl Documentation"
+.TH URL_LFS_REWRITE 8 "2016-04-01" "perl v5.22.1" "User Contributed Perl Documentation"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
diff -u -r -N squid-4.0.7/src/http.cc squid-4.0.8/src/http.cc
--- squid-4.0.7/src/http.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/http.cc	2016-04-02 10:04:07.000000000 +1300
@@ -83,8 +83,6 @@
 static void httpMaybeRemovePublic(StoreEntry *, Http::StatusCode);
 static void copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, const String strConnection, const HttpRequest * request,
         HttpHeader * hdr_out, const int we_do_ranges, const HttpStateFlags &);
-//Declared in HttpHeaderTools.cc
-void httpHdrAdd(HttpHeader *heads, HttpRequest *request, const AccessLogEntryPointer &al, HeaderWithAclList &headers_add);
 
 HttpStateData::HttpStateData(FwdState *theFwdState) :
     AsyncJob("HttpStateData"),
@@ -166,7 +164,8 @@
         fwd->fail(new ErrorState(ERR_READ_TIMEOUT, Http::scGatewayTimeout, fwd->request));
     }
 
-    serverConnection->close();
+    closeServer();
+    mustStop("HttpStateData::httpTimeout");
 }
 
 /// Remove an existing public store entry if the incoming response (to be
@@ -575,9 +574,9 @@
 /*
  * For Vary, store the relevant request headers as
  * virtual headers in the reply
- * Returns false if the variance cannot be stored
+ * Returns an empty SBuf if the variance cannot be stored
  */
-const char *
+SBuf
 httpMakeVaryMark(HttpRequest * request, HttpReply const * reply)
 {
     String vary, hdr;
@@ -585,20 +584,21 @@
     const char *item;
     const char *value;
     int ilen;
-    static String vstr;
+    SBuf vstr;
+    static const SBuf asterisk("*");
 
-    vstr.clean();
     vary = reply->header.getList(Http::HdrType::VARY);
 
     while (strListGetItem(&vary, ',', &item, &ilen, &pos)) {
-        static const SBuf asterisk("*");
         SBuf name(item, ilen);
         if (name == asterisk) {
-            vstr.clean();
+            vstr.clear();
             break;
         }
         name.toLower();
-        strListAdd(&vstr, name.c_str(), ',');
+        if (!vstr.isEmpty())
+            vstr.append(", ", 2);
+        vstr.append(name);
         hdr = request->header.getByName(name);
         value = hdr.termedBuf();
         if (value) {
@@ -618,12 +618,16 @@
     vary = reply->header.getList(Http::HdrType::HDR_X_ACCELERATOR_VARY);
 
     while (strListGetItem(&vary, ',', &item, &ilen, &pos)) {
-        char *name = (char *)xmalloc(ilen + 1);
-        xstrncpy(name, item, ilen + 1);
-        Tolower(name);
-        strListAdd(&vstr, name, ',');
+        SBuf name(item, ilen);
+        if (name == asterisk) {
+            vstr.clear();
+            break;
+        }
+        name.toLower();
+        if (!vstr.isEmpty())
+            vstr.append(", ", 2);
+        vstr.append(name);
         hdr = request->header.getByName(name);
-        safe_free(name);
         value = hdr.termedBuf();
 
         if (value) {
@@ -639,8 +643,8 @@
     vary.clean();
 #endif
 
-    debugs(11, 3, "httpMakeVaryMark: " << vstr);
-    return vstr.termedBuf();
+    debugs(11, 3, vstr);
+    return vstr;
 }
 
 void
@@ -941,15 +945,15 @@
             || rep->header.has(Http::HdrType::HDR_X_ACCELERATOR_VARY)
 #endif
        ) {
-        const char *vary = httpMakeVaryMark(request, rep);
+        const SBuf vary(httpMakeVaryMark(request, rep));
 
-        if (!vary) {
+        if (vary.isEmpty()) {
             entry->makePrivate();
             if (!fwd->reforwardableStatus(rep->sline.status()))
                 EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT);
             varyFailure = true;
         } else {
-            entry->mem_obj->vary_headers = xstrdup(vary);
+            entry->mem_obj->vary_headers = vary;
         }
     }
 
@@ -1234,8 +1238,8 @@
         err->xerrno = rd.xerrno;
         fwd->fail(err);
         flags.do_next_read = false;
-        io.conn->close();
-
+        closeServer();
+        mustStop("HttpStateData::readReply");
         return;
     }
 
@@ -1335,7 +1339,8 @@
     entry->reset();
     fwd->fail(new ErrorState(error, Http::scBadGateway, fwd->request));
     flags.do_next_read = false;
-    serverConnection->close();
+    closeServer();
+    mustStop("HttpStateData::continueAfterParsingHeader");
     return false; // quit on error
 }
 
@@ -1446,8 +1451,11 @@
             writeReplyBody();
     }
 
+    // storing/sending methods like earlier adaptOrFinalizeReply() or
+    // above writeReplyBody() may release/abort the store entry.
     if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) {
-        // The above writeReplyBody() call may have aborted the store entry.
+        // TODO: In some cases (e.g., 304), we should keep persistent conn open.
+        // Detect end-of-reply (and, hence, pool our idle pconn) earlier (ASAP).
         abortTransaction("store entry aborted while storing reply");
         return;
     } else
@@ -1599,7 +1607,8 @@
         ErrorState *err = new ErrorState(ERR_WRITE_ERROR, Http::scBadGateway, fwd->request);
         err->xerrno = io.xerrno;
         fwd->fail(err);
-        serverConnection->close();
+        closeServer();
+        mustStop("HttpStateData::wroteLast");
         return;
     }
 
@@ -1627,7 +1636,6 @@
     request->hier.peer_http_request_sent = current_time;
 }
 
-// Close the HTTP server connection. Used by serverComplete().
 void
 HttpStateData::closeServer()
 {
@@ -1937,11 +1945,7 @@
     }
 
     /* Now mangle the headers. */
-    if (Config2.onoff.mangle_request_headers)
-        httpHdrMangleList(hdr_out, request, ROR_REQUEST);
-
-    if (Config.request_header_add && !Config.request_header_add->empty())
-        httpHdrAdd(hdr_out, request, al, *Config.request_header_add);
+    httpHdrMangleList(hdr_out, request, al, ROR_REQUEST);
 
     strConnection.clean();
 }
@@ -2426,7 +2430,8 @@
             debugs(11, DBG_IMPORTANT, "http handleMoreRequestBodyAvailable: Likely proxy abuse detected '" << request->client_addr << "' -> '" << entry->url() << "'" );
 
             if (virginReply()->sline.status() == Http::scInvalidHeader) {
-                serverConnection->close();
+                closeServer();
+                mustStop("HttpStateData::handleMoreRequestBodyAvailable");
                 return;
             }
         }
diff -u -r -N squid-4.0.7/src/http.h squid-4.0.8/src/http.h
--- squid-4.0.7/src/http.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/http.h	2016-04-02 10:04:07.000000000 +1300
@@ -13,6 +13,7 @@
 #include "comm.h"
 #include "http/forward.h"
 #include "HttpStateFlags.h"
+#include "sbuf/SBuf.h"
 
 class FwdState;
 class HttpHeader;
@@ -132,7 +133,7 @@
 
 int httpCachable(const HttpRequestMethod&);
 void httpStart(FwdState *);
-const char *httpMakeVaryMark(HttpRequest * request, HttpReply const * reply);
+SBuf httpMakeVaryMark(HttpRequest * request, HttpReply const * reply);
 
 #endif /* SQUID_HTTP_H */
 
diff -u -r -N squid-4.0.7/src/HttpHdrCc.cc squid-4.0.8/src/HttpHdrCc.cc
--- squid-4.0.7/src/HttpHdrCc.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/HttpHdrCc.cc	2016-04-02 10:04:07.000000000 +1300
@@ -15,7 +15,7 @@
 #include "HttpHeaderFieldStat.h"
 #include "HttpHeaderStat.h"
 #include "HttpHeaderTools.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "StatHist.h"
 #include "Store.h"
 #include "StrList.h"
diff -u -r -N squid-4.0.7/src/HttpHeader.h squid-4.0.8/src/HttpHeader.h
--- squid-4.0.7/src/HttpHeader.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/HttpHeader.h	2016-04-02 10:04:07.000000000 +1300
@@ -14,6 +14,7 @@
 /* because we pass a spec by value */
 #include "HttpHeaderMask.h"
 #include "mem/forward.h"
+#include "sbuf/forward.h"
 #include "SquidString.h"
 
 #include <vector>
@@ -24,7 +25,6 @@
 class HttpHdrRange;
 class HttpHdrSc;
 class Packable;
-class SBuf;
 
 /** Possible owners of http header */
 typedef enum {
diff -u -r -N squid-4.0.7/src/HttpHeaderTools.cc squid-4.0.8/src/HttpHeaderTools.cc
--- squid-4.0.7/src/HttpHeaderTools.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/HttpHeaderTools.cc	2016-04-02 10:04:07.000000000 +1300
@@ -40,6 +40,7 @@
 #include <string>
 
 static void httpHeaderPutStrvf(HttpHeader * hdr, Http::HdrType id, const char *fmt, va_list vargs);
+static void httpHdrAdd(HttpHeader *heads, HttpRequest *request, const AccessLogEntryPointer &al, HeaderWithAclList &headersAdd);
 
 void
 httpHeaderMaskInit(HttpHeaderMask * mask, int value)
@@ -267,29 +268,12 @@
  * \retval 1    Header has no access controls to test
  */
 static int
-httpHdrMangle(HttpHeaderEntry * e, HttpRequest * request, int req_or_rep)
+httpHdrMangle(HttpHeaderEntry * e, HttpRequest * request, HeaderManglers *hms)
 {
     int retval;
 
-    /* check with anonymizer tables */
-    HeaderManglers *hms = NULL;
     assert(e);
 
-    if (ROR_REQUEST == req_or_rep) {
-        hms = Config.request_header_access;
-    } else if (ROR_REPLY == req_or_rep) {
-        hms = Config.reply_header_access;
-    } else {
-        /* error. But let's call it "request". */
-        hms = Config.request_header_access;
-    }
-
-    /* manglers are not configured for this message kind */
-    if (!hms) {
-        debugs(66, 7, "no manglers configured for message kind " << req_or_rep);
-        return 1;
-    }
-
     const headerMangler *hm = hms->find(*e);
 
     /* mangler or checklist went away. default allow */
@@ -323,18 +307,40 @@
 
 /** Mangles headers for a list of headers. */
 void
-httpHdrMangleList(HttpHeader * l, HttpRequest * request, int req_or_rep)
+httpHdrMangleList(HttpHeader *l, HttpRequest *request, const AccessLogEntryPointer &al, req_or_rep_t req_or_rep)
 {
     HttpHeaderEntry *e;
     HttpHeaderPos p = HttpHeaderInitPos;
 
-    int headers_deleted = 0;
-    while ((e = l->getEntry(&p)))
-        if (0 == httpHdrMangle(e, request, req_or_rep))
-            l->delAt(p, headers_deleted);
+    /* check with anonymizer tables */
+    HeaderManglers *hms = nullptr;
+    HeaderWithAclList *headersAdd = nullptr;
+
+    switch (req_or_rep) {
+    case ROR_REQUEST:
+        hms = Config.request_header_access;
+        headersAdd = Config.request_header_add;
+        break;
+    case ROR_REPLY:
+        hms = Config.reply_header_access;
+        headersAdd = Config.reply_header_add;
+        break;
+    }
 
-    if (headers_deleted)
-        l->refreshMask();
+    if (hms) {
+        int headers_deleted = 0;
+        while ((e = l->getEntry(&p))) {
+            if (0 == httpHdrMangle(e, request, hms))
+                l->delAt(p, headers_deleted);
+        }
+
+        if (headers_deleted)
+            l->refreshMask();
+    }
+
+    if (headersAdd && !headersAdd->empty()) {
+        httpHdrAdd(l, request, al, *headersAdd);
+    }
 }
 
 static
diff -u -r -N squid-4.0.7/src/HttpHeaderTools.h squid-4.0.8/src/HttpHeaderTools.h
--- squid-4.0.7/src/HttpHeaderTools.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/HttpHeaderTools.h	2016-04-02 10:04:07.000000000 +1300
@@ -29,6 +29,12 @@
 
 typedef std::list<HeaderWithAcl> HeaderWithAclList;
 
+/* Distinguish between Request and Reply (for header mangling) */
+typedef enum {
+    ROR_REQUEST,
+    ROR_REPLY
+} req_or_rep_t;
+
 // Currently a POD
 class headerMangler
 {
@@ -119,7 +125,7 @@
 
 const char *getStringPrefix(const char *str, size_t len);
 
-void httpHdrMangleList(HttpHeader *, HttpRequest *, int req_or_rep);
+void httpHdrMangleList(HttpHeader *, HttpRequest *, const AccessLogEntryPointer &al, req_or_rep_t req_or_rep);
 
 #endif
 
diff -u -r -N squid-4.0.7/src/HttpMsg.cc squid-4.0.8/src/HttpMsg.cc
--- squid-4.0.7/src/HttpMsg.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/HttpMsg.cc	2016-04-02 10:04:07.000000000 +1300
@@ -11,6 +11,7 @@
 #include "squid.h"
 #include "Debug.h"
 #include "http/one/Parser.h"
+#include "HttpHdrCc.h"
 #include "HttpHeaderTools.h"
 #include "HttpMsg.h"
 #include "MemBuf.h"
@@ -33,6 +34,25 @@
     assert(!body_pipe);
 }
 
+void
+HttpMsg::putCc(const HttpHdrCc *otherCc)
+{
+    // get rid of the old CC, if any
+    if (cache_control) {
+        delete cache_control;
+        cache_control = nullptr;
+        if (!otherCc)
+            header.delById(Http::HdrType::CACHE_CONTROL);
+        // else it will be deleted inside putCc() below
+    }
+
+    // add new CC, if any
+    if (otherCc) {
+        cache_control = new HttpHdrCc(*otherCc);
+        header.putCc(cache_control);
+    }
+}
+
 HttpMsgParseState &operator++ (HttpMsgParseState &aState)
 {
     int tmp = (int)aState;
diff -u -r -N squid-4.0.7/src/HttpMsg.h squid-4.0.8/src/HttpMsg.h
--- squid-4.0.7/src/HttpMsg.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/HttpMsg.h	2016-04-02 10:04:07.000000000 +1300
@@ -87,6 +87,9 @@
 
     uint32_t sources; ///< The message sources
 
+    /// copies Cache-Control header to this message
+    void putCc(const HttpHdrCc *otherCc);
+
     // returns true and sets hdr_sz on success
     // returns false and sets *error to zero when needs more data
     // returns false and sets *error to a positive Http::StatusCode on error
diff -u -r -N squid-4.0.7/src/HttpReply.cc squid-4.0.8/src/HttpReply.cc
--- squid-4.0.7/src/HttpReply.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/HttpReply.cc	2016-04-02 10:04:07.000000000 +1300
@@ -116,7 +116,7 @@
 }
 
 void
-HttpReply::packInto(Packable * p)
+HttpReply::packInto(Packable * p) const
 {
     packHeadersInto(p);
     body.packInto(p);
@@ -124,7 +124,7 @@
 
 /* create memBuf, create mem-based packer, pack, destroy packer, return MemBuf */
 MemBuf *
-HttpReply::pack()
+HttpReply::pack() const
 {
     MemBuf *mb = new MemBuf;
     mb->init();
@@ -146,7 +146,6 @@
     rv->last_modified = last_modified;
     rv->expires = expires;
     rv->content_type = content_type;
-    /* rv->cache_control */
     /* rv->content_range */
     /* rv->keep_alive */
     rv->sline.set(Http::ProtocolVersion(), Http::scNotModified, NULL);
@@ -156,12 +155,14 @@
             rv->header.addEntry(e->clone());
     }
 
+    rv->putCc(cache_control);
+
     /* rv->body */
     return rv;
 }
 
 MemBuf *
-HttpReply::packed304Reply()
+HttpReply::packed304Reply() const
 {
     /* Not as efficient as skipping the header duplication,
      * but easier to maintain
diff -u -r -N squid-4.0.7/src/HttpReply.h squid-4.0.8/src/HttpReply.h
--- squid-4.0.7/src/HttpReply.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/HttpReply.h	2016-04-02 10:04:07.000000000 +1300
@@ -79,7 +79,7 @@
                     const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires);
 
     /** \return a ready to use mem buffer with a packed reply */
-    MemBuf *pack();
+    MemBuf *pack() const;
 
     /** construct a 304 reply and return it */
     HttpReply *make304() const;
@@ -120,11 +120,11 @@
 
     void hdrCacheClean();
 
-    void packInto(Packable * p);
+    void packInto(Packable * p) const;
 
     /* ez-routines */
     /** \return construct 304 reply and pack it into a MemBuf */
-    MemBuf *packed304Reply();
+    MemBuf *packed304Reply() const;
 
     /* header manipulation */
     time_t hdrExpirationTime();
diff -u -r -N squid-4.0.7/src/HttpRequest.cc squid-4.0.8/src/HttpRequest.cc
--- squid-4.0.7/src/HttpRequest.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/HttpRequest.cc	2016-04-02 10:04:07.000000000 +1300
@@ -25,6 +25,7 @@
 #include "HttpRequest.h"
 #include "log/Config.h"
 #include "MemBuf.h"
+#include "sbuf/StringConvert.h"
 #include "SquidConfig.h"
 #include "Store.h"
 #include "URL.h"
@@ -88,7 +89,7 @@
     peer_login = NULL;      // not allocated/deallocated by this class
     peer_domain = NULL;     // not allocated/deallocated by this class
     peer_host = NULL;
-    vary_headers = NULL;
+    vary_headers = SBuf();
     myportname = null_string;
     tag = null_string;
 #if USE_AUTH
@@ -120,8 +121,7 @@
 #if USE_AUTH
     auth_user_request = NULL;
 #endif
-    safe_free(vary_headers);
-
+    vary_headers.clear();
     url.clear();
 
     header.clean();
@@ -196,7 +196,7 @@
 
     copy->lastmod = lastmod;
     copy->etag = etag;
-    copy->vary_headers = vary_headers ? xstrdup(vary_headers) : NULL;
+    copy->vary_headers = vary_headers;
     // XXX: what to do with copy->peer_domain?
 
     copy->tag = tag;
@@ -350,7 +350,7 @@
 
 /* packs request-line and headers, appends <crlf> terminator */
 void
-HttpRequest::pack(Packable * p)
+HttpRequest::pack(Packable * p) const
 {
     assert(p);
     /* pack request-line */
@@ -519,22 +519,11 @@
  * If the request cannot be created cleanly, NULL is returned
  */
 HttpRequest *
-HttpRequest::CreateFromUrlAndMethod(char * url, const HttpRequestMethod& method)
+HttpRequest::CreateFromUrl(char * url, const HttpRequestMethod& method)
 {
     return urlParse(method, url, NULL);
 }
 
-/*
- * Create a Request from a URL.
- *
- * If the request cannot be created cleanly, NULL is returned
- */
-HttpRequest *
-HttpRequest::CreateFromUrl(char * url)
-{
-    return urlParse(Http::METHOD_GET, url, NULL);
-}
-
 /**
  * Are responses to this request possible cacheable ?
  * If false then no matter what the response must not be cached.
@@ -660,7 +649,7 @@
 {
     if (store_id.size() != 0) {
         debugs(73, 3, "sent back store_id: " << store_id);
-        return SBuf(store_id);
+        return StringToSBuf(store_id);
     }
     debugs(73, 3, "sent back effectiveRequestUrl: " << effectiveRequestUri());
     return effectiveRequestUri();
diff -u -r -N squid-4.0.7/src/HttpRequest.h squid-4.0.8/src/HttpRequest.h
--- squid-4.0.7/src/HttpRequest.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/HttpRequest.h	2016-04-02 10:04:07.000000000 +1300
@@ -148,7 +148,8 @@
 
     time_t lastmod;     /* Used on refreshes */
 
-    const char *vary_headers;   /* Used when varying entities are detected. Changes how the store key is calculated */
+    /// The variant second-stage cache key. Generated from Vary header pattern for this request.
+    SBuf vary_headers;
 
     char *peer_domain;      /* Configured peer forceddomain */
 
@@ -189,13 +190,11 @@
 
     void swapOut(StoreEntry * e);
 
-    void pack(Packable * p);
+    void pack(Packable * p) const;
 
     static void httpRequestPack(void *obj, Packable *p);
 
-    static HttpRequest * CreateFromUrlAndMethod(char * url, const HttpRequestMethod& method);
-
-    static HttpRequest * CreateFromUrl(char * url);
+    static HttpRequest * CreateFromUrl(char * url, const HttpRequestMethod &method = Http::METHOD_GET);
 
     ConnStateData *pinnedConnection();
 
diff -u -r -N squid-4.0.7/src/icmp/Icmp6.cc squid-4.0.8/src/icmp/Icmp6.cc
--- squid-4.0.7/src/icmp/Icmp6.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/icmp/Icmp6.cc	2016-04-02 10:04:07.000000000 +1300
@@ -256,7 +256,7 @@
     #define ip6_hops    // HOPS!!!  (can it be true??)
 
         ip = (struct ip6_hdr *) pkt;
-        pkt += sizeof(ip6_hdr);
+        FIXME  += sizeof(ip6_hdr);
 
     debugs(42, DBG_CRITICAL, HERE << "ip6_nxt=" << ip->ip6_nxt <<
             ", ip6_plen=" << ip->ip6_plen <<
@@ -267,7 +267,6 @@
     */
 
     icmp6header = (struct icmp6_hdr *) pkt;
-    pkt += sizeof(icmp6_hdr);
 
     if (icmp6header->icmp6_type != ICMP6_ECHO_REPLY) {
 
@@ -292,7 +291,7 @@
         return;
     }
 
-    echo = (icmpEchoData *) pkt;
+    echo = (icmpEchoData *) (pkt + sizeof(icmp6_hdr));
 
     preply.opcode = echo->opcode;
 
diff -u -r -N squid-4.0.7/src/icmp/IcmpConfig.h squid-4.0.8/src/icmp/IcmpConfig.h
--- squid-4.0.7/src/icmp/IcmpConfig.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/icmp/IcmpConfig.h	2016-04-02 10:04:07.000000000 +1300
@@ -14,7 +14,7 @@
 #if USE_ICMP
 
 #include "cache_cf.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 /**
  * Squid pinger Configuration settings
diff -u -r -N squid-4.0.7/src/icmp/Makefile.in squid-4.0.8/src/icmp/Makefile.in
--- squid-4.0.7/src/icmp/Makefile.in	2016-02-24 06:49:37.000000000 +1300
+++ squid-4.0.8/src/icmp/Makefile.in	2016-04-02 10:07:44.000000000 +1300
@@ -716,6 +716,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders $(COPIED_SOURCE)
diff -u -r -N squid-4.0.7/src/icmp/pinger.cc squid-4.0.8/src/icmp/pinger.cc
--- squid-4.0.7/src/icmp/pinger.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/icmp/pinger.cc	2016-04-02 10:04:07.000000000 +1300
@@ -162,18 +162,46 @@
     max_fd = max(max_fd, squid_link);
 
     if (setgid(getgid()) < 0) {
-        debugs(42, DBG_CRITICAL, "FATAL: pinger: setgid(" << getgid() << ") failed: " << xstrerror());
+        int xerrno = errno;
+        debugs(42, DBG_CRITICAL, "FATAL: pinger: setgid(" << getgid() << ") failed: " << xstrerr(xerrno));
         icmp4.Close();
         icmp6.Close();
         exit (1);
     }
     if (setuid(getuid()) < 0) {
-        debugs(42, DBG_CRITICAL, "FATAL: pinger: setuid(" << getuid() << ") failed: " << xstrerror());
+        int xerrno = errno;
+        debugs(42, DBG_CRITICAL, "FATAL: pinger: setuid(" << getuid() << ") failed: " << xstrerr(xerrno));
         icmp4.Close();
         icmp6.Close();
         exit (1);
     }
 
+#if USE_LIBCAP
+    // Drop remaining capabilities (if installed as non-setuid setcap cap_net_raw=ep).
+    // If pinger binary was installed setuid root, setuid() above already dropped all
+    // capabilities, and this is no-op.
+    cap_t caps;
+    caps = cap_init();
+    if (!caps) {
+        int xerrno = errno;
+        debugs(42, DBG_CRITICAL, "FATAL: pinger: cap_init() failed: " << xstrerr(xerrno));
+        icmp4.Close();
+        icmp6.Close();
+        exit (1);
+    } else {
+        if (cap_set_proc(caps) != 0) {
+            int xerrno = errno;
+            // cap_set_proc(cap_init()) is expected to never fail
+            debugs(42, DBG_CRITICAL, "FATAL: pinger: cap_set_proc(none) failed: " << xstrerr(xerrno));
+            cap_free(caps);
+            icmp4.Close();
+            icmp6.Close();
+            exit (1);
+        }
+        cap_free(caps);
+    }
+#endif
+
     last_check_time = squid_curtime;
 
     for (;;) {
@@ -188,11 +216,12 @@
         }
 
         FD_SET(squid_link, &R);
-        x = select(10, &R, NULL, NULL, &tv);
+        x = select(max_fd+1, &R, NULL, NULL, &tv);
         getCurrentTime();
 
         if (x < 0) {
-            debugs(42, DBG_CRITICAL, HERE << " FATAL Shutdown. select()==" << x << ", ERR: " << xstrerror());
+            int xerrno = errno;
+            debugs(42, DBG_CRITICAL, HERE << " FATAL Shutdown. select()==" << x << ", ERR: " << xstrerr(xerrno));
             control.Close();
             exit(1);
         }
diff -u -r -N squid-4.0.7/src/ident/Makefile.in squid-4.0.8/src/ident/Makefile.in
--- squid-4.0.7/src/ident/Makefile.in	2016-02-24 06:49:37.000000000 +1300
+++ squid-4.0.8/src/ident/Makefile.in	2016-04-02 10:07:45.000000000 +1300
@@ -685,6 +685,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/internal.h squid-4.0.8/src/internal.h
--- squid-4.0.7/src/internal.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/internal.h	2016-04-02 10:04:07.000000000 +1300
@@ -15,9 +15,9 @@
 #define SQUID_INTERNAL_H_
 
 #include "comm/forward.h"
+#include "sbuf/forward.h"
 
 class HttpRequest;
-class SBuf;
 class StoreEntry;
 
 void internalStart(const Comm::ConnectionPointer &clientConn, HttpRequest *, StoreEntry *);
diff -u -r -N squid-4.0.7/src/ip/Makefile.in squid-4.0.8/src/ip/Makefile.in
--- squid-4.0.7/src/ip/Makefile.in	2016-02-24 06:49:38.000000000 +1300
+++ squid-4.0.8/src/ip/Makefile.in	2016-04-02 10:07:46.000000000 +1300
@@ -685,6 +685,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/ipc/Makefile.in squid-4.0.8/src/ipc/Makefile.in
--- squid-4.0.7/src/ipc/Makefile.in	2016-02-24 06:49:38.000000000 +1300
+++ squid-4.0.8/src/ipc/Makefile.in	2016-04-02 10:07:48.000000000 +1300
@@ -691,6 +691,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/ipc/mem/Segment.cc squid-4.0.8/src/ipc/mem/Segment.cc
--- squid-4.0.7/src/ipc/mem/Segment.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/ipc/mem/Segment.cc	2016-04-02 10:04:07.000000000 +1300
@@ -14,7 +14,8 @@
 #include "Debug.h"
 #include "fatal.h"
 #include "ipc/mem/Segment.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
+#include "SquidConfig.h"
 #include "tools.h"
 
 #if HAVE_FCNTL_H
@@ -174,6 +175,8 @@
                theName.termedBuf(), xstrerror());
     }
     theMem = p;
+
+    lock();
 }
 
 /// Unmap the shared memory segment from the process memory space.
@@ -191,6 +194,39 @@
     theMem = 0;
 }
 
+/// Lock the segment into RAM, ensuring that the OS has enough RAM for it [now]
+/// and preventing segment bytes from being swapped out to disk later by the OS.
+void
+Ipc::Mem::Segment::lock()
+{
+    if (!Config.shmLocking) {
+        debugs(54, 5, "mlock(2)-ing disabled");
+        return;
+    }
+
+#if defined(_POSIX_MEMLOCK_RANGE)
+    debugs(54, 7, "mlock(" << theName << ',' << theSize << ") starts");
+    if (mlock(theMem, theSize) != 0) {
+        const int savedError = errno;
+        fatalf("shared_memory_locking on but failed to mlock(%s, %" PRId64 "): %s\n",
+               theName.termedBuf(),static_cast<int64_t>(theSize), xstrerr(savedError));
+    }
+    // TODO: Warn if it took too long.
+    debugs(54, 7, "mlock(" << theName << ',' << theSize << ") OK");
+#else
+    debugs(54, 5, "insufficient mlock(2) support");
+    if (Config.shmLocking.configured()) { // set explicitly
+        static bool warnedOnce = false;
+        if (!warnedOnce) {
+            debugs(54, DBG_IMPORTANT, "ERROR: insufficient mlock(2) support prevents " <<
+                   "honoring `shared_memory_locking on`. " <<
+                   "If you lack RAM, kernel will kill Squid later.");
+            warnedOnce = true;
+        }
+    }
+#endif
+}
+
 void
 Ipc::Mem::Segment::unlink()
 {
diff -u -r -N squid-4.0.7/src/ipc/mem/Segment.h squid-4.0.8/src/ipc/mem/Segment.h
--- squid-4.0.7/src/ipc/mem/Segment.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/ipc/mem/Segment.h	2016-04-02 10:04:07.000000000 +1300
@@ -10,10 +10,9 @@
 #define SQUID_IPC_MEM_SEGMENT_H
 
 #include "base/RunnersRegistry.h"
+#include "sbuf/forward.h"
 #include "SquidString.h"
 
-class SBuf;
-
 namespace Ipc
 {
 
@@ -57,6 +56,7 @@
     bool createFresh();
     void attach();
     void detach();
+    void lock();
     void unlink(); ///< unlink the segment
     off_t statSize(const char *context) const;
 
diff -u -r -N squid-4.0.7/src/ipc/MemMap.h squid-4.0.8/src/ipc/MemMap.h
--- squid-4.0.7/src/ipc/MemMap.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/ipc/MemMap.h	2016-04-02 10:04:07.000000000 +1300
@@ -13,7 +13,7 @@
 #include "ipc/mem/FlexibleArray.h"
 #include "ipc/mem/Pointer.h"
 #include "ipc/ReadWriteLock.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "store/forward.h"
 #include "store_key_md5.h"
 #include "tools.h"
diff -u -r -N squid-4.0.7/src/ipc/ReadWriteLock.cc squid-4.0.8/src/ipc/ReadWriteLock.cc
--- squid-4.0.7/src/ipc/ReadWriteLock.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/ipc/ReadWriteLock.cc	2016-04-02 10:04:07.000000000 +1300
@@ -12,6 +12,14 @@
 #include "ipc/ReadWriteLock.h"
 #include "Store.h"
 
+void Ipc::AssertFlagIsSet(std::atomic_flag &flag)
+{
+    // If the flag was false, then we set it to true and assert. A true flag
+    // may help keep other processes away from this broken entry.
+    // Otherwise, we just set an already set flag, which is probably a no-op.
+    assert(flag.test_and_set(std::memory_order_relaxed));
+}
+
 bool
 Ipc::ReadWriteLock::lockShared()
 {
@@ -37,6 +45,18 @@
     return false;
 }
 
+bool
+Ipc::ReadWriteLock::lockHeaders()
+{
+    if (lockShared()) {
+        if (!updating.test_and_set(std::memory_order_acquire))
+            return true; // we got here first
+        // the updating lock was already set by somebody else
+        unlockShared();
+    }
+    return false;
+}
+
 void
 Ipc::ReadWriteLock::unlockShared()
 {
@@ -55,6 +75,14 @@
 }
 
 void
+Ipc::ReadWriteLock::unlockHeaders()
+{
+    AssertFlagIsSet(updating);
+    updating.clear(std::memory_order_release);
+    unlockShared();
+}
+
+void
 Ipc::ReadWriteLock::switchExclusiveToShared()
 {
     assert(writing);
diff -u -r -N squid-4.0.7/src/ipc/ReadWriteLock.h squid-4.0.8/src/ipc/ReadWriteLock.h
--- squid-4.0.7/src/ipc/ReadWriteLock.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/ipc/ReadWriteLock.h	2016-04-02 10:04:07.000000000 +1300
@@ -30,8 +30,10 @@
 
     bool lockShared(); ///< lock for reading or return false
     bool lockExclusive(); ///< lock for modification or return false
+    bool lockHeaders(); ///< lock for [readable] metadata update or return false
     void unlockShared(); ///< undo successful sharedLock()
     void unlockExclusive(); ///< undo successful exclusiveLock()
+    void unlockHeaders(); ///< undo successful lockHeaders()
     void switchExclusiveToShared(); ///< stop writing, start reading
 
     void startAppending(); ///< writer keeps its lock but also allows reading
@@ -42,7 +44,8 @@
 public:
     mutable std::atomic<uint32_t> readers; ///< number of reading users
     std::atomic<bool> writing; ///< there is a writing user (there can be at most 1)
-    std::atomic<bool> appending; ///< the writer has promissed to only append
+    std::atomic<bool> appending; ///< the writer has promised to only append
+    std::atomic_flag updating; ///< a reader is updating metadata/headers
 
 private:
     mutable std::atomic<uint32_t> readLevel; ///< number of users reading (or trying to)
@@ -66,6 +69,11 @@
     int appenders; ///< number of appending writers
 };
 
+/// Same as assert(flag is set): The process assert()s if flag is not set.
+/// Side effect: The unset flag becomes set just before we assert().
+/// Needed because atomic_flag cannot be compared with a boolean.
+void AssertFlagIsSet(std::atomic_flag &flag);
+
 } // namespace Ipc
 
 #endif /* SQUID_IPC_READ_WRITE_LOCK_H */
diff -u -r -N squid-4.0.7/src/ipc/StoreMap.cc squid-4.0.8/src/ipc/StoreMap.cc
--- squid-4.0.7/src/ipc/StoreMap.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/ipc/StoreMap.cc	2016-04-02 10:04:07.000000000 +1300
@@ -10,7 +10,7 @@
 
 #include "squid.h"
 #include "ipc/StoreMap.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "Store.h"
 #include "store_key_md5.h"
 #include "tools.h"
@@ -27,12 +27,19 @@
     return Ipc::Mem::Segment::Name(path, "anchors");
 }
 
+static SBuf
+StoreMapFileNosId(const SBuf &path)
+{
+    return Ipc::Mem::Segment::Name(path, "filenos");
+}
+
 Ipc::StoreMap::Owner *
 Ipc::StoreMap::Init(const SBuf &path, const int sliceLimit)
 {
     assert(sliceLimit > 0); // we should not be created otherwise
     const int anchorLimit = min(sliceLimit, static_cast<int>(SwapFilenMax));
     Owner *owner = new Owner;
+    owner->fileNos = shm_new(FileNos)(StoreMapFileNosId(path).c_str(), anchorLimit);
     owner->anchors = shm_new(Anchors)(StoreMapAnchorsId(path).c_str(), anchorLimit);
     owner->slices = shm_new(Slices)(StoreMapSlicesId(path).c_str(), sliceLimit);
     debugs(54, 5, "created " << path << " with " << anchorLimit << '+' << sliceLimit);
@@ -40,10 +47,12 @@
 }
 
 Ipc::StoreMap::StoreMap(const SBuf &aPath): cleaner(NULL), path(aPath),
+    fileNos(shm_old(FileNos)(StoreMapFileNosId(path).c_str())),
     anchors(shm_old(Anchors)(StoreMapAnchorsId(path).c_str())),
     slices(shm_old(Slices)(StoreMapSlicesId(path).c_str()))
 {
     debugs(54, 5, "attached " << path << " with " <<
+           fileNos->capacity << '+' <<
            anchors->capacity << '+' << slices->capacity);
     assert(entryLimit() > 0); // key-to-position mapping requires this
     assert(entryLimit() <= sliceLimit()); // at least one slice per entry
@@ -76,7 +85,6 @@
     // them; the caller is responsible for freeing them (most likely
     // our slice list is incomplete or has holes)
 
-    inode.waitingToBeFreed = false;
     inode.rewind();
 
     inode.lock.unlockExclusive();
@@ -90,7 +98,7 @@
 {
     debugs(54, 5, "opening entry with key " << storeKeyText(key)
            << " for writing " << path);
-    const int idx = anchorIndexByKey(key);
+    const int idx = fileNoByKey(key);
 
     if (Anchor *anchor = openForWritingAt(idx)) {
         fileno = idx;
@@ -123,6 +131,7 @@
 
         assert(s.empty());
         s.start = -1; // we have not allocated any slices yet
+        s.splicingPoint = -1;
         ++anchors->count;
 
         //s.setKey(key); // XXX: the caller should do that
@@ -208,6 +217,24 @@
     }
 }
 
+void
+Ipc::StoreMap::abortUpdating(Update &update)
+{
+    const sfileno fileno = update.stale.fileNo;
+    debugs(54, 5, "aborting entry " << fileno << " for updating " << path);
+    if (update.stale) {
+        AssertFlagIsSet(update.stale.anchor->lock.updating);
+        update.stale.anchor->lock.unlockHeaders();
+        closeForReading(update.stale.fileNo);
+        update.stale = Update::Edition();
+    }
+    if (update.fresh) {
+        abortWriting(update.fresh.fileNo);
+        update.fresh = Update::Edition();
+    }
+    debugs(54, 5, "aborted entry " << fileno << " for updating " << path);
+}
+
 const Ipc::StoreMap::Anchor *
 Ipc::StoreMap::peekAtReader(const sfileno fileno) const
 {
@@ -245,7 +272,7 @@
     debugs(54, 5, "marking entry with key " << storeKeyText(key)
            << " to be freed in " << path);
 
-    const int idx = anchorIndexByKey(key);
+    const int idx = fileNoByKey(key);
     Anchor &s = anchorAt(idx);
     if (s.lock.lockExclusive()) {
         if (s.sameKey(key))
@@ -269,21 +296,8 @@
 {
     debugs(54, 7, "freeing entry " << fileno <<
            " in " << path);
-    if (!inode.empty()) {
-        sfileno sliceId = inode.start;
-        debugs(54, 8, "first slice " << sliceId);
-        while (sliceId >= 0) {
-            Slice &slice = sliceAt(sliceId);
-            const sfileno nextId = slice.next;
-            slice.size = 0;
-            slice.next = -1;
-            if (cleaner)
-                cleaner->noteFreeMapSlice(sliceId); // might change slice state
-            sliceId = nextId;
-        }
-    }
-
-    inode.waitingToBeFreed = false;
+    if (!inode.empty())
+        freeChainAt(inode.start, inode.splicingPoint);
     inode.rewind();
 
     if (!keepLocked)
@@ -292,19 +306,62 @@
     debugs(54, 5, "freed entry " << fileno << " in " << path);
 }
 
+/// unconditionally frees an already locked chain of slots; no anchor maintenance
+void
+Ipc::StoreMap::freeChainAt(SliceId sliceId, const SliceId splicingPoint)
+{
+    static uint64_t ChainId = 0; // to pair freeing/freed calls in debugs()
+    const uint64_t chainId = ++ChainId;
+    debugs(54, 7, "freeing chain #" << chainId << " starting at " << sliceId << " in " << path);
+    while (sliceId >= 0) {
+        Slice &slice = sliceAt(sliceId);
+        const SliceId nextId = slice.next;
+        slice.size = 0;
+        slice.next = -1;
+        if (cleaner)
+            cleaner->noteFreeMapSlice(sliceId); // might change slice state
+        if (sliceId == splicingPoint) {
+            debugs(54, 5, "preserving chain #" << chainId << " in " << path <<
+                   " suffix after slice " << splicingPoint);
+            break; // do not free the rest of the chain
+        }
+        sliceId = nextId;
+    }
+    debugs(54, 7, "freed chain #" << chainId << " in " << path);
+}
+
+Ipc::StoreMap::SliceId
+Ipc::StoreMap::sliceContaining(const sfileno fileno, const uint64_t bytesNeeded) const
+{
+    const Anchor &anchor = anchorAt(fileno);
+    Must(anchor.reading());
+    uint64_t bytesSeen = 0;
+    SliceId lastSlice = anchor.start;
+    while (lastSlice >= 0) {
+        const Slice &slice = sliceAt(lastSlice);
+        bytesSeen += slice.size;
+        if (bytesSeen >= bytesNeeded)
+            break;
+        lastSlice = slice.next;
+    }
+    debugs(54, 7, "entry " << fileno << " has " << bytesNeeded << '/' << bytesSeen <<
+           " bytes at slice " << lastSlice << " in " << path);
+    return lastSlice; // may be negative
+}
+
 const Ipc::StoreMap::Anchor *
 Ipc::StoreMap::openForReading(const cache_key *const key, sfileno &fileno)
 {
     debugs(54, 5, "opening entry with key " << storeKeyText(key)
            << " for reading " << path);
-    const int idx = anchorIndexByKey(key);
+    const int idx = fileNoByKey(key);
     if (const Anchor *slot = openForReadingAt(idx)) {
         if (slot->sameKey(key)) {
             fileno = idx;
             return slot; // locked for reading
         }
         slot->lock.unlockShared();
-        debugs(54, 7, "closed entry " << idx << " for reading " << path);
+        debugs(54, 7, "closed wrong-key entry " << idx << " for reading " << path);
     }
     return NULL;
 }
@@ -349,14 +406,192 @@
 }
 
 bool
-Ipc::StoreMap::purgeOne()
+Ipc::StoreMap::openForUpdating(Update &update, const sfileno fileNoHint)
 {
-    // Hopefully, we find a removable entry much sooner (TODO: use time?).
+    Must(update.entry);
+    const StoreEntry &entry = *update.entry;
+    const cache_key *const key = reinterpret_cast<const cache_key*>(entry.key);
+    update.stale.name = nameByKey(key);
+
+    if (!validEntry(fileNoHint)) {
+        debugs(54, 5, "opening entry with key " << storeKeyText(key) <<
+               " for updating " << path);
+        update.stale.fileNo = fileNoByName(update.stale.name);
+    } else {
+        update.stale.fileNo = fileNoHint;
+    }
+
+    debugs(54, 5, "opening entry " << update.stale.fileNo << " of " << entry << " for updating " << path);
+
+    // Unreadable entries cannot (e.g., empty and otherwise problematic entries)
+    // or should not (e.g., entries still forming their metadata) be updated.
+    if (const Anchor *anchor = openForReadingAt(update.stale.fileNo)) {
+        if (!anchor->sameKey(key)) {
+            closeForReading(update.stale.fileNo);
+            debugs(54, 5, "cannot open wrong-key entry " << update.stale.fileNo << " for updating " << path);
+            return false;
+        }
+    } else {
+        debugs(54, 5, "cannot open unreadable entry " << update.stale.fileNo << " for updating " << path);
+        return false;
+    }
+
+    update.stale.anchor = &anchorAt(update.stale.fileNo);
+    if (update.stale.anchor->writing()) {
+        // TODO: Support updating appending entries.
+        // For example, MemStore::updateHeaders() would not know how
+        // many old prefix body bytes to copy to the new prefix if the last old
+        // prefix slice has not been formed yet (i.e., still gets more bytes).
+        debugs(54, 5, "cannot open appending entry " << update.stale.fileNo <<
+               " for updating " << path);
+        closeForReading(update.stale.fileNo);
+        return false;
+    }
+
+    if (!update.stale.anchor->lock.lockHeaders()) {
+        debugs(54, 5, "cannot open updating entry " << update.stale.fileNo <<
+               " for updating " << path);
+        closeForReading(update.stale.fileNo);
+        return false;
+    }
+
+    /* stale anchor is properly locked; we can now use abortUpdating() if needed */
+
+    if (!openKeyless(update.fresh)) {
+        debugs(54, 5, "cannot open freshchainless entry " << update.stale.fileNo <<
+               " for updating " << path);
+        abortUpdating(update);
+        return false;
+    }
+
+    Must(update.stale);
+    Must(update.fresh);
+    update.fresh.anchor->set(entry);
+    debugs(54, 5, "opened entry " << update.stale.fileNo << " for updating " << path <<
+           " using entry " << update.fresh.fileNo << " of " << entry);
+
+    return true;
+}
+
+/// finds an anchor that is currently not associated with any entry key and
+/// locks it for writing so ensure exclusive access during updates
+bool
+Ipc::StoreMap::openKeyless(Update::Edition &edition)
+{
+    return visitVictims([&](const sfileno name) {
+        Update::Edition temp;
+        temp.name = name;
+        temp.fileNo = fileNoByName(temp.name);
+        if ((temp.anchor = openForWritingAt(temp.fileNo))) {
+            debugs(54, 5, "created entry " << temp.fileNo <<
+                   " for updating " << path);
+            Must(temp);
+            edition = temp;
+            return true;
+        }
+        return false;
+    });
+}
+
+void
+Ipc::StoreMap::closeForUpdating(Update &update)
+{
+    Must(update.stale.anchor);
+    Must(update.fresh.anchor);
+    AssertFlagIsSet(update.stale.anchor->lock.updating);
+    Must(update.stale.splicingPoint >= 0);
+    Must(update.fresh.splicingPoint >= 0);
+
+    /* the stale prefix cannot overlap with the fresh one (a weak check) */
+    Must(update.stale.anchor->start != update.fresh.anchor->start);
+    Must(update.stale.anchor->start != update.fresh.splicingPoint);
+    Must(update.stale.splicingPoint != update.fresh.anchor->start);
+    Must(update.stale.splicingPoint != update.fresh.splicingPoint);
+
+    /* the relative order of most operations is significant here */
+
+    /* splice the fresh chain prefix with the stale chain suffix */
+    Slice &freshSplicingSlice = sliceAt(update.fresh.splicingPoint);
+    const SliceId suffixStart = sliceAt(update.stale.splicingPoint).next; // may be negative
+    // the fresh chain is either properly terminated or already spliced
+    if (freshSplicingSlice.next < 0)
+        freshSplicingSlice.next = suffixStart;
+    else
+        Must(freshSplicingSlice.next == suffixStart);
+    // either way, fresh chain uses the stale chain suffix now
+
+    // make the fresh anchor/chain readable for everybody
+    update.fresh.anchor->lock.switchExclusiveToShared();
+    // but the fresh anchor is still invisible to anybody but us
+
+    // This freeEntry() code duplicates the code below to minimize the time when
+    // the freeEntry() race condition (see the Race: comment below) might occur.
+    if (update.stale.anchor->waitingToBeFreed)
+        freeEntry(update.fresh.fileNo);
+
+    /* any external changes were applied to the stale anchor/chain until now */
+    relocate(update.stale.name, update.fresh.fileNo);
+    /* any external changes will apply to the fresh anchor/chain from now on */
+
+    // Race: If the stale entry was deleted by some kid during the assignment,
+    // then we propagate that event to the fresh anchor and chain. Since this
+    // update is not atomically combined with the assignment above, another kid
+    // might get a fresh entry just before we have a chance to free it. However,
+    // such deletion races are always possible even without updates.
+    if (update.stale.anchor->waitingToBeFreed)
+        freeEntry(update.fresh.fileNo);
+
+    /* free the stale chain prefix except for the shared suffix */
+    update.stale.anchor->splicingPoint = update.stale.splicingPoint;
+    freeEntry(update.stale.fileNo);
+
+    // make the stale anchor/chain reusable, reachable via its new location
+    relocate(update.fresh.name, update.stale.fileNo);
+
+    const Update updateSaved = update; // for post-close debugging below
+
+    /* unlock the stale anchor/chain */
+    update.stale.anchor->lock.unlockHeaders();
+    closeForReading(update.stale.fileNo);
+    update.stale = Update::Edition();
+
+    // finally, unlock the fresh entry
+    closeForReading(update.fresh.fileNo);
+    update.fresh = Update::Edition();
+
+    debugs(54, 5, "closed entry " << updateSaved.stale.fileNo << " of " << *updateSaved.entry <<
+           " named " << updateSaved.stale.name << " for updating " << path <<
+           " to fresh entry " << updateSaved.fresh.fileNo << " named " << updateSaved.fresh.name <<
+           " with [" << updateSaved.fresh.anchor->start << ',' << updateSaved.fresh.splicingPoint <<
+           "] prefix containing at least " << freshSplicingSlice.size << " bytes");
+}
+
+/// Visits entries until either
+/// * the `visitor` returns true (indicating its satisfaction with the offer);
+/// * we give up finding a suitable entry because it already took "too long"; or
+/// * we have offered all entries.
+bool
+Ipc::StoreMap::visitVictims(const NameFilter visitor)
+{
+    // Hopefully, we find a usable entry much sooner (TODO: use time?).
     // The min() will protect us from division by zero inside the loop.
     const int searchLimit = min(10000, entryLimit());
     int tries = 0;
     for (; tries < searchLimit; ++tries) {
-        const sfileno fileno = static_cast<sfileno>(++anchors->victim % entryLimit());
+        const sfileno name = static_cast<sfileno>(++anchors->victim % entryLimit());
+        if (visitor(name))
+            return true;
+    }
+
+    debugs(54, 5, "no victims found in " << path << "; tried: " << tries);
+    return false;
+}
+
+bool
+Ipc::StoreMap::purgeOne()
+{
+    return visitVictims([&](const sfileno name) {
+        const sfileno fileno = fileNoByName(name);
         Anchor &s = anchorAt(fileno);
         if (s.lock.lockExclusive()) {
             // the caller wants a free slice; empty anchor is not enough
@@ -368,9 +603,8 @@
             }
             s.lock.unlockExclusive();
         }
-    }
-    debugs(54, 5, "no entries to purge from " << path << "; tried: " << tries);
-    return false;
+        return false;
+    });
 }
 
 void
@@ -435,17 +669,43 @@
 }
 
 sfileno
-Ipc::StoreMap::anchorIndexByKey(const cache_key *const key) const
+Ipc::StoreMap::nameByKey(const cache_key *const key) const
 {
     const uint64_t *const k = reinterpret_cast<const uint64_t *>(key);
     // TODO: use a better hash function
-    return (k[0] + k[1]) % entryLimit();
+    const int hash = (k[0] + k[1]) % entryLimit();
+    return hash;
+}
+
+sfileno
+Ipc::StoreMap::fileNoByName(const sfileno name) const
+{
+    // fileNos->items are initialized to zero, which we treat as "name is fileno";
+    // a positive value means the entry anchor got moved to a new fileNo
+    if (const int item = fileNos->items[name])
+        return item-1;
+    return name;
+}
+
+/// map `name` to `fileNo`
+void
+Ipc::StoreMap::relocate(const sfileno name, const sfileno fileno)
+{
+    // preserve special meaning for zero; see fileNoByName
+    fileNos->items[name] = fileno+1;
+}
+
+sfileno
+Ipc::StoreMap::fileNoByKey(const cache_key *const key) const
+{
+    const int name = nameByKey(key);
+    return fileNoByName(name);
 }
 
 Ipc::StoreMap::Anchor &
 Ipc::StoreMap::anchorByKey(const cache_key *const key)
 {
-    return anchorAt(anchorIndexByKey(key));
+    return anchorAt(fileNoByKey(key));
 }
 
 Ipc::StoreMap::Slice&
@@ -463,7 +723,7 @@
 
 /* Ipc::StoreMapAnchor */
 
-Ipc::StoreMapAnchor::StoreMapAnchor(): start(0)
+Ipc::StoreMapAnchor::StoreMapAnchor(): start(0), splicingPoint(-1)
 {
     memset(&key, 0, sizeof(key));
     memset(&basics, 0, sizeof(basics));
@@ -502,17 +762,46 @@
 {
     assert(writing());
     start = 0;
+    splicingPoint = -1;
     memset(&key, 0, sizeof(key));
     memset(&basics, 0, sizeof(basics));
+    waitingToBeFreed = false;
     // but keep the lock
 }
 
-Ipc::StoreMap::Owner::Owner(): anchors(NULL), slices(NULL)
+/* Ipc::StoreMapUpdate */
+
+Ipc::StoreMapUpdate::StoreMapUpdate(StoreEntry *anEntry):
+    entry(anEntry)
+{
+    entry->lock("Ipc::StoreMapUpdate1");
+}
+
+Ipc::StoreMapUpdate::StoreMapUpdate(const StoreMapUpdate &other):
+    entry(other.entry),
+    stale(other.stale),
+    fresh(other.fresh)
+{
+    entry->lock("Ipc::StoreMapUpdate2");
+}
+
+Ipc::StoreMapUpdate::~StoreMapUpdate()
+{
+    entry->unlock("Ipc::StoreMapUpdate");
+}
+
+/* Ipc::StoreMap::Owner */
+
+Ipc::StoreMap::Owner::Owner():
+    fileNos(nullptr),
+    anchors(nullptr),
+    slices(nullptr)
 {
 }
 
 Ipc::StoreMap::Owner::~Owner()
 {
+    delete fileNos;
     delete anchors;
     delete slices;
 }
diff -u -r -N squid-4.0.7/src/ipc/StoreMap.h squid-4.0.8/src/ipc/StoreMap.h
--- squid-4.0.7/src/ipc/StoreMap.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/ipc/StoreMap.h	2016-04-02 10:04:07.000000000 +1300
@@ -12,10 +12,12 @@
 #include "ipc/mem/FlexibleArray.h"
 #include "ipc/mem/Pointer.h"
 #include "ipc/ReadWriteLock.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "store/forward.h"
 #include "store_key_md5.h"
 
+#include <functional>
+
 namespace Ipc
 {
 
@@ -74,6 +76,7 @@
     std::atomic<uint8_t> waitingToBeFreed; ///< may be accessed w/o a lock
 
     // fields marked with [app] can be modified when appending-while-reading
+    // fields marked with [update] can be modified when updating-while-reading
 
     uint64_t key[2]; ///< StoreEntry key
 
@@ -90,6 +93,10 @@
 
     /// where the chain of StoreEntry slices begins [app]
     std::atomic<StoreMapSliceId> start;
+
+    /// where the updated chain prefix containing metadata/headers ends [update]
+    /// if unset, this anchor points to a chain that was never updated
+    std::atomic<StoreMapSliceId> splicingPoint;
 };
 
 /// an array of shareable Items
@@ -113,7 +120,7 @@
 /// StoreMapSlices indexed by their slice ID.
 typedef StoreMapItems<StoreMapSlice> StoreMapSlices;
 
-/// StoreMapAnchors indexed by entry fileno plus
+/// StoreMapAnchors (indexed by fileno) plus
 /// sharing-safe basic housekeeping info about Store entries
 class StoreMapAnchors
 {
@@ -132,20 +139,58 @@
 };
 // TODO: Find an elegant way to use StoreMapItems in StoreMapAnchors
 
+/// StoreMapAnchor positions, indexed by entry "name" (i.e., the entry key hash)
+typedef StoreMapItems< std::atomic<sfileno> > StoreMapFileNos;
+
+/// Aggregates information required for updating entry metadata and headers.
+class StoreMapUpdate
+{
+public:
+    /// During an update, the stored entry has two editions: stale and fresh.
+    class Edition
+    {
+    public:
+        Edition(): anchor(nullptr), fileNo(-1), name(-1), splicingPoint(-1) {}
+
+        /// whether this entry edition is currently used/initialized
+        explicit operator bool() const { return anchor; }
+
+        StoreMapAnchor *anchor; ///< StoreMap::anchors[fileNo], for convenience/speed
+        sfileno fileNo; ///< StoreMap::fileNos[name], for convenience/speed
+        sfileno name; ///< StoreEntry position in StoreMap::fileNos, for swapping Editions
+
+        /// the last slice in the chain still containing metadata/headers
+        StoreMapSliceId splicingPoint;
+    };
+
+    explicit StoreMapUpdate(StoreEntry *anEntry);
+    StoreMapUpdate(const StoreMapUpdate &other);
+    ~StoreMapUpdate();
+
+    StoreMapUpdate &operator =(const StoreMapUpdate &other) = delete;
+
+    StoreEntry *entry; ///< the store entry being updated
+    Edition stale; ///< old anchor and chain being updated
+    Edition fresh; ///< new anchor and updated chain prefix
+};
+
 class StoreMapCleaner;
 
 /// Manages shared Store index (e.g., locking/unlocking/freeing entries) using
-/// StoreMapAnchors indexed by their keys and
-/// StoreMapSlices indexed by their slide ID.
+/// StoreMapFileNos indexed by hashed entry keys (a.k.a. entry names),
+/// StoreMapAnchors indexed by fileno, and
+/// StoreMapSlices indexed by slice ID.
 class StoreMap
 {
 public:
+    typedef StoreMapFileNos FileNos;
     typedef StoreMapAnchor Anchor;
     typedef StoreMapAnchors Anchors;
     typedef sfileno AnchorId;
     typedef StoreMapSlice Slice;
     typedef StoreMapSlices Slices;
     typedef StoreMapSliceId SliceId;
+    typedef StoreMapUpdate Update;
 
 public:
     /// aggregates anchor and slice owners for Init() caller convenience
@@ -154,6 +199,7 @@
     public:
         Owner();
         ~Owner();
+        FileNos::Owner *fileNos;
         Anchors::Owner *anchors;
         Slices::Owner *slices;
     private:
@@ -166,8 +212,8 @@
 
     StoreMap(const SBuf &aPath);
 
-    /// computes map entry position for a given entry key
-    sfileno anchorIndexByKey(const cache_key *const key) const;
+    /// computes map entry anchor position for a given entry key
+    sfileno fileNoByKey(const cache_key *const key) const;
 
     /// Like strcmp(mapped, new), but for store entry versions/timestamps.
     /// Returns +2 if the mapped entry does not exist; -1/0/+1 otherwise.
@@ -188,6 +234,13 @@
     /// this call does not free entry slices so the caller has to do that
     void forgetWritingEntry(const sfileno fileno);
 
+    /// finds and locks the Update entry for an exclusive metadata update
+    bool openForUpdating(Update &update, sfileno fileNoHint);
+    /// makes updated info available to others, unlocks, and cleans up
+    void closeForUpdating(Update &update);
+    /// undoes partial update, unlocks, and cleans up
+    void abortUpdating(Update &update);
+
     /// only works on locked entries; returns nil unless the slice is readable
     const Anchor *peekAtReader(const sfileno fileno) const;
 
@@ -216,6 +269,11 @@
     /// readable anchor for the entry created by openForReading()
     const Anchor &readableEntry(const AnchorId anchorId) const;
 
+    /// Returns the ID of the entry slice containing n-th byte or
+    /// a negative ID if the entry does not store that many bytes (yet).
+    /// Requires a read lock.
+    SliceId sliceContaining(const sfileno fileno, const uint64_t nth) const;
+
     /// stop writing the entry, freeing its slot for others to use if possible
     void abortWriting(const sfileno fileno);
 
@@ -239,10 +297,17 @@
 
 protected:
     const SBuf path; ///< cache_dir path or similar cache name; for logging
+    Mem::Pointer<StoreMapFileNos> fileNos; ///< entry inodes (starting blocks)
     Mem::Pointer<StoreMapAnchors> anchors; ///< entry inodes (starting blocks)
     Mem::Pointer<StoreMapSlices> slices; ///< chained entry pieces positions
 
 private:
+    /// computes entry name (i.e., key hash) for a given entry key
+    sfileno nameByKey(const cache_key *const key) const;
+    /// computes anchor position for a given entry name
+    sfileno fileNoByName(const sfileno name) const;
+    void relocate(const sfileno name, const sfileno fileno);
+
     Anchor &anchorAt(const sfileno fileno);
     const Anchor &anchorAt(const sfileno fileno) const;
     Anchor &anchorByKey(const cache_key *const key);
@@ -250,8 +315,14 @@
     Slice &sliceAt(const SliceId sliceId);
     const Slice &sliceAt(const SliceId sliceId) const;
     Anchor *openForReading(Slice &s);
+    bool openKeyless(Update::Edition &edition);
+    void closeForUpdateFinal(Update &update);
+
+    typedef std::function<bool (const sfileno name)> NameFilter; // a "name"-based test
+    bool visitVictims(const NameFilter filter);
 
     void freeChain(const sfileno fileno, Anchor &inode, const bool keepLock);
+    void freeChainAt(SliceId sliceId, const SliceId splicingPoint);
 };
 
 /// API for adjusting external state when dirty map slice is being freed
diff -u -r -N squid-4.0.7/src/ipc/TypedMsgHdr.cc squid-4.0.8/src/ipc/TypedMsgHdr.cc
--- squid-4.0.7/src/ipc/TypedMsgHdr.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/ipc/TypedMsgHdr.cc	2016-04-02 10:04:07.000000000 +1300
@@ -11,6 +11,7 @@
 #include "squid.h"
 #include "base/TextException.h"
 #include "ipc/TypedMsgHdr.h"
+#include "SquidString.h"
 #include "tools.h"
 
 #include <cstring>
diff -u -r -N squid-4.0.7/src/log/access_log.cc squid-4.0.8/src/log/access_log.cc
--- squid-4.0.7/src/log/access_log.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/log/access_log.cc	2016-04-02 10:04:07.000000000 +1300
@@ -17,8 +17,6 @@
 #include "CachePeer.h"
 #include "err_detail_type.h"
 #include "errorpage.h"
-#include "errorpage.h"
-#include "errorpage.h"
 #include "format/Token.h"
 #include "globals.h"
 #include "hier_code.h"
@@ -76,8 +74,8 @@
 accessLogLogTo(CustomLog* log, AccessLogEntry::Pointer &al, ACLChecklist * checklist)
 {
 
-    if (al->url == NULL)
-        al->url = dash_str;
+    if (al->url.isEmpty())
+        al->url = Format::Dash;
 
     if (!al->http.content_type || *al->http.content_type == '\0')
         al->http.content_type = dash_str;
@@ -160,8 +158,8 @@
     else {
         unsigned int ibuf[365];
         size_t isize;
-        xstrncpy((char *) ibuf, al->url, 364 * sizeof(int));
-        isize = ((strlen(al->url) + 8) / 8) * 2;
+        xstrncpy((char *) ibuf, al->url.c_str(), 364 * sizeof(int));
+        isize = ((al->url.length() + 8) / 8) * 2;
 
         if (isize > 364)
             isize = 364;
diff -u -r -N squid-4.0.7/src/log/DB/log_db_daemon.8 squid-4.0.8/src/log/DB/log_db_daemon.8
--- squid-4.0.7/src/log/DB/log_db_daemon.8	2016-02-24 07:40:23.000000000 +1300
+++ squid-4.0.8/src/log/DB/log_db_daemon.8	2016-04-02 11:49:21.000000000 +1300
@@ -133,7 +133,7 @@
 .\" ========================================================================
 .\"
 .IX Title "LOG_DB_DAEMON 8"
-.TH LOG_DB_DAEMON 8 "2016-02-23" "perl v5.22.1" "User Contributed Perl Documentation"
+.TH LOG_DB_DAEMON 8 "2016-04-01" "perl v5.22.1" "User Contributed Perl Documentation"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
diff -u -r -N squid-4.0.7/src/log/DB/Makefile.in squid-4.0.8/src/log/DB/Makefile.in
--- squid-4.0.7/src/log/DB/Makefile.in	2016-02-24 06:49:38.000000000 +1300
+++ squid-4.0.8/src/log/DB/Makefile.in	2016-04-02 10:07:48.000000000 +1300
@@ -624,6 +624,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = log_db_daemon $(am__append_2)
diff -u -r -N squid-4.0.7/src/log/file/Makefile.in squid-4.0.8/src/log/file/Makefile.in
--- squid-4.0.7/src/log/file/Makefile.in	2016-02-24 06:49:39.000000000 +1300
+++ squid-4.0.8/src/log/file/Makefile.in	2016-04-02 10:07:51.000000000 +1300
@@ -672,6 +672,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/src/log/FormatHttpdCombined.cc squid-4.0.8/src/log/FormatHttpdCombined.cc
--- squid-4.0.7/src/log/FormatHttpdCombined.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/log/FormatHttpdCombined.cc	2016-04-02 10:04:07.000000000 +1300
@@ -47,13 +47,13 @@
 
     const SBuf method(al->getLogMethod());
 
-    logfilePrintf(logfile, "%s %s %s [%s] \"" SQUIDSBUFPH " %s %s/%d.%d\" %d %" PRId64 " \"%s\" \"%s\" %s:%s%s",
+    logfilePrintf(logfile, "%s %s %s [%s] \"" SQUIDSBUFPH " " SQUIDSBUFPH " %s/%d.%d\" %d %" PRId64 " \"%s\" \"%s\" %s:%s%s",
                   clientip,
                   user_ident ? user_ident : dash_str,
                   user_auth ? user_auth : dash_str,
                   Time::FormatHttpd(squid_curtime),
                   SQUIDSBUFPRINT(method),
-                  al->url,
+                  SQUIDSBUFPRINT(al->url),
                   AnyP::ProtocolType_str[al->http.version.protocol],
                   al->http.version.major, al->http.version.minor,
                   al->http.code,
diff -u -r -N squid-4.0.7/src/log/FormatHttpdCommon.cc squid-4.0.8/src/log/FormatHttpdCommon.cc
--- squid-4.0.7/src/log/FormatHttpdCommon.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/log/FormatHttpdCommon.cc	2016-04-02 10:04:07.000000000 +1300
@@ -34,13 +34,13 @@
 
     const SBuf method(al->getLogMethod());
 
-    logfilePrintf(logfile, "%s %s %s [%s] \"" SQUIDSBUFPH " %s %s/%d.%d\" %d %" PRId64 " %s:%s%s",
+    logfilePrintf(logfile, "%s %s %s [%s] \"" SQUIDSBUFPH " " SQUIDSBUFPH " %s/%d.%d\" %d %" PRId64 " %s:%s%s",
                   clientip,
                   user_ident ? user_ident : dash_str,
                   user_auth ? user_auth : dash_str,
                   Time::FormatHttpd(squid_curtime),
                   SQUIDSBUFPRINT(method),
-                  al->url,
+                  SQUIDSBUFPRINT(al->url),
                   AnyP::ProtocolType_str[al->http.version.protocol],
                   al->http.version.major, al->http.version.minor,
                   al->http.code,
diff -u -r -N squid-4.0.7/src/log/FormatSquidNative.cc squid-4.0.8/src/log/FormatSquidNative.cc
--- squid-4.0.7/src/log/FormatSquidNative.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/log/FormatSquidNative.cc	2016-04-02 10:04:07.000000000 +1300
@@ -50,7 +50,7 @@
 
     const SBuf method(al->getLogMethod());
 
-    logfilePrintf(logfile, "%9ld.%03d %6ld %s %s/%03d %" PRId64 " " SQUIDSBUFPH " %s %s %s%s/%s %s%s",
+    logfilePrintf(logfile, "%9ld.%03d %6ld %s %s/%03d %" PRId64 " " SQUIDSBUFPH " " SQUIDSBUFPH " %s %s%s/%s %s%s",
                   (long int) current_time.tv_sec,
                   (int) current_time.tv_usec / 1000,
                   tvToMsec(al->cache.trTime),
@@ -59,7 +59,7 @@
                   al->http.code,
                   al->http.clientReplySz.messageTotal(),
                   SQUIDSBUFPRINT(method),
-                  al->url,
+                  SQUIDSBUFPRINT(al->url),
                   user ? user : dash_str,
                   al->hier.ping.timedout ? "TIMEOUT_" : "",
                   hier_code_str[al->hier.code],
diff -u -r -N squid-4.0.7/src/log/FormatSquidReferer.cc squid-4.0.8/src/log/FormatSquidReferer.cc
--- squid-4.0.7/src/log/FormatSquidReferer.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/log/FormatSquidReferer.cc	2016-04-02 10:04:07.000000000 +1300
@@ -28,11 +28,13 @@
     char clientip[MAX_IPSTRLEN];
     al->getLogClientIp(clientip, MAX_IPSTRLEN);
 
-    logfilePrintf(logfile, "%9ld.%03d %s %s %s\n",
+    const SBuf url = !al->url.isEmpty() ? al->url : ::Format::Dash;
+
+    logfilePrintf(logfile, "%9ld.%03d %s %s " SQUIDSBUFPH "\n",
                   (long int) current_time.tv_sec,
                   (int) current_time.tv_usec / 1000,
                   clientip,
                   referer,
-                  al->url ? al->url : "-");
+                  SQUIDSBUFPRINT(url));
 }
 
diff -u -r -N squid-4.0.7/src/log/Makefile.in squid-4.0.8/src/log/Makefile.in
--- squid-4.0.7/src/log/Makefile.in	2016-02-24 06:49:39.000000000 +1300
+++ squid-4.0.8/src/log/Makefile.in	2016-04-02 10:07:50.000000000 +1300
@@ -729,6 +729,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/log/TcpLogger.cc squid-4.0.8/src/log/TcpLogger.cc
--- squid-4.0.7/src/log/TcpLogger.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/log/TcpLogger.cc	2016-04-02 10:04:07.000000000 +1300
@@ -18,8 +18,8 @@
 #include "log/CustomLog.h"
 #include "log/File.h"
 #include "log/TcpLogger.h"
-#include "MemBlob.h"
 #include "Parsing.h"
+#include "sbuf/MemBlob.h"
 #include "SquidConfig.h"
 #include "SquidTime.h"
 
diff -u -r -N squid-4.0.7/src/main.cc squid-4.0.8/src/main.cc
--- squid-4.0.7/src/main.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/main.cc	2016-04-02 10:04:07.000000000 +1300
@@ -383,6 +383,8 @@
             "       -D        OBSOLETE. Scheduled for removal.\n"
             "       -F        Don't serve any requests until store is rebuilt.\n"
             "       -N        No daemon mode.\n"
+            "       --foreground\n"
+            "                 Parent process does not exit until its children have finished.\n"
 #if USE_WIN32_SERVICE
             "       -O options\n"
             "                 Set Windows Service Command line options in Registry.\n"
@@ -415,8 +417,9 @@
 
     // long options
     static struct option squidOptions[] = {
-        {"help",    no_argument, 0, 'h'},
-        {"version", no_argument, 0, 'v'},
+        {"foreground", no_argument, 0,  1 },
+        {"help",       no_argument, 0, 'h'},
+        {"version",    no_argument, 0, 'v'},
         {0, 0, 0, 0}
     };
 
@@ -674,6 +677,12 @@
             opt_create_swap_dirs = 1;
             break;
 
+        case 1:
+            /** \par --foreground
+             * Set global option opt_foreground */
+            opt_foreground = 1;
+            break;
+
         case 'h':
 
         case '?':
@@ -1446,6 +1455,10 @@
 
     mainParseOptions(argc, argv);
 
+    if (opt_foreground && opt_no_daemon) {
+        debugs(1, DBG_CRITICAL, "WARNING: --foreground command-line option has no effect with -N.");
+    }
+
     if (opt_parse_cfg_only) {
         Debug::parseOptions("ALL,1");
     }
@@ -1781,7 +1794,7 @@
 {
 #if !_SQUID_WINDOWS_
     char *prog;
-    PidStatus status;
+    PidStatus status_f, status;
     pid_t pid;
 #ifdef TIOCNOTTY
 
@@ -1794,8 +1807,16 @@
 
     if ((pid = fork()) < 0)
         syslog(LOG_ALERT, "fork failed: %s", xstrerror());
-    else if (pid > 0)
+    else if (pid > 0) {
+        // parent
+        if (opt_foreground) {
+            if (WaitForAnyPid(status_f, 0) < 0) {
+                syslog(LOG_ALERT, "WaitForAnyPid failed: %s", xstrerror());
+            }
+        }
+
         exit(0);
+    }
 
     if (setsid() < 0)
         syslog(LOG_ALERT, "setsid failed: %s", xstrerror());
@@ -2015,6 +2036,9 @@
 
     WIN32_svcstatusupdate(SERVICE_STOP_PENDING, 10000);
 #endif
+#if ICAP_CLIENT
+    Adaptation::Icap::TheConfig.freeService();
+#endif
 
     Store::Root().sync(); /* Flush pending object writes/unlinks */
 
diff -u -r -N squid-4.0.7/src/Makefile.am squid-4.0.8/src/Makefile.am
--- squid-4.0.7/src/Makefile.am	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/Makefile.am	2016-04-02 10:04:07.000000000 +1300
@@ -10,17 +10,6 @@
 DNSSOURCE = \
 	dns_internal.cc
 
-SBUF_SOURCE= \
-	base/CharacterSet.h \
-	base/InstanceId.h \
-	MemBlob.h \
-	MemBlob.cc \
-	OutOfBoundsException.h \
-	SBuf.h \
-	SBuf.cc \
-	SBufExceptions.h \
-	SBufExceptions.cc
-
 STOREMETA_SOURCE = \
 	StoreMeta.cc \
 	StoreMeta.h \
@@ -42,8 +31,8 @@
 	LoadableModules.h \
 	LoadableModules.cc
 
-SUBDIRS	= mem base anyp helper dns ftp parser comm eui acl format clients servers fs repl store DiskIO
-DIST_SUBDIRS = mem base anyp helper dns ftp parser comm eui acl format clients servers fs repl store DiskIO
+SUBDIRS	= mem base anyp helper dns ftp parser comm eui acl format clients sbuf servers fs repl store DiskIO
+DIST_SUBDIRS = mem base anyp helper dns ftp parser comm eui acl format clients sbuf servers fs repl store DiskIO
 
 if ENABLE_AUTH
 SUBDIRS += auth
@@ -421,13 +410,9 @@
 	RemovalPolicy.h \
 	send-announce.h \
 	send-announce.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
-	SBufDetailedStats.cc \
 	SBufStatsAction.h \
 	SBufStatsAction.cc \
+	sbuf/StringConvert.h \
 	$(SNMP_SOURCE) \
 	SquidMath.h \
 	SquidMath.cc \
@@ -571,6 +556,7 @@
 	icmp/libicmp.la \
 	log/liblog.la \
 	format/libformat.la \
+	sbuf/libsbuf.la \
 	$(XTRA_OBJS) \
 	$(REPL_OBJS) \
 	$(NETTLELIB) \
@@ -739,26 +725,6 @@
 	mib.txt \
 	mime.conf.default
 
-DEFAULT_HTTP_PORT	= 3128
-DEFAULT_ICP_PORT	= 3130
-DEFAULT_PREFIX		= $(prefix)
-DEFAULT_CONFIG_DIR	= $(sysconfdir)
-DEFAULT_CONFIG_FILE	= $(DEFAULT_CONFIG_DIR)/squid.conf
-DEFAULT_MIME_TABLE	= $(DEFAULT_CONFIG_DIR)/mime.conf
-DEFAULT_SSL_CRTD	= $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
-DEFAULT_LOG_PREFIX	= $(DEFAULT_LOG_DIR)
-DEFAULT_CACHE_LOG	= $(DEFAULT_LOG_PREFIX)/cache.log
-DEFAULT_ACCESS_LOG	= $(DEFAULT_LOG_PREFIX)/access.log
-DEFAULT_STORE_LOG	= $(DEFAULT_LOG_PREFIX)/store.log
-DEFAULT_NETDB_FILE	= $(DEFAULT_LOG_PREFIX)/netdb.state
-DEFAULT_SSL_DB_DIR	= $(localstatedir)/lib/ssl_db
-DEFAULT_PINGER		= $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
-DEFAULT_UNLINKD		= $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
-DEFAULT_LOGFILED	= $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
-DEFAULT_DISKD		= $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
-DEFAULT_ICON_DIR	= $(datadir)/icons
-DEFAULT_ERROR_DIR	= $(datadir)/errors
-
 # Make location configure settings available to the code
 DEFS += -DDEFAULT_CONFIG_FILE=\"$(DEFAULT_CONFIG_FILE)\" -DDEFAULT_SQUID_DATA_DIR=\"$(datadir)\" -DDEFAULT_SQUID_CONFIG_DIR=\"$(sysconfdir)\"
 
@@ -951,9 +917,7 @@
 #tests_testX_LDADD=\
 #	$(SQUID_CPPUNIT_LIBS) \
 #	$(SQUID_CPPUNIT_LA) \
-#	$(COMPAT_LIB) \
-#tests_testX_DEPENDENCIES= $(SQUID_CPPUNIT_LA)
-
+#	$(COMPAT_LIB) 
 
 # - add other component .(h|cc) files needed to link and run tests
 tests_testHttpReply_SOURCES=\
@@ -998,10 +962,6 @@
 	Notes.cc \
 	SquidString.h \
 	SquidTime.h \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	String.cc \
 	StrList.h \
@@ -1054,6 +1014,7 @@
 	base/libbase.la \
 	ipc/libipc.la \
 	mem/libmem.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
 	$(top_builddir)/lib/libmiscutil.la \
@@ -1063,7 +1024,6 @@
 	$(SSLLIB) \
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
-tests_testHttpReply_DEPENDENCIES= $(SQUID_CPPUNIT_LA)
 
 tests_testACLMaxUserIP_SOURCES= \
 	cbdata.cc \
@@ -1111,10 +1071,6 @@
 	StrList.cc \
 	tests/stub_StatHist.cc \
 	stmem.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	String.cc \
 	StoreIOState.cc \
@@ -1189,6 +1145,7 @@
 	ip/libip.la \
 	ipc/libipc.la \
 	mgr/libmgr.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
 	$(top_builddir)/lib/libmiscutil.la \
@@ -1199,8 +1156,6 @@
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 tests_testACLMaxUserIP_LDFLAGS = $(LIBADD_DL)
-##tests_testACLMaxUserIP_DEPENDENCIES = \
-##	$(SQUID_CPPUNIT_LA)
 
 ## a demonstration test that does nothing but shows the salient points
 ## involved in writing tests.
@@ -1216,13 +1171,12 @@
 	$(TESTSOURCES)
 tests_testBoilerplate_LDADD= \
 	$(SQUID_CPPUNIT_LIBS) \
+	$(SQUID_CPPUNIT_LA) \
 	$(SSLLIB) \
 	base/libbase.la \
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 tests_testBoilerplate_LDFLAGS = $(LIBADD_DL)
-tests_testBoilerplate_DEPENDENCIES = \
-	$(SQUID_CPPUNIT_LA)
 
 ## Tests of base/libbase.la objects
 tests_testCharacterSet_SOURCES = \
@@ -1379,10 +1333,6 @@
 	refresh.h \
 	refresh.cc \
 	RemovalPolicy.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	$(SNMP_SOURCE) \
 	SquidMath.h \
@@ -1473,6 +1423,7 @@
 	$(SNMP_LIBS) \
 	mem/libmem.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
 	$(top_builddir)/lib/libmiscutil.la \
@@ -1485,9 +1436,6 @@
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 tests_testCacheManager_LDFLAGS = $(LIBADD_DL)
-tests_testCacheManager_DEPENDENCIES = \
-	$(REPL_OBJS) \
-	$(SQUID_CPPUNIT_LA)
 
 tests_testDiskIO_SOURCES = \
 	CacheDigest.h \
@@ -1552,10 +1500,6 @@
 	StatHist.h \
 	tests/stub_StatHist.cc \
 	stmem.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	StoreFileSystem.cc \
 	StoreIOState.cc \
@@ -1652,6 +1596,7 @@
 	base/libbase.la \
 	mem/libmem.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
 	$(top_builddir)/lib/libmiscutil.la \
@@ -1661,7 +1606,6 @@
 	$(SSLLIB) \
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
-
 tests_testDiskIO_LDFLAGS = $(LIBADD_DL)
 tests_testDiskIO_DEPENDENCIES = \
 	DiskIO/libdiskio.la \
@@ -1818,10 +1762,6 @@
 	RemovalPolicy.cc \
 	StrList.h \
 	StrList.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	$(SNMP_SOURCE) \
 	SquidMath.cc \
@@ -1917,6 +1857,7 @@
 	ipc/libipc.la \
 	mgr/libmgr.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	$(SNMP_LIBS) \
 	$(NETTLELIB) \
 	$(REGEXLIB) \
@@ -1927,9 +1868,6 @@
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 tests_testEvent_LDFLAGS = $(LIBADD_DL)
-tests_testEvent_DEPENDENCIES = \
-	$(REPL_OBJS) \
-	$(SQUID_CPPUNIT_LA)
 
 ## Tests of the EventLoop module.
 tests_testEventLoop_SOURCES = \
@@ -2061,10 +1999,6 @@
 	tests/stub_redirect.cc \
 	refresh.h \
 	refresh.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	$(SNMP_SOURCE) \
 	SquidMath.h \
@@ -2161,6 +2095,7 @@
 	$(top_builddir)/lib/libmiscutil.la \
 	ipc/libipc.la \
 	mgr/libmgr.la \
+	sbuf/libsbuf.la \
 	store/libstore.la \
 	$(SNMP_LIBS) \
 	$(NETTLELIB) \
@@ -2172,9 +2107,6 @@
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 tests_testEventLoop_LDFLAGS = $(LIBADD_DL)
-tests_testEventLoop_DEPENDENCIES = \
-	$(REPL_OBJS) \
-	$(SQUID_CPPUNIT_LA)
 
 tests_test_http_range_SOURCES = \
 	AccessLogEntry.cc \
@@ -2302,10 +2234,6 @@
 	refresh.h \
 	refresh.cc \
 	RemovalPolicy.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	$(SNMP_SOURCE) \
 	SquidMath.h \
@@ -2399,6 +2327,7 @@
 	dns/libdns.la \
 	base/libbase.la \
 	mgr/libmgr.la \
+	sbuf/libsbuf.la \
 	store/libstore.la \
 	$(SNMP_LIBS) \
 	$(top_builddir)/lib/libmisccontainers.la \
@@ -2413,8 +2342,6 @@
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 tests_test_http_range_LDFLAGS = $(LIBADD_DL)
-tests_test_http_range_DEPENDENCIES = \
-	$(SQUID_CPPUNIT_LA)
 
 ## Tests of parser/* objects
 tests_testTokenizer_SOURCES = \
@@ -2422,7 +2349,6 @@
 	tests/testTokenizer.cc
 nodist_tests_testTokenizer_SOURCES = \
 	parser/Tokenizer.h \
-	$(SBUF_SOURCE) \
 	SquidString.h \
 	String.cc \
 	$(TESTSOURCES) \
@@ -2434,6 +2360,7 @@
 tests_testTokenizer_LDADD = \
 	parser/libparser.la \
 	base/libbase.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmiscutil.la \
 	$(COMPAT_LIB) \
 	$(SQUID_CPPUNIT_LA) \
@@ -2449,9 +2376,6 @@
 	mime_header.h \
 	String.cc \
 	cache_cf.h \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
 	tests/stub_SBufDetailedStats.cc \
 	tests/stub_cache_cf.cc \
 	tests/stub_cache_manager.cc \
@@ -2481,14 +2405,14 @@
 	SquidConfig.o \
 	base/libbase.la \
 	ip/libip.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmiscutil.la \
 	$(SQUID_CPPUNIT_LIBS) \
+	$(SQUID_CPPUNIT_LA) \
 	$(SSLLIB) \
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 tests_testHttp1Parser_LDFLAGS = $(LIBADD_DL)
-tests_testHttp1Parser_DEPENDENCIES = \
-	$(SQUID_CPPUNIT_LA)
 
 ## Tests of the HttpRequest module.
 tests_testHttpRequest_SOURCES = \
@@ -2629,10 +2553,6 @@
 	refresh.h \
 	refresh.cc \
 	RemovalPolicy.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	$(SNMP_SOURCE) \
 	SquidMath.h \
@@ -2715,6 +2635,7 @@
 	log/liblog.la \
 	format/libformat.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	$(REPL_OBJS) \
 	$(ADAPTATION_LIBS) \
 	$(ESI_LIBS) \
@@ -2730,9 +2651,6 @@
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 tests_testHttpRequest_LDFLAGS = $(LIBADD_DL)
-tests_testHttpRequest_DEPENDENCIES = \
-	$(REPL_OBJS) \
-	$(SQUID_CPPUNIT_LA)
 
 ## Tests for icmp/* objects
 # icmp/libicmpcore.la is used by pinger so SHOULD NOT require more dependancies! :-(
@@ -2840,10 +2758,6 @@
 	StoreSwapLogData.cc \
 	store_key_md5.h \
 	store_key_md5.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	String.cc \
 	StrList.h \
@@ -2930,6 +2844,7 @@
 	anyp/libanyp.la \
 	mem/libmem.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	DiskIO/libdiskio.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
@@ -2937,13 +2852,12 @@
 	$(NETTLELIB) \
 	$(REGEXLIB) \
 	$(SQUID_CPPUNIT_LIBS) \
+	$(SQUID_CPPUNIT_LA) \
 	$(SSLLIB) \
 	CommCalls.o \
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 tests_testStore_LDFLAGS = $(LIBADD_DL)
-tests_testStore_DEPENDENCIES = \
-	$(SQUID_CPPUNIT_LA)
 
 ## string needs mem.cc.
 ## mem.cc needs ClientInfo.h
@@ -2952,8 +2866,6 @@
 	ClientInfo.h \
 	MemBuf.cc \
 	String.cc \
-	$(SBUF_SOURCE) \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	tests/testString.cc \
 	tests/testString.h \
@@ -2975,15 +2887,15 @@
 	base/libbase.la \
 	libsquid.la \
 	ip/libip.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmiscutil.la \
 	$(REGEXLIB) \
 	$(SQUID_CPPUNIT_LIBS) \
+	$(SQUID_CPPUNIT_LA) \
 	$(SSLLIB) \
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 tests_testString_LDFLAGS = $(LIBADD_DL)
-tests_testString_DEPENDENCIES = \
-	$(SQUID_CPPUNIT_LA)
 
 SWAP_TEST_DS =\
 	repl_modules.o \
@@ -3081,10 +2993,6 @@
 	tests/stub_cache_cf.cc \
 	tests/stub_helper.cc \
 	cbdata.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	String.cc \
 	tests/stub_debug.cc \
@@ -3163,6 +3071,7 @@
 	ip/libip.la \
 	mem/libmem.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
 	$(top_builddir)/lib/libmiscutil.la \
@@ -3260,10 +3169,6 @@
 	store_key_md5.cc \
 	store_swapmeta.cc \
 	store_swapout.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	String.cc \
 	StrList.h \
@@ -3339,6 +3244,7 @@
 	base/libbase.la \
 	mem/libmem.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
 	$(top_builddir)/lib/libmiscutil.la \
@@ -3479,10 +3385,6 @@
 	refresh.h \
 	refresh.cc \
 	RemovalPolicy.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	$(SNMP_SOURCE) \
 	SquidMath.h \
@@ -3580,6 +3482,7 @@
 	log/liblog.la \
 	format/libformat.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	$(REGEXLIB) \
 	$(REPL_OBJS) \
 	$(ADAPTATION_LIBS) \
@@ -3596,101 +3499,49 @@
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 tests_testURL_LDFLAGS = $(LIBADD_DL)
-tests_testURL_DEPENDENCIES = \
-	$(REPL_OBJS) \
-	$(SQUID_CPPUNIT_LA)
 
 tests_testSBuf_SOURCES= \
 	tests/testSBuf.h \
 	tests/testSBuf.cc \
 	tests/SBufFindTest.h \
 	tests/SBufFindTest.cc \
-	$(SBUF_SOURCE) \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufStream.h \
 	tests/stub_time.cc \
 	tests/stub_debug.cc \
 	tests/stub_fatal.cc \
-	tests/stub_HelperChildConfig.cc \
-	tests/stub_libmem.cc \
-	tests/stub_cache_cf.cc \
-	tests/stub_cache_manager.cc \
-	tests/stub_cbdata.cc \
-	tests/stub_store.cc \
-	tests/stub_store_stats.cc \
-	tests/stub_tools.cc \
-	SquidString.h \
-	String.cc \
-	tests/stub_wordlist.cc \
-	tests/stub_MemBuf.cc
+	tests/stub_libmem.cc
 nodist_tests_testSBuf_SOURCES=$(TESTSOURCES)
 tests_testSBuf_LDFLAGS = $(LIBADD_DL)
-tests_testSBuf_LDADD=\
+tests_testSBuf_LDADD= \
+	sbuf/libsbuf.la \
 	base/libbase.la \
-	libsquid.la \
-	ip/libip.la \
-	mgr/libmgr.la \
-	$(top_builddir)/lib/libmiscutil.la \
-	$(REGEXLIB) \
 	$(SQUID_CPPUNIT_LIBS) \
 	$(COMPAT_LIB) \
-	$(XTRA_LIBS)
-tests_testSBuf_DEPENDENCIES= $(SQUID_CPPUNIT_LA)
+	$(XTRA_LIBS) \
+	$(SQUID_CPPUNIT_LA)
 
 tests_testSBufList_SOURCES= \
 	tests/testSBufList.h \
 	tests/testSBufList.cc \
-	$(SBUF_SOURCE) \
-	SBufList.h \
-	SBufList.cc \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
-	SBufStream.h \
 	tests/stub_time.cc \
-	tests/stub_MemObject.cc \
-	tests/stub_cbdata.cc \
-	tests/stub_comm.cc \
 	tests/stub_debug.cc \
-	tests/stub_event.cc \
 	tests/stub_fatal.cc \
-	tests/stub_fd.cc \
-	tests/stub_HelperChildConfig.cc \
-	tests/stub_libmem.cc \
-	tests/stub_cache_cf.cc \
-	tests/stub_cache_manager.cc \
-	tests/stub_store.cc \
-	tests/stub_stmem.cc \
-	tests/stub_store_stats.cc \
-	tests/stub_tools.cc \
-	SquidString.h \
-	StatCounters.cc \
-	String.cc \
-	tests/stub_wordlist.cc \
-	tests/stub_MemBuf.cc
+	tests/stub_libmem.cc
 nodist_tests_testSBufList_SOURCES=$(TESTSOURCES)
 tests_testSBufList_LDFLAGS = $(LIBADD_DL)
 tests_testSBufList_LDADD=\
+	sbuf/libsbuf.la \
 	base/libbase.la \
-	libsquid.la \
-	ip/libip.la \
-	mgr/libmgr.la \
-	$(top_builddir)/lib/libmiscutil.la \
 	$(SQUID_CPPUNIT_LIBS) \
 	$(COMPAT_LIB) \
-	$(XTRA_LIBS)
-tests_testSBufList_DEPENDENCIES= $(SQUID_CPPUNIT_LA)
+	$(XTRA_LIBS) \
+	$(SQUID_CPPUNIT_LA)
 
 tests_testConfigParser_SOURCES = \
 	ClientInfo.h \
 	tests/stub_MemBuf.cc \
 	tests/stub_time.cc \
-	$(SBUF_SOURCE) \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	String.cc \
 	ConfigParser.cc \
@@ -3700,7 +3551,6 @@
 	tests/testConfigParser.h \
 	cache_cf.h \
 	tests/stub_cache_cf.cc \
-	tests/stub_cache_manager.cc \
 	tests/stub_cbdata.cc \
 	tests/stub_debug.cc \
 	tests/stub_libmem.cc \
@@ -3712,26 +3562,24 @@
 nodist_tests_testConfigParser_SOURCES = \
 	$(TESTSOURCES)
 tests_testConfigParser_LDADD = \
-	base/libbase.la \
 	libsquid.la \
 	ip/libip.la \
+	sbuf/libsbuf.la \
+	base/libbase.la \
 	$(top_builddir)/lib/libmiscutil.la \
 	$(REGEXLIB) \
 	$(SQUID_CPPUNIT_LIBS) \
+	$(SQUID_CPPUNIT_LA) \
 	$(SSLLIB) \
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 tests_testConfigParser_LDFLAGS = $(LIBADD_DL)
-tests_testConfigParser_DEPENDENCIES = \
-	$(SQUID_CPPUNIT_LA)
 	
 tests_testStatHist_SOURCES = \
 	tests/stub_cbdata.cc \
 	fatal.h \
 	tests/stub_fatal.cc \
 	tests/stub_MemBuf.cc \
-	$(SBUF_SOURCE) \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	StatHist.cc \
 	StatHist.h \
@@ -3759,13 +3607,13 @@
 	$(TESTSOURCES)
 tests_testStatHist_LDFLAGS = $(LIBADD_DL)
 tests_testStatHist_LDADD = \
+	sbuf/libsbuf.la \
 	base/libbase.la \
 	$(top_builddir)/lib/libmiscutil.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(SQUID_CPPUNIT_LIBS) \
 	$(SQUID_CPPUNIT_LA) \
 	$(COMPAT_LIB)
-tests_testStatHist_DEPENDENCIES = $(SQUID_CPPUNIT_LA)
 
 tests_testLookupTable_SOURCES = \
 	tests/testLookupTable.h \
@@ -3773,19 +3621,16 @@
 	tests/stub_debug.cc \
 	tests/stub_libmem.cc \
 	tests/stub_SBufDetailedStats.cc \
-	base/LookupTable.h \
-	String.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc
+	base/LookupTable.h
 nodist_tests_testLookupTable_SOURCES = $(TESTSOURCES)
 tests_testLookupTable_LDFLAGS = $(LIBADD_DL)
 tests_testLookupTable_LDADD = \
+	sbuf/libsbuf.la \
 	base/libbase.la \
 	$(SQUID_CPPUNIT_LIBS) \
 	$(COMPAT_LIB) \
-	$(XTRA_LIBS)
-tests_testLookupTable_DEPENDENCIES = $(SQUID_CPPUNIT_LA)
+	$(XTRA_LIBS) \
+	$(SQUID_CPPUNIT_LA)
 
 tests_testEnumIterator_SOURCES = \
 	base/EnumIterator.h \
@@ -3802,7 +3647,6 @@
 	$(COMPAT_LIB) \
 	$(SQUID_CPPUNIT_LA) \
 	$(XTRA_LIBS)
-tests_testEnumIterator_DEPENDENCIES =
 
 tests_testYesNoNone_SOURCES = \
 	tests/testYesNoNone.cc \
diff -u -r -N squid-4.0.7/src/Makefile.in squid-4.0.8/src/Makefile.in
--- squid-4.0.7/src/Makefile.in	2016-02-24 06:49:09.000000000 +1300
+++ squid-4.0.8/src/Makefile.in	2016-04-02 10:06:35.000000000 +1300
@@ -287,13 +287,10 @@
 	PeerPoolMgr.h PeerPoolMgr.cc PeerSelectState.h PingData.h \
 	Pipeline.cc Pipeline.h protos.h redirect.h redirect.cc \
 	refresh.h refresh.cc RemovalPolicy.cc RemovalPolicy.h \
-	send-announce.h send-announce.cc base/CharacterSet.h \
-	base/InstanceId.h MemBlob.h MemBlob.cc OutOfBoundsException.h \
-	SBuf.h SBuf.cc SBufExceptions.h SBufExceptions.cc SBufAlgos.h \
-	SBufAlgos.cc SBufDetailedStats.h SBufDetailedStats.cc \
-	SBufStatsAction.h SBufStatsAction.cc SnmpRequest.h snmp_core.h \
-	snmp_core.cc snmp_agent.h snmp_agent.cc SquidMath.h \
-	SquidMath.cc SquidNew.cc IoStats.h stat.h stat.cc \
+	send-announce.h send-announce.cc SBufStatsAction.h \
+	SBufStatsAction.cc sbuf/StringConvert.h SnmpRequest.h \
+	snmp_core.h snmp_core.cc snmp_agent.h snmp_agent.cc \
+	SquidMath.h SquidMath.cc SquidNew.cc IoStats.h stat.h stat.cc \
 	StatCounters.h StatCounters.cc StatHist.h StatHist.cc \
 	String.cc StrList.h StrList.cc stmem.cc stmem.h repl_modules.h \
 	store.cc Store.h StoreFileSystem.cc StoreFileSystem.h \
@@ -327,18 +324,16 @@
 @ENABLE_WIN32_IPC_TRUE@am__objects_6 = ipc_win32.$(OBJEXT)
 @MAKE_LEAKFINDER_TRUE@am__objects_7 = LeakFinder.$(OBJEXT)
 @ENABLE_XPROF_STATS_TRUE@am__objects_8 = ProfStats.$(OBJEXT)
-am__objects_9 = MemBlob.$(OBJEXT) SBuf.$(OBJEXT) \
-	SBufExceptions.$(OBJEXT)
-am__objects_10 = snmp_core.$(OBJEXT) snmp_agent.$(OBJEXT)
-@ENABLE_SNMP_TRUE@am__objects_11 = $(am__objects_10)
-am__objects_12 = StoreMeta.$(OBJEXT) StoreMetaMD5.$(OBJEXT) \
+am__objects_9 = snmp_core.$(OBJEXT) snmp_agent.$(OBJEXT)
+@ENABLE_SNMP_TRUE@am__objects_10 = $(am__objects_9)
+am__objects_11 = StoreMeta.$(OBJEXT) StoreMetaMD5.$(OBJEXT) \
 	StoreMetaSTD.$(OBJEXT) StoreMetaSTDLFS.$(OBJEXT) \
 	StoreMetaURL.$(OBJEXT) StoreMetaVary.$(OBJEXT)
-@ENABLE_UNLINKD_TRUE@am__objects_13 = unlinkd.$(OBJEXT)
-@ENABLE_WIN32SPECIFIC_TRUE@am__objects_14 = win32.$(OBJEXT)
-@ENABLE_WIN32SPECIFIC_TRUE@am__objects_15 = WinSvc.$(OBJEXT)
-am__objects_16 = LoadableModule.$(OBJEXT) LoadableModules.$(OBJEXT)
-@ENABLE_LOADABLE_MODULES_TRUE@am__objects_17 = $(am__objects_16)
+@ENABLE_UNLINKD_TRUE@am__objects_12 = unlinkd.$(OBJEXT)
+@ENABLE_WIN32SPECIFIC_TRUE@am__objects_13 = win32.$(OBJEXT)
+@ENABLE_WIN32SPECIFIC_TRUE@am__objects_14 = WinSvc.$(OBJEXT)
+am__objects_15 = LoadableModule.$(OBJEXT) LoadableModules.$(OBJEXT)
+@ENABLE_LOADABLE_MODULES_TRUE@am__objects_16 = $(am__objects_15)
 am_squid_OBJECTS = $(am__objects_1) AccessLogEntry.$(OBJEXT) \
 	AsyncEngine.$(OBJEXT) cache_cf.$(OBJEXT) CacheDigest.$(OBJEXT) \
 	cache_manager.$(OBJEXT) CachePeer.$(OBJEXT) carp.$(OBJEXT) \
@@ -373,9 +368,8 @@
 	peer_sourcehash.$(OBJEXT) peer_userhash.$(OBJEXT) \
 	PeerPoolMgr.$(OBJEXT) Pipeline.$(OBJEXT) redirect.$(OBJEXT) \
 	refresh.$(OBJEXT) RemovalPolicy.$(OBJEXT) \
-	send-announce.$(OBJEXT) $(am__objects_9) SBufAlgos.$(OBJEXT) \
-	SBufDetailedStats.$(OBJEXT) SBufStatsAction.$(OBJEXT) \
-	$(am__objects_11) SquidMath.$(OBJEXT) SquidNew.$(OBJEXT) \
+	send-announce.$(OBJEXT) SBufStatsAction.$(OBJEXT) \
+	$(am__objects_10) SquidMath.$(OBJEXT) SquidNew.$(OBJEXT) \
 	stat.$(OBJEXT) StatCounters.$(OBJEXT) StatHist.$(OBJEXT) \
 	String.$(OBJEXT) StrList.$(OBJEXT) stmem.$(OBJEXT) \
 	store.$(OBJEXT) StoreFileSystem.$(OBJEXT) store_io.$(OBJEXT) \
@@ -384,13 +378,13 @@
 	store_log.$(OBJEXT) store_rebuild.$(OBJEXT) \
 	store_swapin.$(OBJEXT) store_swapmeta.$(OBJEXT) \
 	store_swapout.$(OBJEXT) StoreMetaUnpacker.$(OBJEXT) \
-	$(am__objects_12) StoreStats.$(OBJEXT) \
+	$(am__objects_11) StoreStats.$(OBJEXT) \
 	StoreSwapLogData.$(OBJEXT) Transients.$(OBJEXT) \
 	MemStore.$(OBJEXT) time.$(OBJEXT) tools.$(OBJEXT) \
-	tunnel.$(OBJEXT) $(am__objects_13) url.$(OBJEXT) urn.$(OBJEXT) \
+	tunnel.$(OBJEXT) $(am__objects_12) url.$(OBJEXT) urn.$(OBJEXT) \
 	wccp.$(OBJEXT) wccp2.$(OBJEXT) whois.$(OBJEXT) \
-	wordlist.$(OBJEXT) $(am__objects_14) $(am__objects_15) \
-	$(am__objects_17)
+	wordlist.$(OBJEXT) $(am__objects_13) $(am__objects_14) \
+	$(am__objects_16)
 am__EXTRA_squid_SOURCES_DIST = ConfigOption.h CommonPool.h \
 	CompositePoolNode.h delay_pools.cc DelayId.cc DelayId.h \
 	DelayIdComposite.h DelayBucket.cc DelayBucket.h DelayConfig.cc \
@@ -404,11 +398,11 @@
 	unlinkd.cc win32.h win32.cc WinSvc.h WinSvc.cc \
 	LoadableModule.h LoadableModule.cc LoadableModules.h \
 	LoadableModules.cc
-am__objects_18 = err_type.$(OBJEXT) err_detail_type.$(OBJEXT) \
+am__objects_17 = err_type.$(OBJEXT) err_detail_type.$(OBJEXT) \
 	globals.$(OBJEXT) hier_code.$(OBJEXT) icp_opcode.$(OBJEXT) \
 	lookup_t.$(OBJEXT) repl_modules.$(OBJEXT) \
 	swap_log_op.$(OBJEXT)
-nodist_squid_OBJECTS = $(am__objects_18)
+nodist_squid_OBJECTS = $(am__objects_17)
 squid_OBJECTS = $(am_squid_OBJECTS) $(nodist_squid_OBJECTS)
 @USE_ESI_TRUE@am__DEPENDENCIES_4 = esi/libesi.la \
 @USE_ESI_TRUE@	$(top_builddir)/lib/libTrie/libTrie.a \
@@ -425,12 +419,12 @@
 	fs/libfs.la DiskIO/libdiskio.la $(SSL_LIBS) ipc/libipc.la \
 	mgr/libmgr.la anyp/libanyp.la comm/libcomm.la \
 	security/libsecurity.la eui/libeui.la icmp/libicmp.la \
-	log/liblog.la format/libformat.la $(am__DEPENDENCIES_1) \
+	log/liblog.la format/libformat.la sbuf/libsbuf.la \
 	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
 	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
-	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_4) \
-	$(am__DEPENDENCIES_5) mem/libmem.la store/libstore.la \
-	$(top_builddir)/lib/libmisccontainers.la \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_4) $(am__DEPENDENCIES_5) mem/libmem.la \
+	store/libstore.la $(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
 	$(top_builddir)/lib/libmiscutil.la $(am__DEPENDENCIES_1) \
 	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
@@ -461,17 +455,16 @@
 	mem_node.$(OBJEXT) Parsing.$(OBJEXT) \
 	tests/stub_libsecurity.$(OBJEXT) SquidMath.$(OBJEXT) \
 	StatCounters.$(OBJEXT) StrList.$(OBJEXT) \
-	tests/stub_StatHist.$(OBJEXT) stmem.$(OBJEXT) $(am__objects_9) \
-	SBufAlgos.$(OBJEXT) tests/stub_SBufDetailedStats.$(OBJEXT) \
-	String.$(OBJEXT) StoreIOState.$(OBJEXT) \
-	tests/stub_StoreMeta.$(OBJEXT) StoreMetaUnpacker.$(OBJEXT) \
-	StoreSwapLogData.$(OBJEXT) store_key_md5.$(OBJEXT) \
-	swap_log_op.$(OBJEXT) tests/stub_SwapDir.$(OBJEXT) \
-	Transients.$(OBJEXT) tests/stub_access_log.$(OBJEXT) \
-	tests/stub_cache_cf.$(OBJEXT) tests/stub_client_side.$(OBJEXT) \
-	tests/stub_debug.$(OBJEXT) tests/stub_DelayId.$(OBJEXT) \
-	tests/stub_errorpage.$(OBJEXT) tests/stub_fd.$(OBJEXT) \
-	tests/stub_HttpRequest.$(OBJEXT) \
+	tests/stub_StatHist.$(OBJEXT) stmem.$(OBJEXT) \
+	tests/stub_SBufDetailedStats.$(OBJEXT) String.$(OBJEXT) \
+	StoreIOState.$(OBJEXT) tests/stub_StoreMeta.$(OBJEXT) \
+	StoreMetaUnpacker.$(OBJEXT) StoreSwapLogData.$(OBJEXT) \
+	store_key_md5.$(OBJEXT) swap_log_op.$(OBJEXT) \
+	tests/stub_SwapDir.$(OBJEXT) Transients.$(OBJEXT) \
+	tests/stub_access_log.$(OBJEXT) tests/stub_cache_cf.$(OBJEXT) \
+	tests/stub_client_side.$(OBJEXT) tests/stub_debug.$(OBJEXT) \
+	tests/stub_DelayId.$(OBJEXT) tests/stub_errorpage.$(OBJEXT) \
+	tests/stub_fd.$(OBJEXT) tests/stub_HttpRequest.$(OBJEXT) \
 	tests/stub_HttpReply.$(OBJEXT) \
 	tests/stub_ipc_TypedMsgHdr.$(OBJEXT) \
 	tests/stub_libauth.$(OBJEXT) tests/stub_libcomm.$(OBJEXT) \
@@ -487,15 +480,15 @@
 	tests/stub_cache_manager.$(OBJEXT) tests/stub_UdsOp.$(OBJEXT) \
 	tests/testACLMaxUserIP.$(OBJEXT) tests/stub_time.$(OBJEXT) \
 	url.$(OBJEXT) MemBuf.$(OBJEXT) wordlist.$(OBJEXT)
-am__objects_19 = test_tools.$(OBJEXT) globals.$(OBJEXT)
-nodist_tests_testACLMaxUserIP_OBJECTS = $(am__objects_19)
+am__objects_18 = test_tools.$(OBJEXT) globals.$(OBJEXT)
+nodist_tests_testACLMaxUserIP_OBJECTS = $(am__objects_18)
 tests_testACLMaxUserIP_OBJECTS = $(am_tests_testACLMaxUserIP_OBJECTS) \
 	$(nodist_tests_testACLMaxUserIP_OBJECTS)
 tests_testACLMaxUserIP_DEPENDENCIES = libsquid.la helper/libhelper.la \
 	http/libhttp.la parser/libparser.la $(AUTH_ACL_LIBS) \
 	ident/libident.la acl/libacls.la eui/libeui.la acl/libstate.la \
 	acl/libapi.la anyp/libanyp.la base/libbase.la ip/libip.la \
-	ipc/libipc.la mgr/libmgr.la \
+	ipc/libipc.la mgr/libmgr.la sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
 	$(top_builddir)/lib/libmiscutil.la $(am__DEPENDENCIES_1) \
@@ -510,9 +503,12 @@
 	tests/stub_debug.$(OBJEXT) tests/stub_libmem.$(OBJEXT) \
 	tests/stub_time.$(OBJEXT)
 nodist_tests_testBoilerplate_OBJECTS = tests/stub_cbdata.$(OBJEXT) \
-	tests/stub_MemBuf.$(OBJEXT) $(am__objects_19)
+	tests/stub_MemBuf.$(OBJEXT) $(am__objects_18)
 tests_testBoilerplate_OBJECTS = $(am_tests_testBoilerplate_OBJECTS) \
 	$(nodist_tests_testBoilerplate_OBJECTS)
+tests_testBoilerplate_DEPENDENCIES = $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) base/libbase.la \
+	$(am__DEPENDENCIES_3) $(am__DEPENDENCIES_1)
 tests_testBoilerplate_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testBoilerplate_LDFLAGS) \
@@ -559,10 +555,7 @@
 	peer_select.cc peer_sourcehash.h peer_sourcehash.cc \
 	peer_userhash.h peer_userhash.cc PeerPoolMgr.h PeerPoolMgr.cc \
 	Pipeline.cc Pipeline.h redirect.h tests/stub_redirect.cc \
-	refresh.h refresh.cc RemovalPolicy.cc base/CharacterSet.h \
-	base/InstanceId.h MemBlob.h MemBlob.cc OutOfBoundsException.h \
-	SBuf.h SBuf.cc SBufExceptions.h SBufExceptions.cc SBufAlgos.h \
-	SBufAlgos.cc SBufDetailedStats.h \
+	refresh.h refresh.cc RemovalPolicy.cc \
 	tests/stub_SBufDetailedStats.cc SnmpRequest.h snmp_core.h \
 	snmp_core.cc snmp_agent.h snmp_agent.cc SquidMath.h \
 	SquidMath.cc IoStats.h stat.h stat.cc StatCounters.h \
@@ -619,14 +612,14 @@
 	peer_sourcehash.$(OBJEXT) peer_userhash.$(OBJEXT) \
 	PeerPoolMgr.$(OBJEXT) Pipeline.$(OBJEXT) \
 	tests/stub_redirect.$(OBJEXT) refresh.$(OBJEXT) \
-	RemovalPolicy.$(OBJEXT) $(am__objects_9) SBufAlgos.$(OBJEXT) \
-	tests/stub_SBufDetailedStats.$(OBJEXT) $(am__objects_11) \
-	SquidMath.$(OBJEXT) stat.$(OBJEXT) StatCounters.$(OBJEXT) \
-	StrList.$(OBJEXT) tests/stub_libauth_acls.$(OBJEXT) \
-	tests/stub_libauth.$(OBJEXT) tests/stub_libdiskio.$(OBJEXT) \
-	tests/stub_StatHist.$(OBJEXT) stmem.$(OBJEXT) store.$(OBJEXT) \
-	store_client.$(OBJEXT) tests/stub_store_digest.$(OBJEXT) \
-	store_io.$(OBJEXT) store_key_md5.$(OBJEXT) store_log.$(OBJEXT) \
+	RemovalPolicy.$(OBJEXT) tests/stub_SBufDetailedStats.$(OBJEXT) \
+	$(am__objects_10) SquidMath.$(OBJEXT) stat.$(OBJEXT) \
+	StatCounters.$(OBJEXT) StrList.$(OBJEXT) \
+	tests/stub_libauth_acls.$(OBJEXT) tests/stub_libauth.$(OBJEXT) \
+	tests/stub_libdiskio.$(OBJEXT) tests/stub_StatHist.$(OBJEXT) \
+	stmem.$(OBJEXT) store.$(OBJEXT) store_client.$(OBJEXT) \
+	tests/stub_store_digest.$(OBJEXT) store_io.$(OBJEXT) \
+	store_key_md5.$(OBJEXT) store_log.$(OBJEXT) \
 	store_rebuild.$(OBJEXT) store_swapin.$(OBJEXT) \
 	store_swapmeta.$(OBJEXT) store_swapout.$(OBJEXT) \
 	StoreFileSystem.$(OBJEXT) StoreIOState.$(OBJEXT) \
@@ -634,18 +627,35 @@
 	StoreSwapLogData.$(OBJEXT) tools.$(OBJEXT) \
 	Transients.$(OBJEXT) tests/stub_tunnel.$(OBJEXT) \
 	tests/stub_SwapDir.$(OBJEXT) MemStore.$(OBJEXT) \
-	$(am__objects_13) url.$(OBJEXT) urn.$(OBJEXT) \
+	$(am__objects_12) url.$(OBJEXT) urn.$(OBJEXT) \
 	tests/stub_wccp2.$(OBJEXT) tests/stub_whois.$(OBJEXT) \
-	FadingCounter.$(OBJEXT) $(am__objects_14) wordlist.$(OBJEXT)
-nodist_tests_testCacheManager_OBJECTS = $(am__objects_18)
+	FadingCounter.$(OBJEXT) $(am__objects_13) wordlist.$(OBJEXT)
+nodist_tests_testCacheManager_OBJECTS = $(am__objects_17)
 tests_testCacheManager_OBJECTS = $(am_tests_testCacheManager_OBJECTS) \
 	$(nodist_tests_testCacheManager_OBJECTS)
+tests_testCacheManager_DEPENDENCIES = libsquid.la \
+	clients/libclients.la servers/libservers.la ftp/libftp.la \
+	helper/libhelper.la http/libhttp.la parser/libparser.la \
+	ident/libident.la acl/libacls.la acl/libstate.la acl/libapi.la \
+	dns/libdns.la base/libbase.la ip/libip.la fs/libfs.la \
+	comm/libcomm.la eui/libeui.la icmp/libicmp.la log/liblog.la \
+	format/libformat.la $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_4) $(SSL_LIBS) \
+	anyp/libanyp.la ipc/libipc.la mgr/libmgr.la \
+	$(am__DEPENDENCIES_5) mem/libmem.la store/libstore.la \
+	sbuf/libsbuf.la $(top_builddir)/lib/libmisccontainers.la \
+	$(top_builddir)/lib/libmiscencoding.la \
+	$(top_builddir)/lib/libmiscutil.la $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_3) \
+	$(am__DEPENDENCIES_1)
 tests_testCacheManager_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testCacheManager_LDFLAGS) \
 	$(LDFLAGS) -o $@
 am_tests_testCharacterSet_OBJECTS = tests/testCharacterSet.$(OBJEXT)
-nodist_tests_testCharacterSet_OBJECTS = $(am__objects_19) \
+nodist_tests_testCharacterSet_OBJECTS = $(am__objects_18) \
 	tests/stub_cbdata.$(OBJEXT) tests/stub_debug.$(OBJEXT) \
 	tests/stub_libmem.$(OBJEXT) tests/stub_MemBuf.$(OBJEXT)
 tests_testCharacterSet_OBJECTS = $(am_tests_testCharacterSet_OBJECTS) \
@@ -658,17 +668,23 @@
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testCharacterSet_LDFLAGS) \
 	$(LDFLAGS) -o $@
 am_tests_testConfigParser_OBJECTS = tests/stub_MemBuf.$(OBJEXT) \
-	tests/stub_time.$(OBJEXT) $(am__objects_9) \
+	tests/stub_time.$(OBJEXT) \
 	tests/stub_SBufDetailedStats.$(OBJEXT) String.$(OBJEXT) \
 	ConfigParser.$(OBJEXT) tests/stub_fatal.$(OBJEXT) \
 	tests/testConfigParser.$(OBJEXT) tests/stub_cache_cf.$(OBJEXT) \
-	tests/stub_cache_manager.$(OBJEXT) tests/stub_cbdata.$(OBJEXT) \
-	tests/stub_debug.$(OBJEXT) tests/stub_libmem.$(OBJEXT) \
+	tests/stub_cbdata.$(OBJEXT) tests/stub_debug.$(OBJEXT) \
+	tests/stub_libmem.$(OBJEXT) \
 	tests/stub_HelperChildConfig.$(OBJEXT) \
 	tests/stub_tools.$(OBJEXT) wordlist.$(OBJEXT)
-nodist_tests_testConfigParser_OBJECTS = $(am__objects_19)
+nodist_tests_testConfigParser_OBJECTS = $(am__objects_18)
 tests_testConfigParser_OBJECTS = $(am_tests_testConfigParser_OBJECTS) \
 	$(nodist_tests_testConfigParser_OBJECTS)
+tests_testConfigParser_DEPENDENCIES = libsquid.la ip/libip.la \
+	sbuf/libsbuf.la base/libbase.la \
+	$(top_builddir)/lib/libmiscutil.la $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_3) \
+	$(am__DEPENDENCIES_1)
 tests_testConfigParser_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testConfigParser_LDFLAGS) \
@@ -695,10 +711,7 @@
 	Notes.cc Parsing.cc refresh.h refresh.cc RemovalPolicy.cc \
 	RequestFlags.h RequestFlags.cc tests/stub_libsecurity.cc \
 	StatCounters.h StatCounters.cc StatHist.h \
-	tests/stub_StatHist.cc stmem.cc base/CharacterSet.h \
-	base/InstanceId.h MemBlob.h MemBlob.cc OutOfBoundsException.h \
-	SBuf.h SBuf.cc SBufExceptions.h SBufExceptions.cc SBufAlgos.h \
-	SBufAlgos.cc SBufDetailedStats.h \
+	tests/stub_StatHist.cc stmem.cc \
 	tests/stub_SBufDetailedStats.cc StoreFileSystem.cc \
 	StoreIOState.cc tests/stub_StoreMeta.cc StoreMetaUnpacker.cc \
 	StoreSwapLogData.cc store_io.cc store_key_md5.h \
@@ -739,8 +752,8 @@
 	Notes.$(OBJEXT) Parsing.$(OBJEXT) refresh.$(OBJEXT) \
 	RemovalPolicy.$(OBJEXT) RequestFlags.$(OBJEXT) \
 	tests/stub_libsecurity.$(OBJEXT) StatCounters.$(OBJEXT) \
-	tests/stub_StatHist.$(OBJEXT) stmem.$(OBJEXT) $(am__objects_9) \
-	SBufAlgos.$(OBJEXT) tests/stub_SBufDetailedStats.$(OBJEXT) \
+	tests/stub_StatHist.$(OBJEXT) stmem.$(OBJEXT) \
+	tests/stub_SBufDetailedStats.$(OBJEXT) \
 	StoreFileSystem.$(OBJEXT) StoreIOState.$(OBJEXT) \
 	tests/stub_StoreMeta.$(OBJEXT) StoreMetaUnpacker.$(OBJEXT) \
 	StoreSwapLogData.$(OBJEXT) store_io.$(OBJEXT) \
@@ -767,10 +780,10 @@
 	tests/stub_store_stats.$(OBJEXT) \
 	tests/stub_store_rebuild.$(OBJEXT) tests/stub_UdsOp.$(OBJEXT) \
 	tests/testDiskIO.$(OBJEXT) tests/testStoreSupport.$(OBJEXT) \
-	tests/stub_time.$(OBJEXT) $(am__objects_13) url.$(OBJEXT) \
-	$(am__objects_14) wordlist.$(OBJEXT) \
+	tests/stub_time.$(OBJEXT) $(am__objects_12) url.$(OBJEXT) \
+	$(am__objects_13) wordlist.$(OBJEXT) \
 	tests/stub_tools.$(OBJEXT)
-nodist_tests_testDiskIO_OBJECTS = $(am__objects_19) \
+nodist_tests_testDiskIO_OBJECTS = $(am__objects_18) \
 	SquidMath.$(OBJEXT) swap_log_op.$(OBJEXT)
 tests_testDiskIO_OBJECTS = $(am_tests_testDiskIO_OBJECTS) \
 	$(nodist_tests_testDiskIO_OBJECTS)
@@ -794,9 +807,12 @@
 	-o $@
 am_tests_testEnumIterator_OBJECTS = tests/stub_debug.$(OBJEXT) \
 	tests/stub_libmem.$(OBJEXT) tests/testEnumIterator.$(OBJEXT)
-nodist_tests_testEnumIterator_OBJECTS = $(am__objects_19)
+nodist_tests_testEnumIterator_OBJECTS = $(am__objects_18)
 tests_testEnumIterator_OBJECTS = $(am_tests_testEnumIterator_OBJECTS) \
 	$(nodist_tests_testEnumIterator_OBJECTS)
+tests_testEnumIterator_DEPENDENCIES = base/libbase.la \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_3) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 tests_testEnumIterator_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testEnumIterator_LDFLAGS) \
@@ -841,9 +857,6 @@
 	peer_sourcehash.cc peer_userhash.h peer_userhash.cc \
 	Pipeline.cc Pipeline.h redirect.h tests/stub_redirect.cc \
 	refresh.h refresh.cc RemovalPolicy.cc StrList.h StrList.cc \
-	base/CharacterSet.h base/InstanceId.h MemBlob.h MemBlob.cc \
-	OutOfBoundsException.h SBuf.h SBuf.cc SBufExceptions.h \
-	SBufExceptions.cc SBufAlgos.h SBufAlgos.cc SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc SnmpRequest.h snmp_core.h \
 	snmp_core.cc snmp_agent.h snmp_agent.cc SquidMath.cc \
 	SquidMath.h IoStats.h stat.h stat.cc StatCounters.h \
@@ -900,8 +913,7 @@
 	peer_sourcehash.$(OBJEXT) peer_userhash.$(OBJEXT) \
 	Pipeline.$(OBJEXT) tests/stub_redirect.$(OBJEXT) \
 	refresh.$(OBJEXT) RemovalPolicy.$(OBJEXT) StrList.$(OBJEXT) \
-	$(am__objects_9) SBufAlgos.$(OBJEXT) \
-	tests/stub_SBufDetailedStats.$(OBJEXT) $(am__objects_11) \
+	tests/stub_SBufDetailedStats.$(OBJEXT) $(am__objects_10) \
 	SquidMath.$(OBJEXT) stat.$(OBJEXT) StatCounters.$(OBJEXT) \
 	StatHist.$(OBJEXT) stmem.$(OBJEXT) store.$(OBJEXT) \
 	store_client.$(OBJEXT) tests/stub_store_digest.$(OBJEXT) \
@@ -919,12 +931,28 @@
 	tests/stub_store_stats.$(OBJEXT) time.$(OBJEXT) \
 	tools.$(OBJEXT) Transients.$(OBJEXT) \
 	tests/stub_tunnel.$(OBJEXT) MemStore.$(OBJEXT) \
-	$(am__objects_13) url.$(OBJEXT) urn.$(OBJEXT) \
+	$(am__objects_12) url.$(OBJEXT) urn.$(OBJEXT) \
 	tests/stub_wccp2.$(OBJEXT) tests/stub_whois.$(OBJEXT) \
-	$(am__objects_14) wordlist.$(OBJEXT)
-nodist_tests_testEvent_OBJECTS = $(am__objects_18)
+	$(am__objects_13) wordlist.$(OBJEXT)
+nodist_tests_testEvent_OBJECTS = $(am__objects_17)
 tests_testEvent_OBJECTS = $(am_tests_testEvent_OBJECTS) \
 	$(nodist_tests_testEvent_OBJECTS)
+tests_testEvent_DEPENDENCIES = libsquid.la clients/libclients.la \
+	servers/libservers.la ftp/libftp.la helper/libhelper.la \
+	http/libhttp.la parser/libparser.la ident/libident.la \
+	acl/libacls.la acl/libstate.la acl/libapi.la dns/libdns.la \
+	base/libbase.la ip/libip.la fs/libfs.la anyp/libanyp.la \
+	icmp/libicmp.la comm/libcomm.la log/liblog.la \
+	format/libformat.la $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_4) $(SSL_LIBS) \
+	$(top_builddir)/lib/libmisccontainers.la \
+	$(top_builddir)/lib/libmiscencoding.la \
+	$(top_builddir)/lib/libmiscutil.la ipc/libipc.la mgr/libmgr.la \
+	store/libstore.la sbuf/libsbuf.la $(am__DEPENDENCIES_5) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_3) $(am__DEPENDENCIES_1)
 tests_testEvent_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testEvent_LDFLAGS) \
@@ -968,9 +996,6 @@
 	peer_sourcehash.cc peer_userhash.h peer_userhash.cc \
 	Pipeline.cc Pipeline.h RemovalPolicy.cc redirect.h \
 	tests/stub_redirect.cc refresh.h refresh.cc \
-	base/CharacterSet.h base/InstanceId.h MemBlob.h MemBlob.cc \
-	OutOfBoundsException.h SBuf.h SBuf.cc SBufExceptions.h \
-	SBufExceptions.cc SBufAlgos.h SBufAlgos.cc SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc SnmpRequest.h snmp_core.h \
 	snmp_core.cc snmp_agent.h snmp_agent.cc SquidMath.h \
 	SquidMath.cc IoStats.h stat.h stat.cc StatCounters.h \
@@ -1026,8 +1051,7 @@
 	peer_sourcehash.$(OBJEXT) peer_userhash.$(OBJEXT) \
 	Pipeline.$(OBJEXT) RemovalPolicy.$(OBJEXT) \
 	tests/stub_redirect.$(OBJEXT) refresh.$(OBJEXT) \
-	$(am__objects_9) SBufAlgos.$(OBJEXT) \
-	tests/stub_SBufDetailedStats.$(OBJEXT) $(am__objects_11) \
+	tests/stub_SBufDetailedStats.$(OBJEXT) $(am__objects_10) \
 	SquidMath.$(OBJEXT) stat.$(OBJEXT) StatCounters.$(OBJEXT) \
 	StatHist.$(OBJEXT) stmem.$(OBJEXT) store.$(OBJEXT) \
 	store_client.$(OBJEXT) tests/stub_store_digest.$(OBJEXT) \
@@ -1046,20 +1070,35 @@
 	tests/stub_store_stats.$(OBJEXT) time.$(OBJEXT) \
 	tools.$(OBJEXT) Transients.$(OBJEXT) \
 	tests/stub_tunnel.$(OBJEXT) MemStore.$(OBJEXT) \
-	$(am__objects_13) url.$(OBJEXT) urn.$(OBJEXT) \
+	$(am__objects_12) url.$(OBJEXT) urn.$(OBJEXT) \
 	tests/stub_wccp2.$(OBJEXT) tests/stub_whois.$(OBJEXT) \
-	$(am__objects_14) wordlist.$(OBJEXT)
-nodist_tests_testEventLoop_OBJECTS = $(am__objects_18)
+	$(am__objects_13) wordlist.$(OBJEXT)
+nodist_tests_testEventLoop_OBJECTS = $(am__objects_17)
 tests_testEventLoop_OBJECTS = $(am_tests_testEventLoop_OBJECTS) \
 	$(nodist_tests_testEventLoop_OBJECTS)
+tests_testEventLoop_DEPENDENCIES = libsquid.la clients/libclients.la \
+	servers/libservers.la ftp/libftp.la helper/libhelper.la \
+	http/libhttp.la parser/libparser.la ident/libident.la \
+	acl/libacls.la acl/libstate.la acl/libapi.la dns/libdns.la \
+	base/libbase.la ip/libip.la fs/libfs.la anyp/libanyp.la \
+	icmp/libicmp.la comm/libcomm.la log/liblog.la \
+	format/libformat.la $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_4) $(SSL_LIBS) \
+	$(top_builddir)/lib/libmisccontainers.la \
+	$(top_builddir)/lib/libmiscencoding.la \
+	$(top_builddir)/lib/libmiscutil.la ipc/libipc.la mgr/libmgr.la \
+	sbuf/libsbuf.la store/libstore.la $(am__DEPENDENCIES_5) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_3) $(am__DEPENDENCIES_1)
 tests_testEventLoop_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testEventLoop_LDFLAGS) \
 	$(LDFLAGS) -o $@
 am_tests_testHttp1Parser_OBJECTS = MemBuf.$(OBJEXT) \
 	tests/stub_MemObject.$(OBJEXT) mime_header.$(OBJEXT) \
-	String.$(OBJEXT) $(am__objects_9) SBufAlgos.$(OBJEXT) \
-	tests/stub_SBufDetailedStats.$(OBJEXT) \
+	String.$(OBJEXT) tests/stub_SBufDetailedStats.$(OBJEXT) \
 	tests/stub_cache_cf.$(OBJEXT) \
 	tests/stub_cache_manager.$(OBJEXT) tests/stub_comm.$(OBJEXT) \
 	tests/stub_cbdata.$(OBJEXT) tests/stub_debug.$(OBJEXT) \
@@ -1070,9 +1109,15 @@
 	tests/stub_store_stats.$(OBJEXT) tests/stub_tools.$(OBJEXT) \
 	tests/testHttp1Parser.$(OBJEXT) tests/stub_time.$(OBJEXT) \
 	wordlist.$(OBJEXT)
-nodist_tests_testHttp1Parser_OBJECTS = $(am__objects_19)
+nodist_tests_testHttp1Parser_OBJECTS = $(am__objects_18)
 tests_testHttp1Parser_OBJECTS = $(am_tests_testHttp1Parser_OBJECTS) \
 	$(nodist_tests_testHttp1Parser_OBJECTS)
+tests_testHttp1Parser_DEPENDENCIES = http/libhttp.la \
+	parser/libparser.la anyp/libanyp.la SquidConfig.o \
+	base/libbase.la ip/libip.la sbuf/libsbuf.la \
+	$(top_builddir)/lib/libmiscutil.la $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_3) $(am__DEPENDENCIES_1)
 tests_testHttp1Parser_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testHttp1Parser_LDFLAGS) \
@@ -1086,7 +1131,6 @@
 	HttpHeaderTools.$(OBJEXT) HttpControlMsg.$(OBJEXT) \
 	HttpMsg.$(OBJEXT) HttpReply.$(OBJEXT) MasterXaction.$(OBJEXT) \
 	MemBuf.$(OBJEXT) mime_header.$(OBJEXT) Notes.$(OBJEXT) \
-	$(am__objects_9) SBufAlgos.$(OBJEXT) \
 	tests/stub_SBufDetailedStats.$(OBJEXT) String.$(OBJEXT) \
 	StrList.$(OBJEXT) tests/stub_access_log.$(OBJEXT) \
 	tests/stub_cache_cf.$(OBJEXT) \
@@ -1102,9 +1146,19 @@
 	tests/stub_store_stats.$(OBJEXT) tests/stub_tools.$(OBJEXT) \
 	tests/stub_HttpRequest.$(OBJEXT) tests/testHttpReply.$(OBJEXT) \
 	tests/stub_time.$(OBJEXT) url.$(OBJEXT) wordlist.$(OBJEXT)
-nodist_tests_testHttpReply_OBJECTS = $(am__objects_19)
+nodist_tests_testHttpReply_OBJECTS = $(am__objects_18)
 tests_testHttpReply_OBJECTS = $(am_tests_testHttpReply_OBJECTS) \
 	$(nodist_tests_testHttpReply_OBJECTS)
+tests_testHttpReply_DEPENDENCIES = CommCalls.o http/libhttp.la \
+	parser/libparser.la acl/libacls.la acl/libapi.la \
+	acl/libstate.la anyp/libanyp.la ip/libip.la base/libbase.la \
+	ipc/libipc.la mem/libmem.la sbuf/libsbuf.la \
+	$(top_builddir)/lib/libmisccontainers.la \
+	$(top_builddir)/lib/libmiscencoding.la \
+	$(top_builddir)/lib/libmiscutil.la $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_3) \
+	$(am__DEPENDENCIES_1)
 tests_testHttpReply_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testHttpReply_LDFLAGS) \
@@ -1154,22 +1208,18 @@
 	peer_sourcehash.cc peer_userhash.h peer_userhash.cc \
 	PeerPoolMgr.h PeerPoolMgr.cc Pipeline.cc Pipeline.h redirect.h \
 	tests/stub_libauth_acls.cc tests/stub_redirect.cc refresh.h \
-	refresh.cc RemovalPolicy.cc base/CharacterSet.h \
-	base/InstanceId.h MemBlob.h MemBlob.cc OutOfBoundsException.h \
-	SBuf.h SBuf.cc SBufExceptions.h SBufExceptions.cc SBufAlgos.h \
-	SBufAlgos.cc SBufDetailedStats.h \
-	tests/stub_SBufDetailedStats.cc SnmpRequest.h snmp_core.h \
-	snmp_core.cc snmp_agent.h snmp_agent.cc SquidMath.h \
-	SquidMath.cc IoStats.h stat.h stat.cc StatCounters.h \
-	StatCounters.cc StatHist.h StatHist.cc stmem.cc repl_modules.h \
-	store.cc store_client.cc store_digest.h \
-	tests/stub_store_digest.cc store_io.cc store_key_md5.h \
-	store_key_md5.cc store_log.h store_log.cc store_rebuild.h \
-	store_rebuild.cc store_swapin.h store_swapin.cc \
-	store_swapmeta.cc store_swapout.cc StoreFileSystem.cc \
-	StoreIOState.cc tests/stub_StoreMeta.cc StoreMetaUnpacker.cc \
-	StoreSwapLogData.cc StrList.h StrList.cc event.cc tools.h \
-	tools.cc Transients.cc tests/stub_tunnel.cc \
+	refresh.cc RemovalPolicy.cc tests/stub_SBufDetailedStats.cc \
+	SnmpRequest.h snmp_core.h snmp_core.cc snmp_agent.h \
+	snmp_agent.cc SquidMath.h SquidMath.cc IoStats.h stat.h \
+	stat.cc StatCounters.h StatCounters.cc StatHist.h StatHist.cc \
+	stmem.cc repl_modules.h store.cc store_client.cc \
+	store_digest.h tests/stub_store_digest.cc store_io.cc \
+	store_key_md5.h store_key_md5.cc store_log.h store_log.cc \
+	store_rebuild.h store_rebuild.cc store_swapin.h \
+	store_swapin.cc store_swapmeta.cc store_swapout.cc \
+	StoreFileSystem.cc StoreIOState.cc tests/stub_StoreMeta.cc \
+	StoreMetaUnpacker.cc StoreSwapLogData.cc StrList.h StrList.cc \
+	event.cc tools.h tools.cc Transients.cc tests/stub_tunnel.cc \
 	tests/stub_SwapDir.cc MemStore.cc url.cc urn.h urn.cc wccp2.h \
 	tests/stub_wccp2.cc whois.h tests/stub_whois.cc \
 	FadingCounter.cc win32.cc wordlist.h wordlist.cc
@@ -1216,12 +1266,12 @@
 	PeerPoolMgr.$(OBJEXT) Pipeline.$(OBJEXT) \
 	tests/stub_libauth_acls.$(OBJEXT) \
 	tests/stub_redirect.$(OBJEXT) refresh.$(OBJEXT) \
-	RemovalPolicy.$(OBJEXT) $(am__objects_9) SBufAlgos.$(OBJEXT) \
-	tests/stub_SBufDetailedStats.$(OBJEXT) $(am__objects_11) \
-	SquidMath.$(OBJEXT) stat.$(OBJEXT) StatCounters.$(OBJEXT) \
-	StatHist.$(OBJEXT) stmem.$(OBJEXT) store.$(OBJEXT) \
-	store_client.$(OBJEXT) tests/stub_store_digest.$(OBJEXT) \
-	store_io.$(OBJEXT) store_key_md5.$(OBJEXT) store_log.$(OBJEXT) \
+	RemovalPolicy.$(OBJEXT) tests/stub_SBufDetailedStats.$(OBJEXT) \
+	$(am__objects_10) SquidMath.$(OBJEXT) stat.$(OBJEXT) \
+	StatCounters.$(OBJEXT) StatHist.$(OBJEXT) stmem.$(OBJEXT) \
+	store.$(OBJEXT) store_client.$(OBJEXT) \
+	tests/stub_store_digest.$(OBJEXT) store_io.$(OBJEXT) \
+	store_key_md5.$(OBJEXT) store_log.$(OBJEXT) \
 	store_rebuild.$(OBJEXT) store_swapin.$(OBJEXT) \
 	store_swapmeta.$(OBJEXT) store_swapout.$(OBJEXT) \
 	StoreFileSystem.$(OBJEXT) StoreIOState.$(OBJEXT) \
@@ -1231,10 +1281,26 @@
 	tests/stub_tunnel.$(OBJEXT) tests/stub_SwapDir.$(OBJEXT) \
 	MemStore.$(OBJEXT) url.$(OBJEXT) urn.$(OBJEXT) \
 	tests/stub_wccp2.$(OBJEXT) tests/stub_whois.$(OBJEXT) \
-	FadingCounter.$(OBJEXT) $(am__objects_14) wordlist.$(OBJEXT)
-nodist_tests_testHttpRequest_OBJECTS = $(am__objects_18)
+	FadingCounter.$(OBJEXT) $(am__objects_13) wordlist.$(OBJEXT)
+nodist_tests_testHttpRequest_OBJECTS = $(am__objects_17)
 tests_testHttpRequest_OBJECTS = $(am_tests_testHttpRequest_OBJECTS) \
 	$(nodist_tests_testHttpRequest_OBJECTS)
+tests_testHttpRequest_DEPENDENCIES = libsquid.la clients/libclients.la \
+	servers/libservers.la helper/libhelper.la ftp/libftp.la \
+	http/libhttp.la ident/libident.la acl/libacls.la \
+	acl/libstate.la acl/libapi.la parser/libparser.la ip/libip.la \
+	fs/libfs.la $(SSL_LIBS) ipc/libipc.la parser/libparser.la \
+	dns/libdns.la base/libbase.la mgr/libmgr.la anyp/libanyp.la \
+	$(am__DEPENDENCIES_5) icmp/libicmp.la comm/libcomm.la \
+	log/liblog.la format/libformat.la store/libstore.la \
+	sbuf/libsbuf.la $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_4) $(top_builddir)/lib/libmisccontainers.la \
+	$(top_builddir)/lib/libmiscencoding.la \
+	$(top_builddir)/lib/libmiscutil.la $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_3) \
+	$(am__DEPENDENCIES_1)
 tests_testHttpRequest_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testHttpRequest_LDFLAGS) \
@@ -1265,11 +1331,13 @@
 	$(LDFLAGS) -o $@
 am_tests_testLookupTable_OBJECTS = tests/testLookupTable.$(OBJEXT) \
 	tests/stub_debug.$(OBJEXT) tests/stub_libmem.$(OBJEXT) \
-	tests/stub_SBufDetailedStats.$(OBJEXT) String.$(OBJEXT) \
-	$(am__objects_9) SBufAlgos.$(OBJEXT)
-nodist_tests_testLookupTable_OBJECTS = $(am__objects_19)
+	tests/stub_SBufDetailedStats.$(OBJEXT)
+nodist_tests_testLookupTable_OBJECTS = $(am__objects_18)
 tests_testLookupTable_OBJECTS = $(am_tests_testLookupTable_OBJECTS) \
 	$(nodist_tests_testLookupTable_OBJECTS)
+tests_testLookupTable_DEPENDENCIES = sbuf/libsbuf.la base/libbase.la \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_3) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 tests_testLookupTable_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testLookupTable_LDFLAGS) \
@@ -1295,10 +1363,7 @@
 	StoreMetaURL.cc StoreMetaURL.h StoreMetaVary.cc \
 	StoreMetaVary.h StoreSwapLogData.cc store_io.cc \
 	store_key_md5.h store_key_md5.cc store_swapmeta.cc \
-	store_swapout.cc base/CharacterSet.h base/InstanceId.h \
-	MemBlob.h MemBlob.cc OutOfBoundsException.h SBuf.h SBuf.cc \
-	SBufExceptions.h SBufExceptions.cc SBufAlgos.h SBufAlgos.cc \
-	SBufDetailedStats.h tests/stub_SBufDetailedStats.cc String.cc \
+	store_swapout.cc tests/stub_SBufDetailedStats.cc String.cc \
 	StrList.h StrList.cc Transients.h Transients.cc \
 	tests/testRock.cc tests/testRock.h tests/testStoreSupport.cc \
 	tests/testStoreSupport.h log/access_log.h \
@@ -1340,12 +1405,11 @@
 	tests/stub_StatHist.$(OBJEXT) stmem.$(OBJEXT) \
 	tests/stub_stat.$(OBJEXT) store.$(OBJEXT) \
 	StoreFileSystem.$(OBJEXT) StoreIOState.$(OBJEXT) \
-	StoreMetaUnpacker.$(OBJEXT) $(am__objects_12) \
+	StoreMetaUnpacker.$(OBJEXT) $(am__objects_11) \
 	StoreSwapLogData.$(OBJEXT) store_io.$(OBJEXT) \
 	store_key_md5.$(OBJEXT) store_swapmeta.$(OBJEXT) \
-	store_swapout.$(OBJEXT) $(am__objects_9) SBufAlgos.$(OBJEXT) \
-	tests/stub_SBufDetailedStats.$(OBJEXT) String.$(OBJEXT) \
-	StrList.$(OBJEXT) Transients.$(OBJEXT) \
+	store_swapout.$(OBJEXT) tests/stub_SBufDetailedStats.$(OBJEXT) \
+	String.$(OBJEXT) StrList.$(OBJEXT) Transients.$(OBJEXT) \
 	tests/testRock.$(OBJEXT) tests/testStoreSupport.$(OBJEXT) \
 	tests/stub_access_log.$(OBJEXT) tests/stub_cache_cf.$(OBJEXT) \
 	tests/stub_cache_manager.$(OBJEXT) \
@@ -1365,9 +1429,9 @@
 	tests/stub_store_rebuild.$(OBJEXT) \
 	tests/stub_store_stats.$(OBJEXT) tests/stub_tools.$(OBJEXT) \
 	time.$(OBJEXT) url.$(OBJEXT) wordlist.$(OBJEXT) \
-	$(am__objects_3) $(am__objects_13)
+	$(am__objects_3) $(am__objects_12)
 nodist_tests_testRock_OBJECTS = swap_log_op.$(OBJEXT) \
-	SquidMath.$(OBJEXT) $(am__objects_19)
+	SquidMath.$(OBJEXT) $(am__objects_18)
 tests_testRock_OBJECTS = $(am_tests_testRock_OBJECTS) \
 	$(nodist_tests_testRock_OBJECTS)
 tests_testRock_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
@@ -1375,59 +1439,53 @@
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testRock_LDFLAGS) \
 	$(LDFLAGS) -o $@
 am_tests_testSBuf_OBJECTS = tests/testSBuf.$(OBJEXT) \
-	tests/SBufFindTest.$(OBJEXT) $(am__objects_9) \
-	tests/stub_SBufDetailedStats.$(OBJEXT) SBufAlgos.$(OBJEXT) \
+	tests/SBufFindTest.$(OBJEXT) \
+	tests/stub_SBufDetailedStats.$(OBJEXT) \
 	tests/stub_time.$(OBJEXT) tests/stub_debug.$(OBJEXT) \
-	tests/stub_fatal.$(OBJEXT) \
-	tests/stub_HelperChildConfig.$(OBJEXT) \
-	tests/stub_libmem.$(OBJEXT) tests/stub_cache_cf.$(OBJEXT) \
-	tests/stub_cache_manager.$(OBJEXT) tests/stub_cbdata.$(OBJEXT) \
-	tests/stub_store.$(OBJEXT) tests/stub_store_stats.$(OBJEXT) \
-	tests/stub_tools.$(OBJEXT) String.$(OBJEXT) \
-	tests/stub_wordlist.$(OBJEXT) tests/stub_MemBuf.$(OBJEXT)
-nodist_tests_testSBuf_OBJECTS = $(am__objects_19)
+	tests/stub_fatal.$(OBJEXT) tests/stub_libmem.$(OBJEXT)
+nodist_tests_testSBuf_OBJECTS = $(am__objects_18)
 tests_testSBuf_OBJECTS = $(am_tests_testSBuf_OBJECTS) \
 	$(nodist_tests_testSBuf_OBJECTS)
+tests_testSBuf_DEPENDENCIES = sbuf/libsbuf.la base/libbase.la \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_3) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 tests_testSBuf_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testSBuf_LDFLAGS) \
 	$(LDFLAGS) -o $@
 am_tests_testSBufList_OBJECTS = tests/testSBufList.$(OBJEXT) \
-	$(am__objects_9) SBufList.$(OBJEXT) SBufAlgos.$(OBJEXT) \
 	tests/stub_SBufDetailedStats.$(OBJEXT) \
-	tests/stub_time.$(OBJEXT) tests/stub_MemObject.$(OBJEXT) \
-	tests/stub_cbdata.$(OBJEXT) tests/stub_comm.$(OBJEXT) \
-	tests/stub_debug.$(OBJEXT) tests/stub_event.$(OBJEXT) \
-	tests/stub_fatal.$(OBJEXT) tests/stub_fd.$(OBJEXT) \
-	tests/stub_HelperChildConfig.$(OBJEXT) \
-	tests/stub_libmem.$(OBJEXT) tests/stub_cache_cf.$(OBJEXT) \
-	tests/stub_cache_manager.$(OBJEXT) tests/stub_store.$(OBJEXT) \
-	tests/stub_stmem.$(OBJEXT) tests/stub_store_stats.$(OBJEXT) \
-	tests/stub_tools.$(OBJEXT) StatCounters.$(OBJEXT) \
-	String.$(OBJEXT) tests/stub_wordlist.$(OBJEXT) \
-	tests/stub_MemBuf.$(OBJEXT)
-nodist_tests_testSBufList_OBJECTS = $(am__objects_19)
+	tests/stub_time.$(OBJEXT) tests/stub_debug.$(OBJEXT) \
+	tests/stub_fatal.$(OBJEXT) tests/stub_libmem.$(OBJEXT)
+nodist_tests_testSBufList_OBJECTS = $(am__objects_18)
 tests_testSBufList_OBJECTS = $(am_tests_testSBufList_OBJECTS) \
 	$(nodist_tests_testSBufList_OBJECTS)
+tests_testSBufList_DEPENDENCIES = sbuf/libsbuf.la base/libbase.la \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_3) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 tests_testSBufList_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testSBufList_LDFLAGS) \
 	$(LDFLAGS) -o $@
 am_tests_testStatHist_OBJECTS = tests/stub_cbdata.$(OBJEXT) \
 	tests/stub_fatal.$(OBJEXT) tests/stub_MemBuf.$(OBJEXT) \
-	$(am__objects_9) tests/stub_SBufDetailedStats.$(OBJEXT) \
-	StatHist.$(OBJEXT) String.$(OBJEXT) \
-	tests/stub_cache_manager.$(OBJEXT) tests/stub_comm.$(OBJEXT) \
-	tests/stub_debug.$(OBJEXT) tests/stub_DelayId.$(OBJEXT) \
+	tests/stub_SBufDetailedStats.$(OBJEXT) StatHist.$(OBJEXT) \
+	String.$(OBJEXT) tests/stub_cache_manager.$(OBJEXT) \
+	tests/stub_comm.$(OBJEXT) tests/stub_debug.$(OBJEXT) \
+	tests/stub_DelayId.$(OBJEXT) \
 	tests/stub_HelperChildConfig.$(OBJEXT) \
 	tests/stub_libmem.$(OBJEXT) tests/stub_MemObject.$(OBJEXT) \
 	tests/stub_mime.$(OBJEXT) tests/stub_pconn.$(OBJEXT) \
 	tests/stub_stmem.$(OBJEXT) tests/stub_store.$(OBJEXT) \
 	tests/stub_store_stats.$(OBJEXT) time.$(OBJEXT) \
 	tests/stub_tools.$(OBJEXT) tests/testStatHist.$(OBJEXT)
-nodist_tests_testStatHist_OBJECTS = $(am__objects_19)
+nodist_tests_testStatHist_OBJECTS = $(am__objects_18)
 tests_testStatHist_OBJECTS = $(am_tests_testStatHist_OBJECTS) \
 	$(nodist_tests_testStatHist_OBJECTS)
+tests_testStatHist_DEPENDENCIES = sbuf/libsbuf.la base/libbase.la \
+	$(top_builddir)/lib/libmiscutil.la \
+	$(top_builddir)/lib/libmisccontainers.la $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_3)
 tests_testStatHist_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testStatHist_LDFLAGS) \
@@ -1455,9 +1513,6 @@
 	repl_modules.h store.cc store_io.cc store_swapout.cc \
 	StoreIOState.cc tests/stub_StoreMeta.cc StoreMetaUnpacker.cc \
 	StoreSwapLogData.cc store_key_md5.h store_key_md5.cc \
-	base/CharacterSet.h base/InstanceId.h MemBlob.h MemBlob.cc \
-	OutOfBoundsException.h SBuf.h SBuf.cc SBufExceptions.h \
-	SBufExceptions.cc SBufAlgos.h SBufAlgos.cc SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc String.cc StrList.h StrList.cc \
 	tests/CapturingStoreEntry.h log/access_log.h \
 	tests/stub_access_log.cc tests/stub_acl.cc cache_cf.h \
@@ -1500,10 +1555,10 @@
 	store.$(OBJEXT) store_io.$(OBJEXT) store_swapout.$(OBJEXT) \
 	StoreIOState.$(OBJEXT) tests/stub_StoreMeta.$(OBJEXT) \
 	StoreMetaUnpacker.$(OBJEXT) StoreSwapLogData.$(OBJEXT) \
-	store_key_md5.$(OBJEXT) $(am__objects_9) SBufAlgos.$(OBJEXT) \
-	tests/stub_SBufDetailedStats.$(OBJEXT) String.$(OBJEXT) \
-	StrList.$(OBJEXT) tests/stub_access_log.$(OBJEXT) \
-	tests/stub_acl.$(OBJEXT) tests/stub_cache_cf.$(OBJEXT) \
+	store_key_md5.$(OBJEXT) tests/stub_SBufDetailedStats.$(OBJEXT) \
+	String.$(OBJEXT) StrList.$(OBJEXT) \
+	tests/stub_access_log.$(OBJEXT) tests/stub_acl.$(OBJEXT) \
+	tests/stub_cache_cf.$(OBJEXT) \
 	tests/stub_cache_manager.$(OBJEXT) \
 	tests/stub_client_side_request.$(OBJEXT) \
 	tests/stub_comm.$(OBJEXT) tests/stub_debug.$(OBJEXT) \
@@ -1529,40 +1584,57 @@
 	tests/testStoreHashIndex.$(OBJEXT) \
 	tests/testStoreSupport.$(OBJEXT) tests/TestSwapDir.$(OBJEXT) \
 	tests/stub_time.$(OBJEXT) url.$(OBJEXT) wordlist.$(OBJEXT)
-nodist_tests_testStore_OBJECTS = $(am__objects_19) SquidMath.$(OBJEXT) \
+nodist_tests_testStore_OBJECTS = $(am__objects_18) SquidMath.$(OBJEXT) \
 	swap_log_op.$(OBJEXT)
 tests_testStore_OBJECTS = $(am_tests_testStore_OBJECTS) \
 	$(nodist_tests_testStore_OBJECTS)
+tests_testStore_DEPENDENCIES = libsquid.la http/libhttp.la \
+	parser/libparser.la ident/libident.la acl/libacls.la \
+	acl/libstate.la acl/libapi.la dns/libdns.la base/libbase.la \
+	ip/libip.la fs/libfs.la mgr/libmgr.la ipc/libipc.la \
+	anyp/libanyp.la mem/libmem.la store/libstore.la \
+	sbuf/libsbuf.la DiskIO/libdiskio.la \
+	$(top_builddir)/lib/libmisccontainers.la \
+	$(top_builddir)/lib/libmiscencoding.la \
+	$(top_builddir)/lib/libmiscutil.la $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) CommCalls.o \
+	$(am__DEPENDENCIES_3) $(am__DEPENDENCIES_1)
 tests_testStore_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testStore_LDFLAGS) \
 	$(LDFLAGS) -o $@
 am_tests_testString_OBJECTS = MemBuf.$(OBJEXT) String.$(OBJEXT) \
-	$(am__objects_9) tests/stub_SBufDetailedStats.$(OBJEXT) \
+	tests/stub_SBufDetailedStats.$(OBJEXT) \
 	tests/testString.$(OBJEXT) tests/stub_cache_cf.$(OBJEXT) \
 	tests/stub_cache_manager.$(OBJEXT) tests/stub_cbdata.$(OBJEXT) \
 	tests/stub_debug.$(OBJEXT) \
 	tests/stub_HelperChildConfig.$(OBJEXT) \
 	tests/stub_libmem.$(OBJEXT) tests/stub_tools.$(OBJEXT) \
 	tests/stub_time.$(OBJEXT) wordlist.$(OBJEXT)
-nodist_tests_testString_OBJECTS = $(am__objects_19)
+nodist_tests_testString_OBJECTS = $(am__objects_18)
 tests_testString_OBJECTS = $(am_tests_testString_OBJECTS) \
 	$(nodist_tests_testString_OBJECTS)
+tests_testString_DEPENDENCIES = base/libbase.la libsquid.la \
+	ip/libip.la sbuf/libsbuf.la $(top_builddir)/lib/libmiscutil.la \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_3) $(am__DEPENDENCIES_1)
 tests_testString_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testString_LDFLAGS) \
 	$(LDFLAGS) -o $@
 am_tests_testTokenizer_OBJECTS = tests/testTokenizer.$(OBJEXT)
-nodist_tests_testTokenizer_OBJECTS = $(am__objects_9) String.$(OBJEXT) \
-	$(am__objects_19) tests/stub_debug.$(OBJEXT) \
+nodist_tests_testTokenizer_OBJECTS = String.$(OBJEXT) \
+	$(am__objects_18) tests/stub_debug.$(OBJEXT) \
 	tests/stub_libmem.$(OBJEXT) tests/stub_time.$(OBJEXT) \
 	tests/stub_SBufDetailedStats.$(OBJEXT)
 tests_testTokenizer_OBJECTS = $(am_tests_testTokenizer_OBJECTS) \
 	$(nodist_tests_testTokenizer_OBJECTS)
 tests_testTokenizer_DEPENDENCIES = parser/libparser.la base/libbase.la \
-	$(top_builddir)/lib/libmiscutil.la $(am__DEPENDENCIES_3) \
-	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
-	$(am__DEPENDENCIES_1)
+	sbuf/libsbuf.la $(top_builddir)/lib/libmiscutil.la \
+	$(am__DEPENDENCIES_3) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 tests_testTokenizer_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testTokenizer_LDFLAGS) \
@@ -1605,10 +1677,7 @@
 	peer_proxy_negotiate_auth.cc peer_select.cc peer_sourcehash.h \
 	peer_sourcehash.cc peer_userhash.h peer_userhash.cc \
 	Pipeline.cc Pipeline.h redirect.h tests/stub_redirect.cc \
-	refresh.h refresh.cc RemovalPolicy.cc base/CharacterSet.h \
-	base/InstanceId.h MemBlob.h MemBlob.cc OutOfBoundsException.h \
-	SBuf.h SBuf.cc SBufExceptions.h SBufExceptions.cc SBufAlgos.h \
-	SBufAlgos.cc SBufDetailedStats.h \
+	refresh.h refresh.cc RemovalPolicy.cc \
 	tests/stub_SBufDetailedStats.cc SnmpRequest.h snmp_core.h \
 	snmp_core.cc snmp_agent.h snmp_agent.cc SquidMath.h \
 	SquidMath.cc IoStats.h stat.h stat.cc StatCounters.h \
@@ -1664,13 +1733,12 @@
 	peer_proxy_negotiate_auth.$(OBJEXT) peer_select.$(OBJEXT) \
 	peer_sourcehash.$(OBJEXT) peer_userhash.$(OBJEXT) \
 	Pipeline.$(OBJEXT) tests/stub_redirect.$(OBJEXT) \
-	refresh.$(OBJEXT) RemovalPolicy.$(OBJEXT) $(am__objects_9) \
-	SBufAlgos.$(OBJEXT) tests/stub_SBufDetailedStats.$(OBJEXT) \
-	$(am__objects_11) SquidMath.$(OBJEXT) stat.$(OBJEXT) \
-	StatCounters.$(OBJEXT) tests/stub_StatHist.$(OBJEXT) \
-	stmem.$(OBJEXT) store.$(OBJEXT) store_client.$(OBJEXT) \
-	tests/stub_store_digest.$(OBJEXT) store_io.$(OBJEXT) \
-	store_key_md5.$(OBJEXT) store_log.$(OBJEXT) \
+	refresh.$(OBJEXT) RemovalPolicy.$(OBJEXT) \
+	tests/stub_SBufDetailedStats.$(OBJEXT) $(am__objects_10) \
+	SquidMath.$(OBJEXT) stat.$(OBJEXT) StatCounters.$(OBJEXT) \
+	tests/stub_StatHist.$(OBJEXT) stmem.$(OBJEXT) store.$(OBJEXT) \
+	store_client.$(OBJEXT) tests/stub_store_digest.$(OBJEXT) \
+	store_io.$(OBJEXT) store_key_md5.$(OBJEXT) store_log.$(OBJEXT) \
 	store_rebuild.$(OBJEXT) store_swapin.$(OBJEXT) \
 	store_swapmeta.$(OBJEXT) store_swapout.$(OBJEXT) \
 	StoreFileSystem.$(OBJEXT) StoreIOState.$(OBJEXT) \
@@ -1687,10 +1755,27 @@
 	tests/stub_EventLoop.$(OBJEXT) tools.$(OBJEXT) \
 	tests/stub_tunnel.$(OBJEXT) url.$(OBJEXT) urn.$(OBJEXT) \
 	tests/stub_wccp2.$(OBJEXT) tests/stub_whois.$(OBJEXT) \
-	FadingCounter.$(OBJEXT) $(am__objects_14) wordlist.$(OBJEXT)
-nodist_tests_testURL_OBJECTS = $(am__objects_18)
+	FadingCounter.$(OBJEXT) $(am__objects_13) wordlist.$(OBJEXT)
+nodist_tests_testURL_OBJECTS = $(am__objects_17)
 tests_testURL_OBJECTS = $(am_tests_testURL_OBJECTS) \
 	$(nodist_tests_testURL_OBJECTS)
+tests_testURL_DEPENDENCIES = libsquid.la clients/libclients.la \
+	servers/libservers.la helper/libhelper.la http/libhttp.la \
+	ftp/libftp.la parser/libparser.la anyp/libanyp.la \
+	ident/libident.la acl/libacls.la eui/libeui.la acl/libstate.la \
+	acl/libapi.la dns/libdns.la base/libbase.la ip/libip.la \
+	fs/libfs.la $(SSL_LIBS) ipc/libipc.la mgr/libmgr.la \
+	$(am__DEPENDENCIES_5) icmp/libicmp.la comm/libcomm.la \
+	log/liblog.la format/libformat.la store/libstore.la \
+	sbuf/libsbuf.la $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_4) \
+	$(top_builddir)/lib/libmisccontainers.la \
+	$(top_builddir)/lib/libmiscencoding.la \
+	$(top_builddir)/lib/libmiscutil.la $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_3) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_3) \
+	$(am__DEPENDENCIES_1)
 tests_testURL_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_testURL_LDFLAGS) $(LDFLAGS) \
@@ -1728,11 +1813,8 @@
 	HttpMsg.cc RemovalPolicy.cc repl_modules.h store.cc \
 	store_key_md5.h store_key_md5.cc Parsing.cc ConfigOption.cc \
 	tests/stub_acl.cc cache_cf.h tests/stub_cache_cf.cc \
-	tests/stub_helper.cc cbdata.cc base/CharacterSet.h \
-	base/InstanceId.h MemBlob.h MemBlob.cc OutOfBoundsException.h \
-	SBuf.h SBuf.cc SBufExceptions.h SBufExceptions.cc SBufAlgos.h \
-	SBufAlgos.cc SBufDetailedStats.h \
-	tests/stub_SBufDetailedStats.cc String.cc tests/stub_debug.cc \
+	tests/stub_helper.cc cbdata.cc tests/stub_SBufDetailedStats.cc \
+	String.cc tests/stub_debug.cc \
 	tests/stub_client_side_request.cc tests/stub_http.cc \
 	tests/stub_libauth.cc mem_node.cc stmem.cc mime.h \
 	tests/stub_mime.cc HttpHeaderFieldInfo.h HttpHeaderTools.h \
@@ -1766,18 +1848,17 @@
 	Transients.$(OBJEXT) MasterXaction.$(OBJEXT) \
 	MemObject.$(OBJEXT) Notes.$(OBJEXT) StoreSwapLogData.$(OBJEXT) \
 	StoreIOState.$(OBJEXT) StoreMetaUnpacker.$(OBJEXT) \
-	$(am__objects_12) StoreFileSystem.$(OBJEXT) store_io.$(OBJEXT) \
+	$(am__objects_11) StoreFileSystem.$(OBJEXT) store_io.$(OBJEXT) \
 	store_swapout.$(OBJEXT) store_swapmeta.$(OBJEXT) \
-	$(am__objects_13) $(am__objects_14) event.$(OBJEXT) \
+	$(am__objects_12) $(am__objects_13) event.$(OBJEXT) \
 	$(am__objects_3) tests/stub_CacheDigest.$(OBJEXT) \
 	ConfigParser.$(OBJEXT) EventLoop.$(OBJEXT) HttpMsg.$(OBJEXT) \
 	RemovalPolicy.$(OBJEXT) store.$(OBJEXT) \
 	store_key_md5.$(OBJEXT) Parsing.$(OBJEXT) \
 	ConfigOption.$(OBJEXT) tests/stub_acl.$(OBJEXT) \
 	tests/stub_cache_cf.$(OBJEXT) tests/stub_helper.$(OBJEXT) \
-	cbdata.$(OBJEXT) $(am__objects_9) SBufAlgos.$(OBJEXT) \
-	tests/stub_SBufDetailedStats.$(OBJEXT) String.$(OBJEXT) \
-	tests/stub_debug.$(OBJEXT) \
+	cbdata.$(OBJEXT) tests/stub_SBufDetailedStats.$(OBJEXT) \
+	String.$(OBJEXT) tests/stub_debug.$(OBJEXT) \
 	tests/stub_client_side_request.$(OBJEXT) \
 	tests/stub_http.$(OBJEXT) tests/stub_libauth.$(OBJEXT) \
 	mem_node.$(OBJEXT) stmem.$(OBJEXT) tests/stub_mime.$(OBJEXT) \
@@ -1792,7 +1873,7 @@
 	tests/stub_store_client.$(OBJEXT) tests/stub_tools.$(OBJEXT) \
 	tests/testStoreSupport.$(OBJEXT) time.$(OBJEXT) \
 	wordlist.$(OBJEXT)
-nodist_tests_testUfs_OBJECTS = $(am__objects_19) SquidMath.$(OBJEXT) \
+nodist_tests_testUfs_OBJECTS = $(am__objects_18) SquidMath.$(OBJEXT) \
 	swap_log_op.$(OBJEXT)
 tests_testUfs_OBJECTS = $(am_tests_testUfs_OBJECTS) \
 	$(nodist_tests_testUfs_OBJECTS)
@@ -1851,9 +1932,6 @@
 	peer_sourcehash.cc peer_userhash.h peer_userhash.cc \
 	Pipeline.cc Pipeline.h pconn.cc redirect.h \
 	tests/stub_redirect.cc refresh.h refresh.cc RemovalPolicy.cc \
-	base/CharacterSet.h base/InstanceId.h MemBlob.h MemBlob.cc \
-	OutOfBoundsException.h SBuf.h SBuf.cc SBufExceptions.h \
-	SBufExceptions.cc SBufAlgos.h SBufAlgos.cc SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc SnmpRequest.h snmp_core.h \
 	snmp_core.cc snmp_agent.h snmp_agent.cc SquidMath.h \
 	SquidMath.cc IoStats.h stat.h stat.cc StatCounters.h \
@@ -1908,17 +1986,17 @@
 	peer_sourcehash.$(OBJEXT) peer_userhash.$(OBJEXT) \
 	Pipeline.$(OBJEXT) pconn.$(OBJEXT) \
 	tests/stub_redirect.$(OBJEXT) refresh.$(OBJEXT) \
-	RemovalPolicy.$(OBJEXT) $(am__objects_9) SBufAlgos.$(OBJEXT) \
-	tests/stub_SBufDetailedStats.$(OBJEXT) $(am__objects_11) \
-	SquidMath.$(OBJEXT) stat.$(OBJEXT) StatCounters.$(OBJEXT) \
-	StatHist.$(OBJEXT) stmem.$(OBJEXT) store.$(OBJEXT) \
-	store_client.$(OBJEXT) tests/stub_store_digest.$(OBJEXT) \
-	store_key_md5.$(OBJEXT) store_io.$(OBJEXT) store_log.$(OBJEXT) \
-	store_rebuild.$(OBJEXT) store_swapin.$(OBJEXT) \
-	store_swapmeta.$(OBJEXT) store_swapout.$(OBJEXT) \
-	StoreFileSystem.$(OBJEXT) StoreIOState.$(OBJEXT) \
-	tests/stub_StoreMeta.$(OBJEXT) StoreMetaUnpacker.$(OBJEXT) \
-	StoreSwapLogData.$(OBJEXT) String.$(OBJEXT) StrList.$(OBJEXT) \
+	RemovalPolicy.$(OBJEXT) tests/stub_SBufDetailedStats.$(OBJEXT) \
+	$(am__objects_10) SquidMath.$(OBJEXT) stat.$(OBJEXT) \
+	StatCounters.$(OBJEXT) StatHist.$(OBJEXT) stmem.$(OBJEXT) \
+	store.$(OBJEXT) store_client.$(OBJEXT) \
+	tests/stub_store_digest.$(OBJEXT) store_key_md5.$(OBJEXT) \
+	store_io.$(OBJEXT) store_log.$(OBJEXT) store_rebuild.$(OBJEXT) \
+	store_swapin.$(OBJEXT) store_swapmeta.$(OBJEXT) \
+	store_swapout.$(OBJEXT) StoreFileSystem.$(OBJEXT) \
+	StoreIOState.$(OBJEXT) tests/stub_StoreMeta.$(OBJEXT) \
+	StoreMetaUnpacker.$(OBJEXT) StoreSwapLogData.$(OBJEXT) \
+	String.$(OBJEXT) StrList.$(OBJEXT) \
 	tests/stub_SwapDir.$(OBJEXT) Transients.$(OBJEXT) \
 	tests/test_http_range.$(OBJEXT) \
 	tests/stub_external_acl.$(OBJEXT) \
@@ -1927,13 +2005,30 @@
 	tests/stub_libsecurity.$(OBJEXT) tests/stub_main_cc.$(OBJEXT) \
 	tests/stub_MemStore.$(OBJEXT) tests/stub_store_stats.$(OBJEXT) \
 	tests/stub_EventLoop.$(OBJEXT) time.$(OBJEXT) tools.$(OBJEXT) \
-	tests/stub_tunnel.$(OBJEXT) $(am__objects_13) url.$(OBJEXT) \
+	tests/stub_tunnel.$(OBJEXT) $(am__objects_12) url.$(OBJEXT) \
 	urn.$(OBJEXT) tests/stub_wccp2.$(OBJEXT) \
-	tests/stub_whois.$(OBJEXT) $(am__objects_14) \
+	tests/stub_whois.$(OBJEXT) $(am__objects_13) \
 	wordlist.$(OBJEXT)
-nodist_tests_test_http_range_OBJECTS = $(am__objects_18)
+nodist_tests_test_http_range_OBJECTS = $(am__objects_17)
 tests_test_http_range_OBJECTS = $(am_tests_test_http_range_OBJECTS) \
 	$(nodist_tests_test_http_range_OBJECTS)
+tests_test_http_range_DEPENDENCIES = libsquid.la clients/libclients.la \
+	servers/libservers.la ftp/libftp.la helper/libhelper.la \
+	http/libhttp.la parser/libparser.la ident/libident.la \
+	acl/libacls.la acl/libstate.la acl/libapi.la \
+	parser/libparser.la ip/libip.la fs/libfs.la anyp/libanyp.la \
+	icmp/libicmp.la comm/libcomm.la log/liblog.la \
+	format/libformat.la $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_4) $(SSL_LIBS) \
+	ipc/libipc.la dns/libdns.la base/libbase.la mgr/libmgr.la \
+	sbuf/libsbuf.la store/libstore.la $(am__DEPENDENCIES_5) \
+	$(top_builddir)/lib/libmisccontainers.la \
+	$(top_builddir)/lib/libmiscencoding.la \
+	$(top_builddir)/lib/libmiscutil.la $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_3) \
+	$(am__DEPENDENCIES_1)
 tests_test_http_range_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \
 	$(AM_CXXFLAGS) $(CXXFLAGS) $(tests_test_http_range_LDFLAGS) \
@@ -1951,7 +2046,7 @@
 	String.$(OBJEXT) SquidNew.$(OBJEXT) tests/stub_time.$(OBJEXT) \
 	ufsdump.$(OBJEXT) dlink.$(OBJEXT) \
 	tests/stub_HelperChildConfig.$(OBJEXT) RemovalPolicy.$(OBJEXT) \
-	$(am__objects_14) tests/stub_fd.$(OBJEXT)
+	$(am__objects_13) tests/stub_fd.$(OBJEXT)
 nodist_ufsdump_OBJECTS = globals.$(OBJEXT)
 ufsdump_OBJECTS = $(am_ufsdump_OBJECTS) $(nodist_ufsdump_OBJECTS)
 am_unlinkd_OBJECTS = unlinkd_daemon.$(OBJEXT)
@@ -2594,6 +2689,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = $(BUILT_SOURCES) squid.8 cf.data squid.conf.default \
@@ -2611,17 +2725,6 @@
 DNSSOURCE = \
 	dns_internal.cc
 
-SBUF_SOURCE = \
-	base/CharacterSet.h \
-	base/InstanceId.h \
-	MemBlob.h \
-	MemBlob.cc \
-	OutOfBoundsException.h \
-	SBuf.h \
-	SBuf.cc \
-	SBufExceptions.h \
-	SBufExceptions.cc
-
 STOREMETA_SOURCE = \
 	StoreMeta.cc \
 	StoreMeta.h \
@@ -2644,12 +2747,12 @@
 	LoadableModules.cc
 
 SUBDIRS = mem base anyp helper dns ftp parser comm eui acl format \
-	clients servers fs repl store DiskIO $(am__append_2) http ip \
-	icmp ident log ipc mgr $(am__append_4) security \
+	clients sbuf servers fs repl store DiskIO $(am__append_2) http \
+	ip icmp ident log ipc mgr $(am__append_4) security \
 	$(am__append_6) $(am__append_7) $(am__append_8)
 DIST_SUBDIRS = mem base anyp helper dns ftp parser comm eui acl format \
-	clients servers fs repl store DiskIO auth http ip icmp ident \
-	log ipc mgr ssl security snmp adaptation esi
+	clients sbuf servers fs repl store DiskIO auth http ip icmp \
+	ident log ipc mgr ssl security snmp adaptation esi
 @ENABLE_AUTH_TRUE@AUTH_LIBS = auth/libauth.la
 @ENABLE_AUTH_TRUE@AUTH_ACL_LIBS = auth/libacls.la
 SSL_LIBS = $(am__append_5)
@@ -2787,9 +2890,8 @@
 	PeerPoolMgr.h PeerPoolMgr.cc PeerSelectState.h PingData.h \
 	Pipeline.cc Pipeline.h protos.h redirect.h redirect.cc \
 	refresh.h refresh.cc RemovalPolicy.cc RemovalPolicy.h \
-	send-announce.h send-announce.cc $(SBUF_SOURCE) SBufAlgos.h \
-	SBufAlgos.cc SBufDetailedStats.h SBufDetailedStats.cc \
-	SBufStatsAction.h SBufStatsAction.cc $(SNMP_SOURCE) \
+	send-announce.h send-announce.cc SBufStatsAction.h \
+	SBufStatsAction.cc sbuf/StringConvert.h $(SNMP_SOURCE) \
 	SquidMath.h SquidMath.cc SquidNew.cc IoStats.h stat.h stat.cc \
 	StatCounters.h StatCounters.cc StatHist.h StatHist.cc \
 	String.cc StrList.h StrList.cc stmem.cc stmem.h repl_modules.h \
@@ -2853,10 +2955,10 @@
 	fs/libfs.la DiskIO/libdiskio.la $(SSL_LIBS) ipc/libipc.la \
 	mgr/libmgr.la anyp/libanyp.la comm/libcomm.la \
 	security/libsecurity.la eui/libeui.la icmp/libicmp.la \
-	log/liblog.la format/libformat.la $(XTRA_OBJS) $(REPL_OBJS) \
-	$(NETTLELIB) $(CRYPTLIB) $(REGEXLIB) $(ADAPTATION_LIBS) \
-	$(ESI_LIBS) $(SNMP_LIBS) mem/libmem.la store/libstore.la \
-	$(top_builddir)/lib/libmisccontainers.la \
+	log/liblog.la format/libformat.la sbuf/libsbuf.la $(XTRA_OBJS) \
+	$(REPL_OBJS) $(NETTLELIB) $(CRYPTLIB) $(REGEXLIB) \
+	$(ADAPTATION_LIBS) $(ESI_LIBS) $(SNMP_LIBS) mem/libmem.la \
+	store/libstore.la $(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
 	$(top_builddir)/lib/libmiscutil.la $(ATOMICLIB) $(SSLLIB) \
 	$(EPOLL_LIBS) $(MINGW_LIBS) $(KRB5LIBS) $(COMPAT_LIB) \
@@ -3044,28 +3146,11 @@
 EXTRA_DIST = cf_gen_defines cf.data.pre cf.data.depend cf.data.sed \
 	mk-globals-c.awk mk-string-arrays.awk repl_modules.sh \
 	$(STUB_SOURCE) mib.txt mime.conf.default squid.8.in
-DEFAULT_HTTP_PORT = 3128
-DEFAULT_ICP_PORT = 3130
-DEFAULT_PREFIX = $(prefix)
-DEFAULT_CONFIG_DIR = $(sysconfdir)
-DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
-DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
-DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
-DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
-DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
-DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
-DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
-DEFAULT_NETDB_FILE = $(DEFAULT_LOG_PREFIX)/netdb.state
-DEFAULT_SSL_DB_DIR = $(localstatedir)/lib/ssl_db
-DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
-DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
-DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
-DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
-DEFAULT_ICON_DIR = $(datadir)/icons
-DEFAULT_ERROR_DIR = $(datadir)/errors
 SUBSTITUTE = sed "\
 	s%@DEFAULT_ERROR_DIR@%$(DEFAULT_ERROR_DIR)%g;\
 	s%@DEFAULT_MIME_TABLE@%$(DEFAULT_MIME_TABLE)%g;\
+	s%@DEFAULT_SSL_CRTD@%$(DEFAULT_SSL_CRTD)%g;\
+	s%@DEFAULT_SSL_DB_DIR@%$(DEFAULT_SSL_DB_DIR)%g;\
 	s%@""PACKAGE_STRING""@%$(PACKAGE_STRING)%g;\
 	s%@SYSCONFDIR@%$(sysconfdir)%g;\
 	"
@@ -3095,8 +3180,7 @@
 #tests_testX_LDADD=\
 #	$(SQUID_CPPUNIT_LIBS) \
 #	$(SQUID_CPPUNIT_LA) \
-#	$(COMPAT_LIB) \
-#tests_testX_DEPENDENCIES= $(SQUID_CPPUNIT_LA)
+#	$(COMPAT_LIB) 
 
 # - add other component .(h|cc) files needed to link and run tests
 tests_testHttpReply_SOURCES = \
@@ -3141,10 +3225,6 @@
 	Notes.cc \
 	SquidString.h \
 	SquidTime.h \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	String.cc \
 	StrList.h \
@@ -3199,6 +3279,7 @@
 	base/libbase.la \
 	ipc/libipc.la \
 	mem/libmem.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
 	$(top_builddir)/lib/libmiscutil.la \
@@ -3209,7 +3290,6 @@
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 
-tests_testHttpReply_DEPENDENCIES = $(SQUID_CPPUNIT_LA)
 tests_testACLMaxUserIP_SOURCES = \
 	cbdata.cc \
 	ClientInfo.h \
@@ -3256,10 +3336,6 @@
 	StrList.cc \
 	tests/stub_StatHist.cc \
 	stmem.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	String.cc \
 	StoreIOState.cc \
@@ -3336,6 +3412,7 @@
 	ip/libip.la \
 	ipc/libipc.la \
 	mgr/libmgr.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
 	$(top_builddir)/lib/libmiscutil.la \
@@ -3361,15 +3438,13 @@
 
 tests_testBoilerplate_LDADD = \
 	$(SQUID_CPPUNIT_LIBS) \
+	$(SQUID_CPPUNIT_LA) \
 	$(SSLLIB) \
 	base/libbase.la \
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 
 tests_testBoilerplate_LDFLAGS = $(LIBADD_DL)
-tests_testBoilerplate_DEPENDENCIES = \
-	$(SQUID_CPPUNIT_LA)
-
 tests_testCharacterSet_SOURCES = \
 	tests/testCharacterSet.cc \
 	tests/testCharacterSet.h
@@ -3525,10 +3600,6 @@
 	refresh.h \
 	refresh.cc \
 	RemovalPolicy.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	$(SNMP_SOURCE) \
 	SquidMath.h \
@@ -3621,6 +3692,7 @@
 	$(SNMP_LIBS) \
 	mem/libmem.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
 	$(top_builddir)/lib/libmiscutil.la \
@@ -3634,10 +3706,6 @@
 	$(XTRA_LIBS)
 
 tests_testCacheManager_LDFLAGS = $(LIBADD_DL)
-tests_testCacheManager_DEPENDENCIES = \
-	$(REPL_OBJS) \
-	$(SQUID_CPPUNIT_LA)
-
 tests_testDiskIO_SOURCES = \
 	CacheDigest.h \
 	tests/stub_CacheDigest.cc \
@@ -3701,10 +3769,6 @@
 	StatHist.h \
 	tests/stub_StatHist.cc \
 	stmem.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	StoreFileSystem.cc \
 	StoreIOState.cc \
@@ -3803,6 +3867,7 @@
 	base/libbase.la \
 	mem/libmem.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
 	$(top_builddir)/lib/libmiscutil.la \
@@ -3971,10 +4036,6 @@
 	RemovalPolicy.cc \
 	StrList.h \
 	StrList.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	$(SNMP_SOURCE) \
 	SquidMath.cc \
@@ -4072,6 +4133,7 @@
 	ipc/libipc.la \
 	mgr/libmgr.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	$(SNMP_LIBS) \
 	$(NETTLELIB) \
 	$(REGEXLIB) \
@@ -4083,10 +4145,6 @@
 	$(XTRA_LIBS)
 
 tests_testEvent_LDFLAGS = $(LIBADD_DL)
-tests_testEvent_DEPENDENCIES = \
-	$(REPL_OBJS) \
-	$(SQUID_CPPUNIT_LA)
-
 tests_testEventLoop_SOURCES = \
 	AccessLogEntry.cc \
 	BodyPipe.cc \
@@ -4216,10 +4274,6 @@
 	tests/stub_redirect.cc \
 	refresh.h \
 	refresh.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	$(SNMP_SOURCE) \
 	SquidMath.h \
@@ -4318,6 +4372,7 @@
 	$(top_builddir)/lib/libmiscutil.la \
 	ipc/libipc.la \
 	mgr/libmgr.la \
+	sbuf/libsbuf.la \
 	store/libstore.la \
 	$(SNMP_LIBS) \
 	$(NETTLELIB) \
@@ -4330,10 +4385,6 @@
 	$(XTRA_LIBS)
 
 tests_testEventLoop_LDFLAGS = $(LIBADD_DL)
-tests_testEventLoop_DEPENDENCIES = \
-	$(REPL_OBJS) \
-	$(SQUID_CPPUNIT_LA)
-
 tests_test_http_range_SOURCES = \
 	AccessLogEntry.cc \
 	BodyPipe.cc \
@@ -4460,10 +4511,6 @@
 	refresh.h \
 	refresh.cc \
 	RemovalPolicy.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	$(SNMP_SOURCE) \
 	SquidMath.h \
@@ -4559,6 +4606,7 @@
 	dns/libdns.la \
 	base/libbase.la \
 	mgr/libmgr.la \
+	sbuf/libsbuf.la \
 	store/libstore.la \
 	$(SNMP_LIBS) \
 	$(top_builddir)/lib/libmisccontainers.la \
@@ -4574,16 +4622,12 @@
 	$(XTRA_LIBS)
 
 tests_test_http_range_LDFLAGS = $(LIBADD_DL)
-tests_test_http_range_DEPENDENCIES = \
-	$(SQUID_CPPUNIT_LA)
-
 tests_testTokenizer_SOURCES = \
 	tests/testTokenizer.h \
 	tests/testTokenizer.cc
 
 nodist_tests_testTokenizer_SOURCES = \
 	parser/Tokenizer.h \
-	$(SBUF_SOURCE) \
 	SquidString.h \
 	String.cc \
 	$(TESTSOURCES) \
@@ -4596,6 +4640,7 @@
 tests_testTokenizer_LDADD = \
 	parser/libparser.la \
 	base/libbase.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmiscutil.la \
 	$(COMPAT_LIB) \
 	$(SQUID_CPPUNIT_LA) \
@@ -4611,9 +4656,6 @@
 	mime_header.h \
 	String.cc \
 	cache_cf.h \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
 	tests/stub_SBufDetailedStats.cc \
 	tests/stub_cache_cf.cc \
 	tests/stub_cache_manager.cc \
@@ -4645,16 +4687,15 @@
 	SquidConfig.o \
 	base/libbase.la \
 	ip/libip.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmiscutil.la \
 	$(SQUID_CPPUNIT_LIBS) \
+	$(SQUID_CPPUNIT_LA) \
 	$(SSLLIB) \
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 
 tests_testHttp1Parser_LDFLAGS = $(LIBADD_DL)
-tests_testHttp1Parser_DEPENDENCIES = \
-	$(SQUID_CPPUNIT_LA)
-
 tests_testHttpRequest_SOURCES = \
 	AccessLogEntry.cc \
 	RequestFlags.h \
@@ -4793,10 +4834,6 @@
 	refresh.h \
 	refresh.cc \
 	RemovalPolicy.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	$(SNMP_SOURCE) \
 	SquidMath.h \
@@ -4881,6 +4918,7 @@
 	log/liblog.la \
 	format/libformat.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	$(REPL_OBJS) \
 	$(ADAPTATION_LIBS) \
 	$(ESI_LIBS) \
@@ -4897,10 +4935,6 @@
 	$(XTRA_LIBS)
 
 tests_testHttpRequest_LDFLAGS = $(LIBADD_DL)
-tests_testHttpRequest_DEPENDENCIES = \
-	$(REPL_OBJS) \
-	$(SQUID_CPPUNIT_LA)
-
 
 # icmp/libicmpcore.la is used by pinger so SHOULD NOT require more dependancies! :-(
 tests_testIcmp_SOURCES = \
@@ -5008,10 +5042,6 @@
 	StoreSwapLogData.cc \
 	store_key_md5.h \
 	store_key_md5.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	String.cc \
 	StrList.h \
@@ -5098,6 +5128,7 @@
 	anyp/libanyp.la \
 	mem/libmem.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	DiskIO/libdiskio.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
@@ -5105,21 +5136,17 @@
 	$(NETTLELIB) \
 	$(REGEXLIB) \
 	$(SQUID_CPPUNIT_LIBS) \
+	$(SQUID_CPPUNIT_LA) \
 	$(SSLLIB) \
 	CommCalls.o \
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 
 tests_testStore_LDFLAGS = $(LIBADD_DL)
-tests_testStore_DEPENDENCIES = \
-	$(SQUID_CPPUNIT_LA)
-
 tests_testString_SOURCES = \
 	ClientInfo.h \
 	MemBuf.cc \
 	String.cc \
-	$(SBUF_SOURCE) \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	tests/testString.cc \
 	tests/testString.h \
@@ -5143,17 +5170,16 @@
 	base/libbase.la \
 	libsquid.la \
 	ip/libip.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmiscutil.la \
 	$(REGEXLIB) \
 	$(SQUID_CPPUNIT_LIBS) \
+	$(SQUID_CPPUNIT_LA) \
 	$(SSLLIB) \
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 
 tests_testString_LDFLAGS = $(LIBADD_DL)
-tests_testString_DEPENDENCIES = \
-	$(SQUID_CPPUNIT_LA)
-
 SWAP_TEST_DS = \
 	repl_modules.o \
 	ident/libident.la \
@@ -5250,10 +5276,6 @@
 	tests/stub_cache_cf.cc \
 	tests/stub_helper.cc \
 	cbdata.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	String.cc \
 	tests/stub_debug.cc \
@@ -5333,6 +5355,7 @@
 	ip/libip.la \
 	mem/libmem.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
 	$(top_builddir)/lib/libmiscutil.la \
@@ -5431,10 +5454,6 @@
 	store_key_md5.cc \
 	store_swapmeta.cc \
 	store_swapout.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	String.cc \
 	StrList.h \
@@ -5512,6 +5531,7 @@
 	base/libbase.la \
 	mem/libmem.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	$(top_builddir)/lib/libmisccontainers.la \
 	$(top_builddir)/lib/libmiscencoding.la \
 	$(top_builddir)/lib/libmiscutil.la \
@@ -5651,10 +5671,6 @@
 	refresh.h \
 	refresh.cc \
 	RemovalPolicy.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	$(SNMP_SOURCE) \
 	SquidMath.h \
@@ -5754,6 +5770,7 @@
 	log/liblog.la \
 	format/libformat.la \
 	store/libstore.la \
+	sbuf/libsbuf.la \
 	$(REGEXLIB) \
 	$(REPL_OBJS) \
 	$(ADAPTATION_LIBS) \
@@ -5771,103 +5788,50 @@
 	$(XTRA_LIBS)
 
 tests_testURL_LDFLAGS = $(LIBADD_DL)
-tests_testURL_DEPENDENCIES = \
-	$(REPL_OBJS) \
-	$(SQUID_CPPUNIT_LA)
-
 tests_testSBuf_SOURCES = \
 	tests/testSBuf.h \
 	tests/testSBuf.cc \
 	tests/SBufFindTest.h \
 	tests/SBufFindTest.cc \
-	$(SBUF_SOURCE) \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufStream.h \
 	tests/stub_time.cc \
 	tests/stub_debug.cc \
 	tests/stub_fatal.cc \
-	tests/stub_HelperChildConfig.cc \
-	tests/stub_libmem.cc \
-	tests/stub_cache_cf.cc \
-	tests/stub_cache_manager.cc \
-	tests/stub_cbdata.cc \
-	tests/stub_store.cc \
-	tests/stub_store_stats.cc \
-	tests/stub_tools.cc \
-	SquidString.h \
-	String.cc \
-	tests/stub_wordlist.cc \
-	tests/stub_MemBuf.cc
+	tests/stub_libmem.cc
 
 nodist_tests_testSBuf_SOURCES = $(TESTSOURCES)
 tests_testSBuf_LDFLAGS = $(LIBADD_DL)
 tests_testSBuf_LDADD = \
+	sbuf/libsbuf.la \
 	base/libbase.la \
-	libsquid.la \
-	ip/libip.la \
-	mgr/libmgr.la \
-	$(top_builddir)/lib/libmiscutil.la \
-	$(REGEXLIB) \
 	$(SQUID_CPPUNIT_LIBS) \
 	$(COMPAT_LIB) \
-	$(XTRA_LIBS)
+	$(XTRA_LIBS) \
+	$(SQUID_CPPUNIT_LA)
 
-tests_testSBuf_DEPENDENCIES = $(SQUID_CPPUNIT_LA)
 tests_testSBufList_SOURCES = \
 	tests/testSBufList.h \
 	tests/testSBufList.cc \
-	$(SBUF_SOURCE) \
-	SBufList.h \
-	SBufList.cc \
-	SBufAlgos.h \
-	SBufAlgos.cc \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
-	SBufStream.h \
 	tests/stub_time.cc \
-	tests/stub_MemObject.cc \
-	tests/stub_cbdata.cc \
-	tests/stub_comm.cc \
 	tests/stub_debug.cc \
-	tests/stub_event.cc \
 	tests/stub_fatal.cc \
-	tests/stub_fd.cc \
-	tests/stub_HelperChildConfig.cc \
-	tests/stub_libmem.cc \
-	tests/stub_cache_cf.cc \
-	tests/stub_cache_manager.cc \
-	tests/stub_store.cc \
-	tests/stub_stmem.cc \
-	tests/stub_store_stats.cc \
-	tests/stub_tools.cc \
-	SquidString.h \
-	StatCounters.cc \
-	String.cc \
-	tests/stub_wordlist.cc \
-	tests/stub_MemBuf.cc
+	tests/stub_libmem.cc
 
 nodist_tests_testSBufList_SOURCES = $(TESTSOURCES)
 tests_testSBufList_LDFLAGS = $(LIBADD_DL)
 tests_testSBufList_LDADD = \
+	sbuf/libsbuf.la \
 	base/libbase.la \
-	libsquid.la \
-	ip/libip.la \
-	mgr/libmgr.la \
-	$(top_builddir)/lib/libmiscutil.la \
 	$(SQUID_CPPUNIT_LIBS) \
 	$(COMPAT_LIB) \
-	$(XTRA_LIBS)
+	$(XTRA_LIBS) \
+	$(SQUID_CPPUNIT_LA)
 
-tests_testSBufList_DEPENDENCIES = $(SQUID_CPPUNIT_LA)
 tests_testConfigParser_SOURCES = \
 	ClientInfo.h \
 	tests/stub_MemBuf.cc \
 	tests/stub_time.cc \
-	$(SBUF_SOURCE) \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	String.cc \
 	ConfigParser.cc \
@@ -5877,7 +5841,6 @@
 	tests/testConfigParser.h \
 	cache_cf.h \
 	tests/stub_cache_cf.cc \
-	tests/stub_cache_manager.cc \
 	tests/stub_cbdata.cc \
 	tests/stub_debug.cc \
 	tests/stub_libmem.cc \
@@ -5891,27 +5854,24 @@
 	$(TESTSOURCES)
 
 tests_testConfigParser_LDADD = \
-	base/libbase.la \
 	libsquid.la \
 	ip/libip.la \
+	sbuf/libsbuf.la \
+	base/libbase.la \
 	$(top_builddir)/lib/libmiscutil.la \
 	$(REGEXLIB) \
 	$(SQUID_CPPUNIT_LIBS) \
+	$(SQUID_CPPUNIT_LA) \
 	$(SSLLIB) \
 	$(COMPAT_LIB) \
 	$(XTRA_LIBS)
 
 tests_testConfigParser_LDFLAGS = $(LIBADD_DL)
-tests_testConfigParser_DEPENDENCIES = \
-	$(SQUID_CPPUNIT_LA)
-
 tests_testStatHist_SOURCES = \
 	tests/stub_cbdata.cc \
 	fatal.h \
 	tests/stub_fatal.cc \
 	tests/stub_MemBuf.cc \
-	$(SBUF_SOURCE) \
-	SBufDetailedStats.h \
 	tests/stub_SBufDetailedStats.cc \
 	StatHist.cc \
 	StatHist.h \
@@ -5941,6 +5901,7 @@
 
 tests_testStatHist_LDFLAGS = $(LIBADD_DL)
 tests_testStatHist_LDADD = \
+	sbuf/libsbuf.la \
 	base/libbase.la \
 	$(top_builddir)/lib/libmiscutil.la \
 	$(top_builddir)/lib/libmisccontainers.la \
@@ -5948,28 +5909,24 @@
 	$(SQUID_CPPUNIT_LA) \
 	$(COMPAT_LIB)
 
-tests_testStatHist_DEPENDENCIES = $(SQUID_CPPUNIT_LA)
 tests_testLookupTable_SOURCES = \
 	tests/testLookupTable.h \
 	tests/testLookupTable.cc \
 	tests/stub_debug.cc \
 	tests/stub_libmem.cc \
 	tests/stub_SBufDetailedStats.cc \
-	base/LookupTable.h \
-	String.cc \
-	$(SBUF_SOURCE) \
-	SBufAlgos.h \
-	SBufAlgos.cc
+	base/LookupTable.h
 
 nodist_tests_testLookupTable_SOURCES = $(TESTSOURCES)
 tests_testLookupTable_LDFLAGS = $(LIBADD_DL)
 tests_testLookupTable_LDADD = \
+	sbuf/libsbuf.la \
 	base/libbase.la \
 	$(SQUID_CPPUNIT_LIBS) \
 	$(COMPAT_LIB) \
-	$(XTRA_LIBS)
+	$(XTRA_LIBS) \
+	$(SQUID_CPPUNIT_LA)
 
-tests_testLookupTable_DEPENDENCIES = $(SQUID_CPPUNIT_LA)
 tests_testEnumIterator_SOURCES = \
 	base/EnumIterator.h \
 	tests/stub_debug.cc \
@@ -5988,7 +5945,6 @@
 	$(SQUID_CPPUNIT_LA) \
 	$(XTRA_LIBS)
 
-tests_testEnumIterator_DEPENDENCIES = 
 tests_testYesNoNone_SOURCES = \
 	tests/testYesNoNone.cc \
 	tests/testYesNoNone.h
@@ -6492,8 +6448,6 @@
 	tests/$(DEPDIR)/$(am__dirstamp)
 tests/SBufFindTest.$(OBJEXT): tests/$(am__dirstamp) \
 	tests/$(DEPDIR)/$(am__dirstamp)
-tests/stub_wordlist.$(OBJEXT): tests/$(am__dirstamp) \
-	tests/$(DEPDIR)/$(am__dirstamp)
 
 tests/testSBuf$(EXEEXT): $(tests_testSBuf_OBJECTS) $(tests_testSBuf_DEPENDENCIES) $(EXTRA_tests_testSBuf_DEPENDENCIES) tests/$(am__dirstamp)
 	@rm -f tests/testSBuf$(EXEEXT)
@@ -6627,7 +6581,6 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LoadableModules.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LogTags.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MasterXaction.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MemBlob.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MemBuf.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MemObject.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MemStore.Po@am__quote@
@@ -6639,11 +6592,6 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ProfStats.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RemovalPolicy.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RequestFlags.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SBuf.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SBufAlgos.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SBufDetailedStats.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SBufExceptions.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SBufList.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SBufStatsAction.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SquidConfig.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SquidList.Po@am__quote@
@@ -6827,7 +6775,6 @@
 @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/stub_tunnel.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/stub_wccp2.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/stub_whois.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/stub_wordlist.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/testACLMaxUserIP.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/testAddress.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@tests/$(DEPDIR)/testBoilerplate.Po@am__quote@
diff -u -r -N squid-4.0.7/src/mem/AllocatorProxy.cc squid-4.0.8/src/mem/AllocatorProxy.cc
--- squid-4.0.7/src/mem/AllocatorProxy.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/mem/AllocatorProxy.cc	2016-04-02 10:04:07.000000000 +1300
@@ -41,7 +41,7 @@
     if (!theAllocator)
         return 0;
     else
-        return memPoolInUseCount(theAllocator);
+        return theAllocator->inUseCount();
 }
 
 void
diff -u -r -N squid-4.0.7/src/mem/Makefile.in squid-4.0.8/src/mem/Makefile.in
--- squid-4.0.7/src/mem/Makefile.in	2016-02-24 06:49:40.000000000 +1300
+++ squid-4.0.8/src/mem/Makefile.in	2016-04-02 10:07:52.000000000 +1300
@@ -686,6 +686,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/mem/old_api.cc squid-4.0.8/src/mem/old_api.cc
--- squid-4.0.7/src/mem/old_api.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/mem/old_api.cc	2016-04-02 10:04:07.000000000 +1300
@@ -38,60 +38,21 @@
 static void memFree32K(void *);
 static void memFree64K(void *);
 
-/* module globals */
-const size_t squidSystemPageSize=getpagesize();
-
 /* local prototypes */
 static void memStringStats(std::ostream &);
 
 /* module locals */
-static MemAllocator *MemPools[MEM_MAX];
 static double xm_time = 0;
 static double xm_deltat = 0;
 
-/* all pools are ready to be used */
-static bool MemIsInitialized = false;
-
 /* string pools */
 #define mem_str_pool_count 6
 
-// 4 bytes bigger than the biggest string pool size
-// which is in turn calculated from SmallestStringBeforeMemIsInitialized
-static const size_t SmallestStringBeforeMemIsInitialized = 1024*16+4;
-
-static const struct {
+struct PoolMeta {
     const char *name;
     size_t obj_size;
-}
-
-StrPoolsAttrs[mem_str_pool_count] = {
-
-    {
-        "Short Strings", MemAllocator::RoundedSize(36),
-    },              /* to fit rfc1123 and similar */
-    {
-        "Medium Strings", MemAllocator::RoundedSize(128),
-    },              /* to fit most urls */
-    {
-        "Long Strings", MemAllocator::RoundedSize(512),
-    },
-    {
-        "1KB Strings", MemAllocator::RoundedSize(1024),
-    },
-    {
-        "4KB Strings", MemAllocator::RoundedSize(4*1024),
-    },
-    {
-        "16KB Strings",
-        MemAllocator::RoundedSize(SmallestStringBeforeMemIsInitialized-4)
-    }
 };
 
-static struct {
-    MemAllocator *pool;
-}
-
-StrPools[mem_str_pool_count];
 static Mem::Meter StrCountMeter;
 static Mem::Meter StrVolumeMeter;
 
@@ -100,6 +61,80 @@
 
 /* local routines */
 
+// XXX: refactor objects using these pools to use MEMPROXY classes instead
+// then remove this function entirely
+static MemAllocator *&
+GetPool(size_t type)
+{
+    static MemAllocator *pools[MEM_MAX];
+    static bool initialized = false;
+
+    if (!initialized) {
+        memset(pools, '\0', sizeof(pools));
+        initialized = true;
+        // Mem::Init() makes use of GetPool(type) to initialize
+        // the actual pools. So must come after the flag is true
+        Mem::Init();
+    }
+
+    return pools[type];
+}
+
+static MemAllocator &
+GetStrPool(size_t type)
+{
+    static MemAllocator *strPools[mem_str_pool_count];
+    static bool initialized = false;
+
+    static const PoolMeta PoolAttrs[mem_str_pool_count] = {
+        {"Short Strings", MemAllocator::RoundedSize(36)},      /* to fit rfc1123 and similar */
+        {"Medium Strings", MemAllocator::RoundedSize(128)},    /* to fit most urls */
+        {"Long Strings", MemAllocator::RoundedSize(512)},
+        {"1KB Strings", MemAllocator::RoundedSize(1024)},
+        {"4KB Strings", MemAllocator::RoundedSize(4*1024)},
+        {"16KB Strings", MemAllocator::RoundedSize(16*1024)}
+    };
+
+    if (!initialized) {
+        memset(strPools, '\0', sizeof(strPools));
+
+        /** Lastly init the string pools. */
+        for (int i = 0; i < mem_str_pool_count; ++i) {
+            strPools[i] = memPoolCreate(PoolAttrs[i].name, PoolAttrs[i].obj_size);
+            strPools[i]->zeroBlocks(false);
+
+            if (strPools[i]->objectSize() != PoolAttrs[i].obj_size)
+                debugs(13, DBG_IMPORTANT, "NOTICE: " << PoolAttrs[i].name <<
+                       " is " << strPools[i]->objectSize() <<
+                       " bytes instead of requested " <<
+                       PoolAttrs[i].obj_size << " bytes");
+        }
+
+        initialized = true;
+    }
+
+    return *strPools[type];
+}
+
+/* Find the best fit string pool type */
+static mem_type
+memFindStringSizeType(size_t net_size, bool fuzzy)
+{
+    mem_type type = MEM_NONE;
+    for (unsigned int i = 0; i < mem_str_pool_count; ++i) {
+        auto &pool = GetStrPool(i);
+        if (fuzzy && net_size < pool.objectSize()) {
+            type = static_cast<mem_type>(i);
+            break;
+        } else if (net_size == pool.objectSize()) {
+            type = static_cast<mem_type>(i);
+            break;
+        }
+    }
+
+    return type;
+}
+
 static void
 memStringStats(std::ostream &stream)
 {
@@ -111,13 +146,13 @@
     /* table body */
 
     for (i = 0; i < mem_str_pool_count; ++i) {
-        const MemAllocator *pool = StrPools[i].pool;
-        const auto plevel = pool->getMeter().inuse.currentLevel();
-        stream << std::setw(20) << std::left << pool->objectType();
+        const auto &pool = GetStrPool(i);
+        const auto plevel = pool.getMeter().inuse.currentLevel();
+        stream << std::setw(20) << std::left << pool.objectType();
         stream << std::right << "\t " << xpercentInt(plevel, StrCountMeter.currentLevel());
-        stream << "\t " << xpercentInt(plevel * pool->objectSize(), StrVolumeMeter.currentLevel()) << "\n";
+        stream << "\t " << xpercentInt(plevel * pool.objectSize(), StrVolumeMeter.currentLevel()) << "\n";
         pooled_count += plevel;
-        pooled_volume += plevel * pool->objectSize();
+        pooled_volume += plevel * pool.objectSize();
     }
 
     /* malloc strings */
@@ -175,56 +210,49 @@
 {
     assert(name && size);
 
-    if (MemPools[type] != NULL)
+    if (GetPool(type) != NULL)
         return;
 
-    MemPools[type] = memPoolCreate(name, size);
-    MemPools[type]->zeroBlocks(doZero);
+    GetPool(type) = memPoolCreate(name, size);
+    GetPool(type)->zeroBlocks(doZero);
 }
 
 /* find appropriate pool and use it (pools always init buffer with 0s) */
 void *
 memAllocate(mem_type type)
 {
-    assert(MemPools[type]);
-    return MemPools[type]->alloc();
+    assert(GetPool(type));
+    return GetPool(type)->alloc();
 }
 
 /* give memory back to the pool */
 void
 memFree(void *p, int type)
 {
-    assert(MemPools[type]);
-    MemPools[type]->freeOne(p);
+    assert(GetPool(type));
+    GetPool(type)->freeOne(p);
 }
 
 /* allocate a variable size buffer using best-fit string pool */
 void *
 memAllocString(size_t net_size, size_t * gross_size)
 {
-    MemAllocator *pool = NULL;
     assert(gross_size);
 
-    // if pools are not yet ready, make sure that
-    // the requested size is not poolable so that the right deallocator
-    // will be used
-    if (!MemIsInitialized && net_size < SmallestStringBeforeMemIsInitialized)
-        net_size = SmallestStringBeforeMemIsInitialized;
-
-    unsigned int i;
-    for (i = 0; i < mem_str_pool_count; ++i) {
-        if (net_size <= StrPoolsAttrs[i].obj_size) {
-            pool = StrPools[i].pool;
-            break;
-        }
+    auto type = memFindStringSizeType(net_size, true);
+    if (type != MEM_NONE) {
+        auto &pool = GetStrPool(type);
+        *gross_size = pool.objectSize();
+        assert(*gross_size >= net_size);
+        ++StrCountMeter;
+        StrVolumeMeter += *gross_size;
+        return pool.alloc();
     }
 
-    *gross_size = pool ? StrPoolsAttrs[i].obj_size : net_size;
-    assert(*gross_size >= net_size);
-    // may forget [de]allocations until MemIsInitialized
+    *gross_size = net_size;
     ++StrCountMeter;
     StrVolumeMeter += *gross_size;
-    return pool ? pool->alloc() : xcalloc(1, net_size);
+    return xcalloc(1, net_size);
 }
 
 size_t
@@ -233,7 +261,7 @@
     size_t result = 0;
 
     for (int counter = 0; counter < mem_str_pool_count; ++counter)
-        result += memPoolInUseCount(StrPools[counter].pool);
+        result += GetStrPool(counter).inUseCount();
 
     return result;
 }
@@ -242,23 +270,16 @@
 void
 memFreeString(size_t size, void *buf)
 {
-    MemAllocator *pool = NULL;
     assert(buf);
 
-    if (MemIsInitialized) {
-        for (unsigned int i = 0; i < mem_str_pool_count; ++i) {
-            if (size <= StrPoolsAttrs[i].obj_size) {
-                assert(size == StrPoolsAttrs[i].obj_size);
-                pool = StrPools[i].pool;
-                break;
-            }
-        }
-    }
+    auto type = memFindStringSizeType(size, false);
+    if (type != MEM_NONE)
+        GetStrPool(type).freeOne(buf);
+    else
+        xfree(buf);
 
-    // may forget [de]allocations until MemIsInitialized
     --StrCountMeter;
     StrVolumeMeter -= size;
-    pool ? pool->freeOne(buf) : xfree(buf);
 }
 
 /* Find the best fit MEM_X_BUF type */
@@ -396,7 +417,10 @@
 void
 Mem::Init(void)
 {
-    int i;
+    /* all pools are ready to be used */
+    static bool MemIsInitialized = false;
+    if (MemIsInitialized)
+        return;
 
     /** \par
      * NOTE: Mem::Init() is called before the config file is parsed
@@ -405,9 +429,6 @@
      * on stderr.
      */
 
-    /** \par
-     * Set all pointers to null. */
-    memset(MemPools, '\0', sizeof(MemPools));
     /**
      * Then initialize all pools.
      * \par
@@ -436,16 +457,7 @@
     memDataInit(MEM_NET_DB_NAME, "net_db_name", sizeof(net_db_name), 0);
     memDataInit(MEM_CLIENT_INFO, "ClientInfo", sizeof(ClientInfo), 0);
     memDataInit(MEM_MD5_DIGEST, "MD5 digest", SQUID_MD5_DIGEST_LENGTH, 0);
-    MemPools[MEM_MD5_DIGEST]->setChunkSize(512 * 1024);
-
-    /** Lastly init the string pools. */
-    for (i = 0; i < mem_str_pool_count; ++i) {
-        StrPools[i].pool = memPoolCreate(StrPoolsAttrs[i].name, StrPoolsAttrs[i].obj_size);
-        StrPools[i].pool->zeroBlocks(false);
-
-        if (StrPools[i].pool->objectSize() != StrPoolsAttrs[i].obj_size)
-            debugs(13, DBG_IMPORTANT, "Notice: " << StrPoolsAttrs[i].name << " is " << StrPools[i].pool->objectSize() << " bytes instead of requested " << StrPoolsAttrs[i].obj_size << " bytes");
-    }
+    GetPool(MEM_MD5_DIGEST)->setChunkSize(512 * 1024);
 
     MemIsInitialized = true;
 
@@ -483,7 +495,7 @@
          * memDataInit() line for type 't'.
          * Or placed the pool type in the wrong section of the enum list.
          */
-        assert(MemPools[t]);
+        assert(GetPool(t));
     }
 }
 
@@ -505,7 +517,7 @@
 int
 memInUse(mem_type type)
 {
-    return memPoolInUseCount(MemPools[type]);
+    return GetPool(type)->inUseCount();
 }
 
 /* ick */
diff -u -r -N squid-4.0.7/src/mem/Pool.cc squid-4.0.8/src/mem/Pool.cc
--- squid-4.0.7/src/mem/Pool.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/mem/Pool.cc	2016-04-02 10:04:07.000000000 +1300
@@ -29,16 +29,13 @@
 MemPools &
 MemPools::GetInstance()
 {
-    /* Must use this idiom, as we can be double-initialised
-     * if we are called during static initialisations.
-     */
-    if (!Instance)
-        Instance = new MemPools;
+    // We must initialize on first use (which may happen during static
+    // initialization) and preserve until the last user is gone (which
+    // may happen long after main() exit). We currently preserve forever.
+    static MemPools *Instance = new MemPools;
     return *Instance;
 }
 
-MemPools * MemPools::Instance = NULL;
-
 MemPoolIterator *
 memPoolIterate(void)
 {
@@ -301,12 +298,6 @@
 }
 
 int
-memPoolInUseCount(MemAllocator * pool)
-{
-    return pool->inUseCount();
-}
-
-int
 memPoolsTotalAllocated(void)
 {
     MemPoolGlobalStats stats;
diff -u -r -N squid-4.0.7/src/mem/Pool.h squid-4.0.8/src/mem/Pool.h
--- squid-4.0.7/src/mem/Pool.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/mem/Pool.h	2016-04-02 10:04:07.000000000 +1300
@@ -119,7 +119,6 @@
 public:
     static MemPools &GetInstance();
     MemPools();
-    void init();
     void flushMeters();
 
     /**
@@ -170,8 +169,6 @@
     ssize_t mem_idle_limit;
     int poolCount;
     bool defaultIsChunked;
-private:
-    static MemPools *Instance;
 };
 
 /**
@@ -359,8 +356,6 @@
 extern int memPoolGetGlobalStats(MemPoolGlobalStats * stats);
 
 /// \ingroup MemPoolsAPI
-extern int memPoolInUseCount(MemAllocator *);
-/// \ingroup MemPoolsAPI
 extern int memPoolsTotalAllocated(void);
 
 #endif /* _MEM_POOL_H_ */
diff -u -r -N squid-4.0.7/src/MemBlob.cc squid-4.0.8/src/MemBlob.cc
--- squid-4.0.7/src/MemBlob.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/MemBlob.cc	1970-01-01 12:00:00.000000000 +1200
@@ -1,143 +0,0 @@
-/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-#include "squid.h"
-#include "base/TextException.h"
-#include "Debug.h"
-#include "MemBlob.h"
-#include "SBufDetailedStats.h"
-
-#include <iostream>
-
-MemBlobStats MemBlob::Stats;
-InstanceIdDefinitions(MemBlob, "blob");
-
-/* MemBlobStats */
-
-MemBlobStats::MemBlobStats(): alloc(0), live(0), append(0), liveBytes(0)
-{}
-
-MemBlobStats&
-MemBlobStats::operator += (const MemBlobStats& s)
-{
-    alloc+=s.alloc;
-    live+=s.live;
-    append+=s.append;
-    liveBytes+=s.liveBytes;
-
-    return *this;
-}
-
-std::ostream&
-MemBlobStats::dump(std::ostream &os) const
-{
-    os <<
-       "MemBlob created: " << alloc <<
-       "\nMemBlob alive: " << live <<
-       "\nMemBlob append calls: " << append <<
-       "\nMemBlob currently allocated size: " << liveBytes <<
-       "\nlive MemBlob mean current allocation size: " <<
-       (static_cast<double>(liveBytes)/(live?live:1)) << std::endl;
-    return os;
-}
-
-/* MemBlob */
-
-MemBlob::MemBlob(const MemBlob::size_type reserveSize) :
-    mem(NULL), capacity(0), size(0) // will be set by memAlloc
-{
-    debugs(MEMBLOB_DEBUGSECTION,9, HERE << "constructed, this="
-           << static_cast<void*>(this) << " id=" << id
-           << " reserveSize=" << reserveSize);
-    memAlloc(reserveSize);
-}
-
-MemBlob::MemBlob(const char *buffer, const MemBlob::size_type bufSize) :
-    mem(NULL), capacity(0), size(0) // will be set by memAlloc
-{
-    debugs(MEMBLOB_DEBUGSECTION,9, HERE << "constructed, this="
-           << static_cast<void*>(this) << " id=" << id
-           << " buffer=" << static_cast<const void*>(buffer)
-           << " bufSize=" << bufSize);
-    memAlloc(bufSize);
-    append(buffer, bufSize);
-}
-
-MemBlob::~MemBlob()
-{
-    if (mem || capacity)
-        memFreeString(capacity,mem);
-    Stats.liveBytes -= capacity;
-    --Stats.live;
-    recordMemBlobSizeAtDestruct(capacity);
-
-    debugs(MEMBLOB_DEBUGSECTION,9, HERE << "destructed, this="
-           << static_cast<void*>(this) << " id=" << id
-           << " capacity=" << capacity
-           << " size=" << size);
-}
-
-/** Allocate an available space area of at least minSize bytes in size.
- *  Must be called by constructors and only by constructors.
- */
-void
-MemBlob::memAlloc(const size_type minSize)
-{
-    size_t actualAlloc = minSize;
-
-    Must(!mem);
-    mem = static_cast<char*>(memAllocString(actualAlloc, &actualAlloc));
-    Must(mem);
-
-    capacity = actualAlloc;
-    size = 0;
-    debugs(MEMBLOB_DEBUGSECTION, 8,
-           id << " memAlloc: requested=" << minSize <<
-           ", received=" << capacity);
-    ++Stats.live;
-    ++Stats.alloc;
-    Stats.liveBytes += capacity;
-}
-
-void
-MemBlob::appended(const size_type n)
-{
-    Must(willFit(n));
-    size += n;
-    ++Stats.append;
-}
-
-void
-MemBlob::append(const char *source, const size_type n)
-{
-    if (n > 0) { // appending zero bytes is allowed but only affects the stats
-        Must(willFit(n));
-        Must(source);
-        memmove(mem + size, source, n);
-        size += n;
-    }
-    ++Stats.append;
-}
-
-const MemBlobStats&
-MemBlob::GetStats()
-{
-    return Stats;
-}
-
-std::ostream&
-MemBlob::dump(std::ostream &os) const
-{
-    os << "id @" << (void *)this
-       << "mem:" << static_cast<void*>(mem)
-       << ",capacity:" << capacity
-       << ",size:" << size
-       << ",refs:" << LockCount() << "; ";
-    return os;
-}
-
diff -u -r -N squid-4.0.7/src/MemBlob.h squid-4.0.8/src/MemBlob.h
--- squid-4.0.7/src/MemBlob.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/MemBlob.h	1970-01-01 12:00:00.000000000 +1200
@@ -1,124 +0,0 @@
-/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-#ifndef SQUID_MEMBLOB_H_
-#define SQUID_MEMBLOB_H_
-
-#define MEMBLOB_DEBUGSECTION 24
-
-#include "base/InstanceId.h"
-#include "base/RefCount.h"
-#include "mem/forward.h"
-
-/// Various MemBlob class-wide statistics.
-class MemBlobStats
-{
-public:
-    MemBlobStats();
-
-    /// dumps class-wide statistics
-    std::ostream& dump(std::ostream& os) const;
-
-    MemBlobStats& operator += (const MemBlobStats&);
-
-public:
-    uint64_t alloc;     ///< number of MemBlob instances created so far
-    uint64_t live;      ///< number of MemBlob instances currently alive
-    uint64_t append;    ///< number of MemBlob::append() calls
-    uint64_t liveBytes; ///< the total size of currently allocated storage
-};
-
-/** Refcountable, fixed-size, content-agnostic memory buffer.
- *
- * Allocated memory block is divided into two sequential areas:
- * "used memory" and "available space". The used area can be filled during
- * construction, grows via the append() call, and can be clear()ed.
- *
- * MemBlob users can cooperate to safely share the used area. However, MemBlob
- * provides weak use accounting and no sharing protections besides refcounting.
- */
-class MemBlob: public RefCountable
-{
-    MEMPROXY_CLASS(MemBlob);
-
-public:
-    typedef RefCount<MemBlob> Pointer;
-    typedef uint32_t size_type;
-
-    /// obtain a const view of class-wide statistics
-    static const MemBlobStats& GetStats();
-
-    /// create a new MemBlob with at least reserveSize capacity
-    explicit MemBlob(const size_type reserveSize);
-
-    /// create a MemBlob containing a copy of the buffer of a given size
-    MemBlob(const char *buffer, const size_type bufferSize);
-
-    virtual ~MemBlob();
-
-    /// the number unused bytes at the end of the allocated blob
-    size_type spaceSize() const { return capacity - size; }
-
-    /** check whether the caller can successfully append() n bytes
-     *
-     * \return true  the caller may append() n bytes to this blob now
-     * \param off    the end of the blob area currently used by the caller
-     * \param n      the total number of bytes the caller wants to append
-     */
-    bool canAppend(const size_type off, const size_type n) const {
-        // TODO: ignore offset (and adjust size) when the blob is not shared?
-        return isAppendOffset(off) && willFit(n);
-    }
-
-    /** adjusts internal object state as if exactly n bytes were append()ed
-     *
-     * \throw TextException if there was not enough space in the blob
-     * \param n the number of bytes that were appended
-     */
-    void appended(const size_type n);
-
-    /** copies exactly n bytes from the source to the available space area,
-     *  enlarging the used area by n bytes
-     *
-     * \throw TextException if there is not enough space in the blob
-     * \param source raw buffer to be copied
-     * \param n the number of bytes to copy from the source buffer
-     */
-    void append(const char *source, const size_type n);
-
-    /// extends the available space to the entire allocated blob
-    void clear() { size = 0; }
-
-    /// dump debugging information
-    std::ostream & dump(std::ostream &os) const;
-
-public:
-    /* MemBlob users should avoid these and must treat them as read-only */
-    char *mem;          ///< raw allocated memory block
-    size_type capacity; ///< size of the raw allocated memory block
-    size_type size;     ///< maximum allocated memory in use by callers
-    const InstanceId<MemBlob> id; ///< blob identifier
-
-private:
-    static MemBlobStats Stats; ///< class-wide statistics
-
-    void memAlloc(const size_type memSize);
-
-    /// whether the offset points to the end of the used area
-    bool isAppendOffset(const size_type off) const { return off == size; }
-
-    /// whether n more bytes can be appended
-    bool willFit(const size_type n) const { return n <= spaceSize(); }
-
-    /* copying is not implemented */
-    MemBlob(const MemBlob &);
-    MemBlob& operator =(const MemBlob &);
-};
-
-#endif /* SQUID_MEMBLOB_H_ */
-
diff -u -r -N squid-4.0.7/src/MemObject.cc squid-4.0.8/src/MemObject.cc
--- squid-4.0.7/src/MemObject.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/MemObject.cc	2016-04-02 10:04:07.000000000 +1300
@@ -145,8 +145,6 @@
     HTTPMSGUNLOCK(request);
 
     ctx_exit(ctx);              /* must exit before we free mem->url */
-
-    safe_free(vary_headers);
 }
 
 void
@@ -230,8 +228,8 @@
 MemObject::stat(MemBuf * mb) const
 {
     mb->appendf("\t" SQUIDSBUFPH " %s\n", SQUIDSBUFPRINT(method.image()), logUri());
-    if (vary_headers)
-        mb->appendf("\tvary_headers: %s\n", vary_headers);
+    if (!vary_headers.isEmpty())
+        mb->appendf("\tvary_headers: " SQUIDSBUFPH "\n", SQUIDSBUFPRINT(vary_headers));
     mb->appendf("\tinmem_lo: %" PRId64 "\n", inmem_lo);
     mb->appendf("\tinmem_hi: %" PRId64 "\n", data_hdr.endOffset());
     mb->appendf("\tswapout: %" PRId64 " bytes queued\n", swapout.queue_offset);
diff -u -r -N squid-4.0.7/src/MemObject.h squid-4.0.8/src/MemObject.h
--- squid-4.0.7/src/MemObject.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/MemObject.h	2016-04-02 10:04:07.000000000 +1300
@@ -13,6 +13,8 @@
 #include "dlink.h"
 #include "http/RequestMethod.h"
 #include "RemovalPolicy.h"
+#include "sbuf/SBuf.h"
+#include "SquidString.h"
 #include "stmem.h"
 #include "StoreIOBuffer.h"
 #include "StoreIOState.h"
@@ -169,7 +171,7 @@
     unsigned int chksum;
 #endif
 
-    const char *vary_headers;
+    SBuf vary_headers;
 
     void delayRead(DeferredRead const &);
     void kickReads();
diff -u -r -N squid-4.0.7/src/MemStore.cc squid-4.0.8/src/MemStore.cc
--- squid-4.0.7/src/MemStore.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/MemStore.cc	2016-04-02 10:04:07.000000000 +1300
@@ -35,6 +35,138 @@
 // used except for a positivity test. A unique value is handy for debugging.
 static const uint32_t SpacePoolId = 510716;
 
+/// Packs to shared memory, allocating new slots/pages as needed.
+/// Requires an Ipc::StoreMapAnchor locked for writing.
+class ShmWriter: public Packable
+{
+public:
+    ShmWriter(MemStore &aStore, StoreEntry *anEntry, const sfileno aFileNo, Ipc::StoreMapSliceId aFirstSlice = -1);
+
+    /* Packable API */
+    virtual void append(const char *aBuf, int aSize) override;
+    virtual void vappendf(const char *fmt, va_list ap) override;
+
+public:
+    StoreEntry *entry; ///< the entry being updated
+
+    /// the slot keeping the first byte of the appended content (at least)
+    /// either set via constructor parameter or allocated by the first append
+    Ipc::StoreMapSliceId firstSlice;
+
+    /// the slot keeping the last byte of the appended content (at least)
+    Ipc::StoreMapSliceId lastSlice;
+
+    uint64_t totalWritten; ///< cumulative number of bytes appended so far
+
+protected:
+    void copyToShm();
+    void copyToShmSlice(Ipc::StoreMap::Slice &slice);
+
+private:
+    MemStore &store;
+    const sfileno fileNo;
+
+    /* set by (and only valid during) append calls */
+    const char *buf; ///< content being appended now
+    int bufSize; ///< buf size
+    int bufWritten; ///< buf bytes appended so far
+};
+
+/* ShmWriter */
+
+ShmWriter::ShmWriter(MemStore &aStore, StoreEntry *anEntry, const sfileno aFileNo, Ipc::StoreMapSliceId aFirstSlice):
+    entry(anEntry),
+    firstSlice(aFirstSlice),
+    lastSlice(firstSlice),
+    totalWritten(0),
+    store(aStore),
+    fileNo(aFileNo),
+    buf(nullptr),
+    bufSize(0),
+    bufWritten(0)
+{
+    Must(entry);
+}
+
+void
+ShmWriter::append(const char *aBuf, int aBufSize)
+{
+    Must(!buf);
+    buf = aBuf;
+    bufSize = aBufSize;
+    if (bufSize) {
+        Must(buf);
+        bufWritten = 0;
+        copyToShm();
+    }
+    buf = nullptr;
+    bufSize = 0;
+    bufWritten = 0;
+}
+
+void
+ShmWriter::vappendf(const char *fmt, va_list ap)
+{
+    SBuf vaBuf;
+#if defined(VA_COPY)
+    va_list apCopy;
+    VA_COPY(apCopy, ap);
+    vaBuf.vappendf(fmt, apCopy);
+    va_end(apCopy);
+#else
+    vaBuf.vappendf(fmt, ap);
+#endif
+    append(vaBuf.rawContent(), vaBuf.length());
+}
+
+/// copies the entire buffer to shared memory
+void
+ShmWriter::copyToShm()
+{
+    Must(bufSize > 0); // do not use up shared memory pages for nothing
+    Must(firstSlice < 0 || lastSlice >= 0);
+
+    // fill, skip slices that are already full
+    while (bufWritten < bufSize) {
+        Ipc::StoreMap::Slice &slice = store.nextAppendableSlice(fileNo, lastSlice);
+        if (firstSlice < 0)
+            firstSlice = lastSlice;
+        copyToShmSlice(slice);
+    }
+
+    debugs(20, 7, "stored " << bufWritten << '/' << totalWritten << " header bytes of " << *entry);
+}
+
+/// copies at most one slice worth of buffer to shared memory
+void
+ShmWriter::copyToShmSlice(Ipc::StoreMap::Slice &slice)
+{
+    Ipc::Mem::PageId page = store.pageForSlice(lastSlice);
+    debugs(20, 7, "entry " << *entry << " slice " << lastSlice << " has " <<
+           page);
+
+    Must(bufWritten <= bufSize);
+    const int64_t writingDebt = bufSize - bufWritten;
+    const int64_t pageSize = Ipc::Mem::PageSize();
+    const int64_t sliceOffset = totalWritten % pageSize;
+    const int64_t copySize = std::min(writingDebt, pageSize - sliceOffset);
+    memcpy(static_cast<char*>(PagePointer(page)) + sliceOffset, buf + bufWritten,
+           copySize);
+
+    debugs(20, 7, "copied " << slice.size << '+' << copySize << " bytes of " <<
+           entry << " from " << sliceOffset << " in " << page);
+
+    slice.size += copySize;
+    bufWritten += copySize;
+    totalWritten += copySize;
+    // fresh anchor.basics.swap_file_sz is already set [to the stale value]
+
+    // either we wrote everything or we filled the entire slice
+    Must(bufWritten == bufSize || sliceOffset + copySize == pageSize);
+}
+
+/* MemStore */
+
 MemStore::MemStore(): map(NULL), lastWritingSlice(-1)
 {
 }
@@ -207,6 +339,69 @@
     return NULL;
 }
 
+void
+MemStore::updateHeaders(StoreEntry *updatedE)
+{
+    if (!map)
+        return;
+
+    Ipc::StoreMapUpdate update(updatedE);
+    assert(updatedE);
+    assert(updatedE->mem_obj);
+    if (!map->openForUpdating(update, updatedE->mem_obj->memCache.index))
+        return;
+
+    try {
+        updateHeadersOrThrow(update);
+    } catch (const std::exception &ex) {
+        debugs(20, 2, "error starting to update entry " << *updatedE << ": " << ex.what());
+        map->abortUpdating(update);
+    }
+}
+
+void
+MemStore::updateHeadersOrThrow(Ipc::StoreMapUpdate &update)
+{
+    // our +/- hdr_sz math below does not work if the chains differ [in size]
+    Must(update.stale.anchor->basics.swap_file_sz == update.fresh.anchor->basics.swap_file_sz);
+
+    const HttpReply *rawReply = update.entry->getReply();
+    Must(rawReply);
+    const HttpReply &reply = *rawReply;
+    const uint64_t staleHdrSz = reply.hdr_sz;
+    debugs(20, 7, "stale hdr_sz: " << staleHdrSz);
+
+    /* we will need to copy same-slice payload after the stored headers later */
+    Must(staleHdrSz > 0);
+    update.stale.splicingPoint = map->sliceContaining(update.stale.fileNo, staleHdrSz);
+    Must(update.stale.splicingPoint >= 0);
+    Must(update.stale.anchor->basics.swap_file_sz >= staleHdrSz);
+
+    Must(update.stale.anchor);
+    ShmWriter writer(*this, update.entry, update.fresh.fileNo);
+    reply.packHeadersInto(&writer);
+    const uint64_t freshHdrSz = writer.totalWritten;
+    debugs(20, 7, "fresh hdr_sz: " << freshHdrSz << " diff: " << (freshHdrSz - staleHdrSz));
+
+    /* copy same-slice payload remaining after the stored headers */
+    const Ipc::StoreMapSlice &slice = map->readableSlice(update.stale.fileNo, update.stale.splicingPoint);
+    const Ipc::StoreMapSlice::Size sliceCapacity = Ipc::Mem::PageSize();
+    const Ipc::StoreMapSlice::Size headersInLastSlice = staleHdrSz % sliceCapacity;
+    Must(headersInLastSlice > 0); // or sliceContaining() would have stopped earlier
+    Must(slice.size >= headersInLastSlice);
+    const Ipc::StoreMapSlice::Size payloadInLastSlice = slice.size - headersInLastSlice;
+    const MemStoreMapExtras::Item &extra = extras->items[update.stale.splicingPoint];
+    char *page = static_cast<char*>(PagePointer(extra.page));
+    debugs(20, 5, "appending same-slice payload: " << payloadInLastSlice);
+    writer.append(page + headersInLastSlice, payloadInLastSlice);
+    update.fresh.splicingPoint = writer.lastSlice;
+
+    update.fresh.anchor->basics.swap_file_sz -= staleHdrSz;
+    update.fresh.anchor->basics.swap_file_sz += freshHdrSz;
+
+    map->closeForUpdating(update);
+}
+
 bool
 MemStore::anchorCollapsed(StoreEntry &collapsed, bool &inSync)
 {
@@ -423,7 +618,7 @@
 
     assert(e.mem_obj);
 
-    if (e.mem_obj->vary_headers) {
+    if (!e.mem_obj->vary_headers.isEmpty()) {
         // XXX: We must store/load SerialisedMetaData to cache Vary in RAM
         debugs(20, 5, "Vary not yet supported: " << e.mem_obj->vary_headers);
         return false;
@@ -498,10 +693,6 @@
     assert(map);
     assert(e.mem_obj);
 
-    const int32_t index = e.mem_obj->memCache.index;
-    assert(index >= 0);
-    Ipc::StoreMapAnchor &anchor = map->writeableEntry(index);
-
     const int64_t eSize = e.mem_obj->endOffset();
     if (e.mem_obj->memCache.offset >= eSize) {
         debugs(20, 5, "postponing copying " << e << " for lack of news: " <<
@@ -509,34 +700,19 @@
         return; // nothing to do (yet)
     }
 
-    if (anchor.start < 0) { // must allocate the very first slot for e
-        Ipc::Mem::PageId page;
-        anchor.start = reserveSapForWriting(page); // throws
-        extras->items[anchor.start].page = page;
-    }
-
+    const int32_t index = e.mem_obj->memCache.index;
+    assert(index >= 0);
+    Ipc::StoreMapAnchor &anchor = map->writeableEntry(index);
     lastWritingSlice = anchor.start;
-    const size_t sliceCapacity = Ipc::Mem::PageSize();
 
     // fill, skip slices that are already full
     // Optimize: remember lastWritingSlice in e.mem_obj
     while (e.mem_obj->memCache.offset < eSize) {
-        Ipc::StoreMap::Slice &slice =
-            map->writeableSlice(e.mem_obj->memCache.index, lastWritingSlice);
-
-        if (slice.size >= sliceCapacity) {
-            if (slice.next >= 0) {
-                lastWritingSlice = slice.next;
-                continue;
-            }
-
-            Ipc::Mem::PageId page;
-            slice.next = lastWritingSlice = reserveSapForWriting(page);
-            extras->items[lastWritingSlice].page = page;
-            debugs(20, 7, "entry " << index << " new slice: " << lastWritingSlice);
-        }
-
-        copyToShmSlice(e, anchor);
+        Ipc::StoreMap::Slice &slice = nextAppendableSlice(
+                                          e.mem_obj->memCache.index, lastWritingSlice);
+        if (anchor.start < 0)
+            anchor.start = lastWritingSlice;
+        copyToShmSlice(e, anchor, slice);
     }
 
     debugs(20, 7, "mem-cached available " << eSize << " bytes of " << e);
@@ -544,13 +720,9 @@
 
 /// copies at most one slice worth of local memory to shared memory
 void
-MemStore::copyToShmSlice(StoreEntry &e, Ipc::StoreMapAnchor &anchor)
+MemStore::copyToShmSlice(StoreEntry &e, Ipc::StoreMapAnchor &anchor, Ipc::StoreMap::Slice &slice)
 {
-    Ipc::StoreMap::Slice &slice =
-        map->writeableSlice(e.mem_obj->memCache.index, lastWritingSlice);
-
-    Ipc::Mem::PageId page = extras->items[lastWritingSlice].page;
-    assert(lastWritingSlice >= 0 && page);
+    Ipc::Mem::PageId page = pageForSlice(lastWritingSlice);
     debugs(20, 7, "entry " << e << " slice " << lastWritingSlice << " has " <<
            page);
 
@@ -576,6 +748,53 @@
     anchor.basics.swap_file_sz = e.mem_obj->memCache.offset;
 }
 
+/// starts checking with the entry chain slice at a given offset and
+/// returns a not-full (but not necessarily empty) slice, updating sliceOffset
+Ipc::StoreMap::Slice &
+MemStore::nextAppendableSlice(const sfileno fileNo, sfileno &sliceOffset)
+{
+    // allocate the very first slot for the entry if needed
+    if (sliceOffset < 0) {
+        Ipc::StoreMapAnchor &anchor = map->writeableEntry(fileNo);
+        Must(anchor.start < 0);
+        Ipc::Mem::PageId page;
+        sliceOffset = reserveSapForWriting(page); // throws
+        extras->items[sliceOffset].page = page;
+        anchor.start = sliceOffset;
+    }
+
+    const size_t sliceCapacity = Ipc::Mem::PageSize();
+    do {
+        Ipc::StoreMap::Slice &slice = map->writeableSlice(fileNo, sliceOffset);
+
+        if (slice.size >= sliceCapacity) {
+            if (slice.next >= 0) {
+                sliceOffset = slice.next;
+                continue;
+            }
+
+            Ipc::Mem::PageId page;
+            slice.next = sliceOffset = reserveSapForWriting(page);
+            extras->items[sliceOffset].page = page;
+            debugs(20, 7, "entry " << fileNo << " new slice: " << sliceOffset);
+        }
+
+        return slice;
+    } while (true);
+    /* not reached */
+}
+
+/// safely returns a previously allocated memory page for the given entry slice
+Ipc::Mem::PageId
+MemStore::pageForSlice(Ipc::StoreMapSliceId sliceId)
+{
+    Must(extras);
+    Must(sliceId >= 0);
+    Ipc::Mem::PageId page = extras->items[sliceId].page;
+    Must(page);
+    return page;
+}
+
 /// finds a slot and a free page to fill or throws
 sfileno
 MemStore::reserveSapForWriting(Ipc::Mem::PageId &page)
diff -u -r -N squid-4.0.7/src/MemStore.h squid-4.0.8/src/MemStore.h
--- squid-4.0.7/src/MemStore.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/MemStore.h	2016-04-02 10:04:07.000000000 +1300
@@ -22,6 +22,8 @@
 typedef Ipc::StoreMapItems<MemStoreMapExtraItem> MemStoreMapExtras;
 typedef Ipc::StoreMap MemStoreMap;
 
+class ShmWriter;
+
 /// Stores HTTP entities in RAM. Current implementation uses shared memory.
 /// Unlike a disk store (SwapDir), operations are synchronous (and fast).
 class MemStore: public Store::Controlled, public Ipc::StoreMapCleaner
@@ -55,6 +57,7 @@
     virtual void stat(StoreEntry &e) const override;
     virtual void reference(StoreEntry &e) override;
     virtual bool dereference(StoreEntry &e) override;
+    virtual void updateHeaders(StoreEntry *e) override;
     virtual void maintain() override;
     virtual bool anchorCollapsed(StoreEntry &e, bool &inSync) override;
     virtual bool updateCollapsed(StoreEntry &e) override;
@@ -64,17 +67,23 @@
     static int64_t EntryLimit();
 
 protected:
+    friend ShmWriter;
+
     bool shouldCache(StoreEntry &e) const;
     bool startCaching(StoreEntry &e);
 
     void copyToShm(StoreEntry &e);
-    void copyToShmSlice(StoreEntry &e, Ipc::StoreMapAnchor &anchor);
+    void copyToShmSlice(StoreEntry &e, Ipc::StoreMapAnchor &anchor, Ipc::StoreMap::Slice &slice);
     bool copyFromShm(StoreEntry &e, const sfileno index, const Ipc::StoreMapAnchor &anchor);
     bool copyFromShmSlice(StoreEntry &e, const StoreIOBuffer &buf, bool eof);
 
+    void updateHeadersOrThrow(Ipc::StoreMapUpdate &update);
+
     void anchorEntry(StoreEntry &e, const sfileno index, const Ipc::StoreMapAnchor &anchor);
     bool updateCollapsedWith(StoreEntry &collapsed, const sfileno index, const Ipc::StoreMapAnchor &anchor);
 
+    Ipc::Mem::PageId pageForSlice(Ipc::StoreMapSliceId sliceId);
+    Ipc::StoreMap::Slice &nextAppendableSlice(const sfileno entryIndex, sfileno &sliceOffset);
     sfileno reserveSapForWriting(Ipc::Mem::PageId &page);
 
     // Ipc::StoreMapCleaner API
diff -u -r -N squid-4.0.7/src/mgr/ActionParams.cc squid-4.0.8/src/mgr/ActionParams.cc
--- squid-4.0.7/src/mgr/ActionParams.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/mgr/ActionParams.cc	2016-04-02 10:04:07.000000000 +1300
@@ -12,6 +12,7 @@
 #include "base/TextException.h"
 #include "ipc/TypedMsgHdr.h"
 #include "mgr/ActionParams.h"
+#include "sbuf/StringConvert.h"
 
 Mgr::ActionParams::ActionParams(): httpMethod(Http::METHOD_NONE)
 {
@@ -38,7 +39,7 @@
 Mgr::ActionParams::pack(Ipc::TypedMsgHdr &msg) const
 {
     msg.putString(httpUri);
-    String foo(httpMethod.image().toString());
+    auto foo = SBufToString(httpMethod.image());
     msg.putString(foo);
     msg.putPod(httpFlags);
     msg.putString(httpOrigin);
diff -u -r -N squid-4.0.7/src/mgr/Makefile.in squid-4.0.8/src/mgr/Makefile.in
--- squid-4.0.7/src/mgr/Makefile.in	2016-02-24 06:49:40.000000000 +1300
+++ squid-4.0.8/src/mgr/Makefile.in	2016-04-02 10:07:53.000000000 +1300
@@ -690,6 +690,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/mk-string-arrays.awk squid-4.0.8/src/mk-string-arrays.awk
--- squid-4.0.7/src/mk-string-arrays.awk	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/mk-string-arrays.awk	2016-04-02 10:04:07.000000000 +1300
@@ -73,10 +73,10 @@
 }
 
 END {
-	if (sbuf) print "#include \"SBuf.h\""
+	if (sbuf) print "#include \"sbuf/SBuf.h\""
 	print "#include \"" nspath type ".h\""
 
-	# if namesapce is not empty ??
+	# if namespace is not empty ??
 	if (namespace) print "namespace " namespace
 	if (namespace) print "{"
 
diff -u -r -N squid-4.0.7/src/OutOfBoundsException.h squid-4.0.8/src/OutOfBoundsException.h
--- squid-4.0.7/src/OutOfBoundsException.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/OutOfBoundsException.h	1970-01-01 12:00:00.000000000 +1200
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-#ifndef _SQUID_SRC_OUTOFBOUNDSEXCEPTION_H
-#define _SQUID_SRC_OUTOFBOUNDSEXCEPTION_H
-
-#include "base/TextException.h"
-#include "SBuf.h"
-
-/**
- * Exception raised when the user is going out of bounds when accessing
- * a char within the SBuf
- */
-class OutOfBoundsException : public TextException
-{
-public:
-    OutOfBoundsException(const SBuf &buf, SBuf::size_type &pos, const char *aFileName = 0, int aLineNo = -1);
-    virtual ~OutOfBoundsException() throw();
-
-protected:
-    SBuf theThrowingBuf;
-    SBuf::size_type accessedPosition;
-};
-
-#endif /* _SQUID_SRC_OUTOFBOUNDSEXCEPTION_H */
-
diff -u -r -N squid-4.0.7/src/parser/Makefile.in squid-4.0.8/src/parser/Makefile.in
--- squid-4.0.7/src/parser/Makefile.in	2016-02-24 06:49:41.000000000 +1300
+++ squid-4.0.8/src/parser/Makefile.in	2016-04-02 10:07:54.000000000 +1300
@@ -685,6 +685,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/parser/Tokenizer.h squid-4.0.8/src/parser/Tokenizer.h
--- squid-4.0.7/src/parser/Tokenizer.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/parser/Tokenizer.h	2016-04-02 10:04:07.000000000 +1300
@@ -10,7 +10,7 @@
 #define SQUID_PARSER_TOKENIZER_H_
 
 #include "base/CharacterSet.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 /// Generic protocol-agnostic parsing tools
 namespace Parser
diff -u -r -N squid-4.0.7/src/peer_digest.cc squid-4.0.8/src/peer_digest.cc
--- squid-4.0.7/src/peer_digest.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/peer_digest.cc	2016-04-02 10:04:07.000000000 +1300
@@ -537,11 +537,7 @@
 
             assert(fetch->old_entry->mem_obj->request);
 
-            HttpReply *old_rep = (HttpReply *) fetch->old_entry->getReply();
-
-            old_rep->updateOnNotModified(reply);
-
-            fetch->old_entry->timestampsSet();
+            Store::Root().updateOnNotModified(fetch->old_entry, *fetch->entry);
 
             /* get rid of 304 reply */
             storeUnregister(fetch->sc, fetch->entry, fetch);
diff -u -r -N squid-4.0.7/src/redirect.cc squid-4.0.8/src/redirect.cc
--- squid-4.0.7/src/redirect.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/redirect.cc	2016-04-02 10:04:07.000000000 +1300
@@ -25,7 +25,7 @@
 #include "mgr/Registration.h"
 #include "redirect.h"
 #include "rfc1738.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "SquidConfig.h"
 #include "Store.h"
 #if USE_AUTH
diff -u -r -N squid-4.0.7/src/repl/Makefile.in squid-4.0.8/src/repl/Makefile.in
--- squid-4.0.7/src/repl/Makefile.in	2016-02-24 06:49:41.000000000 +1300
+++ squid-4.0.8/src/repl/Makefile.in	2016-04-02 10:07:55.000000000 +1300
@@ -696,6 +696,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/sbuf/Algorithms.cc squid-4.0.8/src/sbuf/Algorithms.cc
--- squid-4.0.7/src/sbuf/Algorithms.cc	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/Algorithms.cc	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "sbuf/Algorithms.h"
+
+// private common implementation for SBuf hash variants
+static std::size_t
+SBufHashCommon_ (const SBuf & sbuf, bool caseInsensitive) noexcept
+{
+    //ripped and adapted from hash_string
+    const char *s = sbuf.rawContent();
+    size_t rv = 0;
+    SBuf::size_type len=sbuf.length();
+    while (len != 0) {
+        rv ^= 271 * (caseInsensitive? xtolower(*s) : *s);
+        ++s;
+        --len;
+    }
+    return rv ^ (sbuf.length() * 271);
+}
+
+std::size_t
+std::hash<SBuf>::operator() (const SBuf & sbuf) const noexcept
+{
+    return SBufHashCommon_(sbuf, false);
+}
+
+std::size_t
+CaseInsensitiveSBufHash::operator() (const SBuf & sbuf) const noexcept
+{
+    return SBufHashCommon_(sbuf, true);
+}
+
diff -u -r -N squid-4.0.7/src/sbuf/Algorithms.h squid-4.0.8/src/sbuf/Algorithms.h
--- squid-4.0.7/src/sbuf/Algorithms.h	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/Algorithms.h	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SBUFALGOS_H_
+#define SQUID_SBUFALGOS_H_
+
+#include "sbuf/SBuf.h"
+
+#include <algorithm>
+#include <numeric>
+
+/// SBuf equality predicate for STL algorithms etc
+class SBufEqual
+{
+public:
+    explicit SBufEqual(const SBuf &reference, SBufCaseSensitive sensitivity = caseSensitive) :
+        reference_(reference), sensitivity_(sensitivity) {}
+    bool operator() (const SBuf & checking) { return checking.compare(reference_,sensitivity_) == 0; }
+private:
+    SBuf reference_;
+    SBufCaseSensitive sensitivity_;
+};
+
+/// SBuf "starts with" predicate for STL algorithms etc
+class SBufStartsWith
+{
+public:
+    explicit SBufStartsWith(const SBuf &prefix, SBufCaseSensitive sensitivity = caseSensitive) :
+        prefix_(prefix), sensitivity_(sensitivity) {}
+    bool operator() (const SBuf & checking) { return checking.startsWith(prefix_,sensitivity_); }
+private:
+    SBuf prefix_;
+    SBufCaseSensitive sensitivity_;
+};
+
+/** SBuf size addition accumulator for STL contaniners
+ *
+ * Equivalent to prefix_length +  SBuf.length() +  separator.length()
+ */
+class SBufAddLength
+{
+public:
+    explicit SBufAddLength(const SBuf &separator) :
+        separatorLen_(separator.length()) {}
+    SBuf::size_type operator()(const SBuf::size_type sz, const SBuf & item) {
+        return sz + item.length() + separatorLen_;
+    }
+private:
+    SBuf::size_type separatorLen_;
+};
+
+/// join all the SBuf in a container of SBuf into a single SBuf, separating with separator
+template <class Container>
+SBuf
+SBufContainerJoin(const Container &items, const SBuf& separator)
+{
+    // optimization: pre-calculate needed storage
+    const SBuf::size_type sz = std::accumulate(items.begin(), items.end(), 0, SBufAddLength(separator));
+
+    // sz can be zero in two cases: either items is empty, or all items
+    //  are zero-length. In the former case, we must protect against
+    //  dereferencing the iterator later on, and checking sz is more efficient
+    //  than checking items.size(). This check also provides an optimization
+    //  for the latter case without adding complexity.
+    if (sz == 0)
+        return SBuf();
+
+    SBuf rv;
+    rv.reserveSpace(sz);
+
+    typename Container::const_iterator i(items.begin());
+    rv.append(*i);
+    ++i;
+    for (; i != items.end(); ++i)
+        rv.append(separator).append(*i);
+    return rv;
+}
+
+namespace std {
+/// default hash functor to support std::unordered_map<SBuf,*>
+template <>
+struct hash<SBuf>
+{
+    size_t operator()(const SBuf &) const noexcept;
+};
+}
+
+/** hash functor for SBufs, meant so support case-insensitive std::unordered_map
+ *
+ * Typical use:
+ * \code
+ * auto m = std::unordered_map<SBuf, ValueType, CaseInsensitiveSBufHash>();
+ * \endcode
+ */
+class CaseInsensitiveSBufHash
+{
+public:
+    std::size_t operator()(const SBuf &) const noexcept;
+};
+
+#endif /* SQUID_SBUFALGOS_H_ */
+
diff -u -r -N squid-4.0.7/src/sbuf/DetailedStats.cc squid-4.0.8/src/sbuf/DetailedStats.cc
--- squid-4.0.7/src/sbuf/DetailedStats.cc	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/DetailedStats.cc	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "sbuf/DetailedStats.h"
+#include "StatHist.h"
+
+/*
+ * Implementation note: the purpose of this construct is to avoid adding
+ * external dependencies to the SBuf code
+ */
+
+static StatHist sbufDestructTimeStats;
+static StatHist memblobDestructTimeStats;
+
+namespace SBufDetailedStatsHistInitializer
+{
+// run the post-instantiation initialization methods for StatHist objects
+struct Initializer {
+    Initializer() {
+        sbufDestructTimeStats.logInit(100,30.0,128000.0);
+        memblobDestructTimeStats.logInit(100,30.0,128000.0);
+    }
+};
+Initializer initializer;
+}
+
+void
+recordSBufSizeAtDestruct(SBuf::size_type sz)
+{
+    sbufDestructTimeStats.count(static_cast<double>(sz));
+}
+
+const StatHist *
+collectSBufDestructTimeStats()
+{
+    return &sbufDestructTimeStats;
+}
+
+void
+recordMemBlobSizeAtDestruct(SBuf::size_type sz)
+{
+    memblobDestructTimeStats.count(static_cast<double>(sz));
+}
+
+const StatHist *
+collectMemBlobDestructTimeStats()
+{
+    return &memblobDestructTimeStats;
+}
+
diff -u -r -N squid-4.0.7/src/sbuf/DetailedStats.h squid-4.0.8/src/sbuf/DetailedStats.h
--- squid-4.0.7/src/sbuf/DetailedStats.h	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/DetailedStats.h	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SBUFDETAILEDSTATS_H
+#define SQUID_SBUFDETAILEDSTATS_H
+
+#include "sbuf/SBuf.h"
+
+class StatHist;
+
+/// Record the size a SBuf had when it was destructed
+void recordSBufSizeAtDestruct(SBuf::size_type sz);
+
+/** Collect the SBuf size-at-destruct-time histogram
+ *
+ * \note the returned StatHist object must not be freed
+ */
+const StatHist * collectSBufDestructTimeStats();
+
+/// Record the size a MemBlob had when it was destructed
+void recordMemBlobSizeAtDestruct(MemBlob::size_type sz);
+
+/** Collect the MemBlob size-at-destruct-time histogram
+ *
+ * \note the returned StatHist object must not be freed
+ */
+const StatHist * collectMemBlobDestructTimeStats();
+
+#endif /* SQUID_SBUFDETAILEDSTATS_H */
+
diff -u -r -N squid-4.0.7/src/sbuf/Exceptions.cc squid-4.0.8/src/sbuf/Exceptions.cc
--- squid-4.0.7/src/sbuf/Exceptions.cc	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/Exceptions.cc	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "sbuf/Exceptions.h"
+#include "sbuf/OutOfBoundsException.h"
+#include "sbuf/SBuf.h"
+
+OutOfBoundsException::OutOfBoundsException(const SBuf &throwingBuf,
+        SBuf::size_type &pos,
+        const char *aFileName, int aLineNo)
+    : TextException(NULL, aFileName, aLineNo),
+      theThrowingBuf(throwingBuf),
+      accessedPosition(pos)
+{
+    SBuf explanatoryText("OutOfBoundsException");
+    if (aLineNo != -1)
+        explanatoryText.appendf(" at line %d", aLineNo);
+    if (aFileName != NULL)
+        explanatoryText.appendf(" in file %s", aFileName);
+    explanatoryText.appendf(" while accessing position %d in a SBuf long %d",
+                            pos, throwingBuf.length());
+    // we can safely alias c_str as both are local to the object
+    //  and will not further manipulated.
+    message = xstrndup(explanatoryText.c_str(),explanatoryText.length());
+}
+
+OutOfBoundsException::~OutOfBoundsException() throw()
+{ }
+
+InvalidParamException::InvalidParamException(const char *aFilename, int aLineNo)
+    : TextException("Invalid parameter", aFilename, aLineNo)
+{ }
+
+SBufTooBigException::SBufTooBigException(const char *aFilename, int aLineNo)
+    : TextException("Trying to create an oversize SBuf", aFilename, aLineNo)
+{ }
+
diff -u -r -N squid-4.0.7/src/sbuf/Exceptions.h squid-4.0.8/src/sbuf/Exceptions.h
--- squid-4.0.7/src/sbuf/Exceptions.h	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/Exceptions.h	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SBUFEXCEPTIONS_H
+#define SQUID_SBUFEXCEPTIONS_H
+
+#include "base/TextException.h"
+
+/**
+ * Exception raised when call parameters are not valid
+ * \todo move to an Exceptions.h?
+ */
+class InvalidParamException : public TextException
+{
+public:
+    explicit InvalidParamException(const char *aFilename = 0, int aLineNo = -1);
+};
+
+/**
+ * Exception raised when an attempt to resize a SBuf would cause it to reserve too big
+ */
+class SBufTooBigException : public TextException
+{
+public:
+    explicit SBufTooBigException(const char *aFilename = 0, int aLineNo = -1);
+};
+
+#endif /* SQUID_SBUFEXCEPTIONS_H */
+
diff -u -r -N squid-4.0.7/src/sbuf/forward.h squid-4.0.8/src/sbuf/forward.h
--- squid-4.0.7/src/sbuf/forward.h	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/forward.h	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SRC_SBUF_FORWARD_H
+#define SQUID_SRC_SBUF_FORWARD_H
+
+#include <functional>
+#include <list>
+
+class MemBlob;
+
+class SBuf;
+class SBufIterator;
+class SBufReverseIterator;
+
+class OutOfBoundsException;
+class InvalidParamException;
+class SBufTooBigException;
+
+class SBufStats;
+typedef std::list<SBuf> SBufList;
+
+class SBufEqual;
+class SBufStartsWith;
+class SBufAddLength;
+namespace std {
+template <> struct hash<SBuf>;
+}
+class CaseInsensitiveSBufHash;
+
+#endif /* SQUID_SRC_SBUF_FORWARD_H */
+
diff -u -r -N squid-4.0.7/src/sbuf/List.cc squid-4.0.8/src/sbuf/List.cc
--- squid-4.0.7/src/sbuf/List.cc	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/List.cc	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "sbuf/Algorithms.h"
+#include "sbuf/List.h"
+
+bool
+IsMember(const SBufList & sl, const SBuf &S, const SBufCaseSensitive case_sensitive)
+{
+    return std::find_if(sl.begin(), sl.end(), SBufEqual(S,case_sensitive)) != sl.end();
+}
+
diff -u -r -N squid-4.0.7/src/sbuf/List.h squid-4.0.8/src/sbuf/List.h
--- squid-4.0.7/src/sbuf/List.h	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/List.h	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SBUFLIST_H
+#define SQUID_SBUFLIST_H
+
+#include "sbuf/SBuf.h"
+
+#include <list>
+
+typedef std::list<SBuf> SBufList;
+
+/** check for membership
+ *
+ * \return true if the supplied SBuf is a member of the list
+ * \param case_sensitive one of caseSensitive or caseInsensitive
+ */
+bool IsMember(const SBufList &, const SBuf &, const SBufCaseSensitive isCaseSensitive = caseSensitive);
+
+#endif /* SQUID_SBUFLIST_H */
+
diff -u -r -N squid-4.0.7/src/sbuf/Makefile.am squid-4.0.8/src/sbuf/Makefile.am
--- squid-4.0.7/src/sbuf/Makefile.am	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/Makefile.am	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,30 @@
+## Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+##
+## Squid software is distributed under GPLv2+ license and includes
+## contributions from numerous individuals and organizations.
+## Please see the COPYING and CONTRIBUTORS files for details.
+##
+
+include $(top_srcdir)/src/Common.am
+include $(top_srcdir)/src/TestHeaders.am
+
+noinst_LTLIBRARIES = libsbuf.la
+
+libsbuf_la_SOURCES = \
+	Algorithms.cc \
+	Algorithms.h \
+	DetailedStats.cc \
+	DetailedStats.h \
+	Exceptions.cc \
+	Exceptions.h \
+	forward.h \
+	List.cc \
+	List.h \
+	MemBlob.cc \
+	MemBlob.h \
+	OutOfBoundsException.h \
+	SBuf.cc \
+	SBuf.h \
+	Stats.cc \
+	Stats.h \
+	Stream.h
diff -u -r -N squid-4.0.7/src/sbuf/Makefile.in squid-4.0.8/src/sbuf/Makefile.in
--- squid-4.0.7/src/sbuf/Makefile.in	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/Makefile.in	2016-04-02 10:07:57.000000000 +1300
@@ -0,0 +1,1227 @@
+# Makefile.in generated by automake 1.15 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994-2014 Free Software Foundation, Inc.
+
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+am__is_gnu_make = { \
+  if test -z '$(MAKELEVEL)'; then \
+    false; \
+  elif test -n '$(MAKE_HOST)'; then \
+    true; \
+  elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
+    true; \
+  else \
+    false; \
+  fi; \
+}
+am__make_running_with_option = \
+  case $${target_option-} in \
+      ?) ;; \
+      *) echo "am__make_running_with_option: internal error: invalid" \
+              "target option '$${target_option-}' specified" >&2; \
+         exit 1;; \
+  esac; \
+  has_opt=no; \
+  sane_makeflags=$$MAKEFLAGS; \
+  if $(am__is_gnu_make); then \
+    sane_makeflags=$$MFLAGS; \
+  else \
+    case $$MAKEFLAGS in \
+      *\\[\ \	]*) \
+        bs=\\; \
+        sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
+          | sed "s/$$bs$$bs[$$bs $$bs	]*//g"`;; \
+    esac; \
+  fi; \
+  skip_next=no; \
+  strip_trailopt () \
+  { \
+    flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
+  }; \
+  for flg in $$sane_makeflags; do \
+    test $$skip_next = yes && { skip_next=no; continue; }; \
+    case $$flg in \
+      *=*|--*) continue;; \
+        -*I) strip_trailopt 'I'; skip_next=yes;; \
+      -*I?*) strip_trailopt 'I';; \
+        -*O) strip_trailopt 'O'; skip_next=yes;; \
+      -*O?*) strip_trailopt 'O';; \
+        -*l) strip_trailopt 'l'; skip_next=yes;; \
+      -*l?*) strip_trailopt 'l';; \
+      -[dEDm]) skip_next=yes;; \
+      -[JT]) skip_next=yes;; \
+    esac; \
+    case $$flg in \
+      *$$target_option*) has_opt=yes; break;; \
+    esac; \
+  done; \
+  test $$has_opt = yes
+am__make_dryrun = (target_option=n; $(am__make_running_with_option))
+am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+check_PROGRAMS =
+@ENABLE_LOADABLE_MODULES_TRUE@am__append_1 = $(INCLTDL)
+subdir = src/sbuf
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/acinclude/ax_with_prog.m4 \
+	$(top_srcdir)/acinclude/init.m4 \
+	$(top_srcdir)/acinclude/squid-util.m4 \
+	$(top_srcdir)/acinclude/compiler-flags.m4 \
+	$(top_srcdir)/acinclude/os-deps.m4 \
+	$(top_srcdir)/acinclude/krb5.m4 $(top_srcdir)/acinclude/pam.m4 \
+	$(top_srcdir)/acinclude/pkg.m4 \
+	$(top_srcdir)/acinclude/lib-checks.m4 \
+	$(top_srcdir)/acinclude/ax_cxx_compile_stdcxx_11.m4 \
+	$(top_srcdir)/acinclude/ax_cxx_0x_types.m4 \
+	$(top_srcdir)/src/auth/basic/helpers.m4 \
+	$(top_srcdir)/src/auth/basic/DB/required.m4 \
+	$(top_srcdir)/src/auth/basic/LDAP/required.m4 \
+	$(top_srcdir)/src/auth/basic/NCSA/required.m4 \
+	$(top_srcdir)/src/auth/basic/NIS/required.m4 \
+	$(top_srcdir)/src/auth/basic/PAM/required.m4 \
+	$(top_srcdir)/src/auth/basic/POP3/required.m4 \
+	$(top_srcdir)/src/auth/basic/RADIUS/required.m4 \
+	$(top_srcdir)/src/auth/basic/SASL/required.m4 \
+	$(top_srcdir)/src/auth/basic/SMB/required.m4 \
+	$(top_srcdir)/src/auth/basic/SMB_LM/required.m4 \
+	$(top_srcdir)/src/auth/basic/SSPI/required.m4 \
+	$(top_srcdir)/src/auth/basic/fake/required.m4 \
+	$(top_srcdir)/src/auth/basic/getpwnam/required.m4 \
+	$(top_srcdir)/src/auth/digest/helpers.m4 \
+	$(top_srcdir)/src/auth/digest/eDirectory/required.m4 \
+	$(top_srcdir)/src/auth/digest/file/required.m4 \
+	$(top_srcdir)/src/auth/digest/LDAP/required.m4 \
+	$(top_srcdir)/src/auth/negotiate/helpers.m4 \
+	$(top_srcdir)/src/auth/negotiate/SSPI/required.m4 \
+	$(top_srcdir)/src/auth/negotiate/kerberos/required.m4 \
+	$(top_srcdir)/src/auth/negotiate/wrapper/required.m4 \
+	$(top_srcdir)/src/auth/ntlm/helpers.m4 \
+	$(top_srcdir)/src/auth/ntlm/fake/required.m4 \
+	$(top_srcdir)/src/auth/ntlm/SMB_LM/required.m4 \
+	$(top_srcdir)/src/auth/ntlm/SSPI/required.m4 \
+	$(top_srcdir)/src/log/helpers.m4 \
+	$(top_srcdir)/src/log/DB/required.m4 \
+	$(top_srcdir)/src/log/file/required.m4 \
+	$(top_srcdir)/src/acl/external/helpers.m4 \
+	$(top_srcdir)/src/acl/external/AD_group/required.m4 \
+	$(top_srcdir)/src/acl/external/LDAP_group/required.m4 \
+	$(top_srcdir)/src/acl/external/LM_group/required.m4 \
+	$(top_srcdir)/src/acl/external/delayer/required.m4 \
+	$(top_srcdir)/src/acl/external/SQL_session/required.m4 \
+	$(top_srcdir)/src/acl/external/eDirectory_userip/required.m4 \
+	$(top_srcdir)/src/acl/external/file_userip/required.m4 \
+	$(top_srcdir)/src/acl/external/kerberos_ldap_group/required.m4 \
+	$(top_srcdir)/src/acl/external/session/required.m4 \
+	$(top_srcdir)/src/acl/external/time_quota/required.m4 \
+	$(top_srcdir)/src/acl/external/unix_group/required.m4 \
+	$(top_srcdir)/src/acl/external/wbinfo_group/required.m4 \
+	$(top_srcdir)/src/http/url_rewriters/helpers.m4 \
+	$(top_srcdir)/src/http/url_rewriters/fake/required.m4 \
+	$(top_srcdir)/src/http/url_rewriters/LFS/required.m4 \
+	$(top_srcdir)/src/security/cert_validators/helpers.m4 \
+	$(top_srcdir)/src/security/cert_validators/fake/required.m4 \
+	$(top_srcdir)/src/security/cert_generators/helpers.m4 \
+	$(top_srcdir)/src/security/cert_generators/file/required.m4 \
+	$(top_srcdir)/src/store/id_rewriters/helpers.m4 \
+	$(top_srcdir)/src/store/id_rewriters/file/required.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/include/autoconf.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+LTLIBRARIES = $(noinst_LTLIBRARIES)
+libsbuf_la_LIBADD =
+am_libsbuf_la_OBJECTS = Algorithms.lo DetailedStats.lo Exceptions.lo \
+	List.lo MemBlob.lo SBuf.lo Stats.lo
+libsbuf_la_OBJECTS = $(am_libsbuf_la_OBJECTS)
+AM_V_lt = $(am__v_lt_@AM_V@)
+am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
+am__v_lt_0 = --silent
+am__v_lt_1 = 
+AM_V_P = $(am__v_P_@AM_V@)
+am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
+am__v_P_0 = false
+am__v_P_1 = :
+AM_V_GEN = $(am__v_GEN_@AM_V@)
+am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
+am__v_GEN_0 = @echo "  GEN     " $@;
+am__v_GEN_1 = 
+AM_V_at = $(am__v_at_@AM_V@)
+am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
+am__v_at_0 = @
+am__v_at_1 = 
+DEFAULT_INCLUDES = 
+depcomp = $(SHELL) $(top_srcdir)/cfgaux/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
+LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \
+	$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+	$(AM_CXXFLAGS) $(CXXFLAGS)
+AM_V_CXX = $(am__v_CXX_@AM_V@)
+am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@)
+am__v_CXX_0 = @echo "  CXX     " $@;
+am__v_CXX_1 = 
+CXXLD = $(CXX)
+CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
+	$(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CXXLD = $(am__v_CXXLD_@AM_V@)
+am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
+am__v_CXXLD_0 = @echo "  CXXLD   " $@;
+am__v_CXXLD_1 = 
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+	$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+	$(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_@AM_V@)
+am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
+am__v_CC_0 = @echo "  CC      " $@;
+am__v_CC_1 = 
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_@AM_V@)
+am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
+am__v_CCLD_0 = @echo "  CCLD    " $@;
+am__v_CCLD_1 = 
+SOURCES = $(libsbuf_la_SOURCES)
+DIST_SOURCES = $(libsbuf_la_SOURCES)
+am__can_run_installinfo = \
+  case $$AM_UPDATE_INFO_DIR in \
+    n|no|NO) false;; \
+    *) (install-info --version) >/dev/null 2>&1;; \
+  esac
+am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
+# Read a list of newline-separated strings from the standard input,
+# and print each of them once, without duplicates.  Input order is
+# *not* preserved.
+am__uniquify_input = $(AWK) '\
+  BEGIN { nonempty = 0; } \
+  { items[$$0] = 1; nonempty = 1; } \
+  END { if (nonempty) { for (i in items) print i; }; } \
+'
+# Make sure the list of sources is unique.  This is necessary because,
+# e.g., the same source file might be shared among _SOURCES variables
+# for different programs/libraries.
+am__define_uniq_tagged_files = \
+  list='$(am__tagged_files)'; \
+  unique=`for i in $$list; do \
+    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+  done | $(am__uniquify_input)`
+ETAGS = etags
+CTAGS = ctags
+am__tty_colors_dummy = \
+  mgn= red= grn= lgn= blu= brg= std=; \
+  am__color_tests=no
+am__tty_colors = { \
+  $(am__tty_colors_dummy); \
+  if test "X$(AM_COLOR_TESTS)" = Xno; then \
+    am__color_tests=no; \
+  elif test "X$(AM_COLOR_TESTS)" = Xalways; then \
+    am__color_tests=yes; \
+  elif test "X$$TERM" != Xdumb && { test -t 1; } 2>/dev/null; then \
+    am__color_tests=yes; \
+  fi; \
+  if test $$am__color_tests = yes; then \
+    red='[0;31m'; \
+    grn='[0;32m'; \
+    lgn='[1;32m'; \
+    blu='[1;34m'; \
+    mgn='[0;35m'; \
+    brg='[1m'; \
+    std='[m'; \
+  fi; \
+}
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+  for p in $$list; do echo "$$p $$p"; done | \
+  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+    if (++n[$$2] == $(am__install_max)) \
+      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+    END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__uninstall_files_from_dir = { \
+  test -z "$$files" \
+    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
+    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
+         $(am__cd) "$$dir" && rm -f $$files; }; \
+  }
+am__recheck_rx = ^[ 	]*:recheck:[ 	]*
+am__global_test_result_rx = ^[ 	]*:global-test-result:[ 	]*
+am__copy_in_global_log_rx = ^[ 	]*:copy-in-global-log:[ 	]*
+# A command that, given a newline-separated list of test names on the
+# standard input, print the name of the tests that are to be re-run
+# upon "make recheck".
+am__list_recheck_tests = $(AWK) '{ \
+  recheck = 1; \
+  while ((rc = (getline line < ($$0 ".trs"))) != 0) \
+    { \
+      if (rc < 0) \
+        { \
+          if ((getline line2 < ($$0 ".log")) < 0) \
+	    recheck = 0; \
+          break; \
+        } \
+      else if (line ~ /$(am__recheck_rx)[nN][Oo]/) \
+        { \
+          recheck = 0; \
+          break; \
+        } \
+      else if (line ~ /$(am__recheck_rx)[yY][eE][sS]/) \
+        { \
+          break; \
+        } \
+    }; \
+  if (recheck) \
+    print $$0; \
+  close ($$0 ".trs"); \
+  close ($$0 ".log"); \
+}'
+# A command that, given a newline-separated list of test names on the
+# standard input, create the global log from their .trs and .log files.
+am__create_global_log = $(AWK) ' \
+function fatal(msg) \
+{ \
+  print "fatal: making $@: " msg | "cat >&2"; \
+  exit 1; \
+} \
+function rst_section(header) \
+{ \
+  print header; \
+  len = length(header); \
+  for (i = 1; i <= len; i = i + 1) \
+    printf "="; \
+  printf "\n\n"; \
+} \
+{ \
+  copy_in_global_log = 1; \
+  global_test_result = "RUN"; \
+  while ((rc = (getline line < ($$0 ".trs"))) != 0) \
+    { \
+      if (rc < 0) \
+         fatal("failed to read from " $$0 ".trs"); \
+      if (line ~ /$(am__global_test_result_rx)/) \
+        { \
+          sub("$(am__global_test_result_rx)", "", line); \
+          sub("[ 	]*$$", "", line); \
+          global_test_result = line; \
+        } \
+      else if (line ~ /$(am__copy_in_global_log_rx)[nN][oO]/) \
+        copy_in_global_log = 0; \
+    }; \
+  if (copy_in_global_log) \
+    { \
+      rst_section(global_test_result ": " $$0); \
+      while ((rc = (getline line < ($$0 ".log"))) != 0) \
+      { \
+        if (rc < 0) \
+          fatal("failed to read from " $$0 ".log"); \
+        print line; \
+      }; \
+      printf "\n"; \
+    }; \
+  close ($$0 ".trs"); \
+  close ($$0 ".log"); \
+}'
+# Restructured Text title.
+am__rst_title = { sed 's/.*/   &   /;h;s/./=/g;p;x;s/ *$$//;p;g' && echo; }
+# Solaris 10 'make', and several other traditional 'make' implementations,
+# pass "-e" to $(SHELL), and POSIX 2008 even requires this.  Work around it
+# by disabling -e (using the XSI extension "set +e") if it's set.
+am__sh_e_setup = case $$- in *e*) set +e;; esac
+# Default flags passed to test drivers.
+am__common_driver_flags = \
+  --color-tests "$$am__color_tests" \
+  --enable-hard-errors "$$am__enable_hard_errors" \
+  --expect-failure "$$am__expect_failure"
+# To be inserted before the command running the test.  Creates the
+# directory for the log if needed.  Stores in $dir the directory
+# containing $f, in $tst the test, in $log the log.  Executes the
+# developer- defined test setup AM_TESTS_ENVIRONMENT (if any), and
+# passes TESTS_ENVIRONMENT.  Set up options for the wrapper that
+# will run the test scripts (or their associated LOG_COMPILER, if
+# thy have one).
+am__check_pre = \
+$(am__sh_e_setup);					\
+$(am__vpath_adj_setup) $(am__vpath_adj)			\
+$(am__tty_colors);					\
+srcdir=$(srcdir); export srcdir;			\
+case "$@" in						\
+  */*) am__odir=`echo "./$@" | sed 's|/[^/]*$$||'`;;	\
+    *) am__odir=.;; 					\
+esac;							\
+test "x$$am__odir" = x"." || test -d "$$am__odir" 	\
+  || $(MKDIR_P) "$$am__odir" || exit $$?;		\
+if test -f "./$$f"; then dir=./;			\
+elif test -f "$$f"; then dir=;				\
+else dir="$(srcdir)/"; fi;				\
+tst=$$dir$$f; log='$@'; 				\
+if test -n '$(DISABLE_HARD_ERRORS)'; then		\
+  am__enable_hard_errors=no; 				\
+else							\
+  am__enable_hard_errors=yes; 				\
+fi; 							\
+case " $(XFAIL_TESTS) " in				\
+  *[\ \	]$$f[\ \	]* | *[\ \	]$$dir$$f[\ \	]*) \
+    am__expect_failure=yes;;				\
+  *)							\
+    am__expect_failure=no;;				\
+esac; 							\
+$(AM_TESTS_ENVIRONMENT) $(TESTS_ENVIRONMENT)
+# A shell command to get the names of the tests scripts with any registered
+# extension removed (i.e., equivalently, the names of the test logs, with
+# the '.log' extension removed).  The result is saved in the shell variable
+# '$bases'.  This honors runtime overriding of TESTS and TEST_LOGS.  Sadly,
+# we cannot use something simpler, involving e.g., "$(TEST_LOGS:.log=)",
+# since that might cause problem with VPATH rewrites for suffix-less tests.
+# See also 'test-harness-vpath-rewrite.sh' and 'test-trs-basic.sh'.
+am__set_TESTS_bases = \
+  bases='$(TEST_LOGS)'; \
+  bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \
+  bases=`echo $$bases`
+RECHECK_LOGS = $(TEST_LOGS)
+AM_RECURSIVE_TARGETS = check recheck
+TEST_SUITE_LOG = test-suite.log
+TEST_EXTENSIONS = @EXEEXT@ .test
+LOG_DRIVER = $(SHELL) $(top_srcdir)/cfgaux/test-driver
+LOG_COMPILE = $(LOG_COMPILER) $(AM_LOG_FLAGS) $(LOG_FLAGS)
+am__set_b = \
+  case '$@' in \
+    */*) \
+      case '$*' in \
+        */*) b='$*';; \
+          *) b=`echo '$@' | sed 's/\.log$$//'`; \
+       esac;; \
+    *) \
+      b='$*';; \
+  esac
+am__test_logs1 = $(TESTS:=.log)
+am__test_logs2 = $(am__test_logs1:@EXEEXT@.log=.log)
+TEST_LOGS = $(am__test_logs2:.test.log=.log)
+TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/cfgaux/test-driver
+TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \
+	$(TEST_LOG_FLAGS)
+am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/cfgaux/depcomp \
+	$(top_srcdir)/cfgaux/test-driver $(top_srcdir)/src/Common.am \
+	$(top_srcdir)/src/TestHeaders.am
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+ADAPTATION_LIBS = @ADAPTATION_LIBS@
+AIOLIB = @AIOLIB@
+ALLOCA = @ALLOCA@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+AR_R = @AR_R@
+ATOMICLIB = @ATOMICLIB@
+AUTH_LIBS_TO_BUILD = @AUTH_LIBS_TO_BUILD@
+AUTH_MODULES = @AUTH_MODULES@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+BASIC_AUTH_HELPERS = @BASIC_AUTH_HELPERS@
+BUILDCXX = @BUILDCXX@
+BUILDCXXFLAGS = @BUILDCXXFLAGS@
+BZR = @BZR@
+CACHE_EFFECTIVE_USER = @CACHE_EFFECTIVE_USER@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CGIEXT = @CGIEXT@
+CHMOD = @CHMOD@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CPPUNITCONFIG = @CPPUNITCONFIG@
+CRYPTLIB = @CRYPTLIB@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFAULT_HOSTS = @DEFAULT_HOSTS@
+DEFAULT_LOG_DIR = @DEFAULT_LOG_DIR@
+DEFAULT_PID_FILE = @DEFAULT_PID_FILE@
+DEFAULT_SWAP_DIR = @DEFAULT_SWAP_DIR@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DIGEST_AUTH_HELPERS = @DIGEST_AUTH_HELPERS@
+DISK_LIBS = @DISK_LIBS@
+DISK_MODULES = @DISK_MODULES@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECAP_LIBS = @ECAP_LIBS@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EPOLL_LIBS = @EPOLL_LIBS@
+EUILIB = @EUILIB@
+EXEEXT = @EXEEXT@
+EXPATLIB = @EXPATLIB@
+EXTERNAL_ACL_HELPERS = @EXTERNAL_ACL_HELPERS@
+EXT_LIBECAP_CFLAGS = @EXT_LIBECAP_CFLAGS@
+EXT_LIBECAP_LIBS = @EXT_LIBECAP_LIBS@
+FALSE = @FALSE@
+FGREP = @FGREP@
+GREP = @GREP@
+HAVE_CXX11 = @HAVE_CXX11@
+ICAP_LIBS = @ICAP_LIBS@
+INCLTDL = @INCLTDL@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+KRB5INCS = @KRB5INCS@
+KRB5LIBS = @KRB5LIBS@
+LBERLIB = @LBERLIB@
+LD = @LD@
+LDAPLIB = @LDAPLIB@
+LDFLAGS = @LDFLAGS@
+LIBADD_DL = @LIBADD_DL@
+LIBADD_DLD_LINK = @LIBADD_DLD_LINK@
+LIBADD_DLOPEN = @LIBADD_DLOPEN@
+LIBADD_SHL_LOAD = @LIBADD_SHL_LOAD@
+LIBGNUTLS_CFLAGS = @LIBGNUTLS_CFLAGS@
+LIBGNUTLS_LIBS = @LIBGNUTLS_LIBS@
+LIBLTDL = @LIBLTDL@
+LIBOBJS = @LIBOBJS@
+LIBOPENSSL_CFLAGS = @LIBOPENSSL_CFLAGS@
+LIBOPENSSL_LIBS = @LIBOPENSSL_LIBS@
+LIBPTHREADS = @LIBPTHREADS@
+LIBS = @LIBS@
+LIBSASL = @LIBSASL@
+LIBTOOL = @LIBTOOL@
+LIB_DB = @LIB_DB@
+LIB_KRB5_CFLAGS = @LIB_KRB5_CFLAGS@
+LIB_KRB5_LIBS = @LIB_KRB5_LIBS@
+LINUXDOC = @LINUXDOC@
+LIPO = @LIPO@
+LN = @LN@
+LN_S = @LN_S@
+LOG_DAEMON_HELPERS = @LOG_DAEMON_HELPERS@
+LTDLDEPS = @LTDLDEPS@
+LTDLINCL = @LTDLINCL@
+LTDLOPEN = @LTDLOPEN@
+LTLIBOBJS = @LTLIBOBJS@
+LT_ARGZ_H = @LT_ARGZ_H@
+LT_CONFIG_H = @LT_CONFIG_H@
+LT_DLLOADERS = @LT_DLLOADERS@
+LT_DLPREOPEN = @LT_DLPREOPEN@
+LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MANIFEST_TOOL = @MANIFEST_TOOL@
+MINGW_LIBS = @MINGW_LIBS@
+MKDIR = @MKDIR@
+MKDIR_P = @MKDIR_P@
+MV = @MV@
+NEGOTIATE_AUTH_HELPERS = @NEGOTIATE_AUTH_HELPERS@
+NETTLELIB = @NETTLELIB@
+NM = @NM@
+NMEDIT = @NMEDIT@
+NTLM_AUTH_HELPERS = @NTLM_AUTH_HELPERS@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PERL = @PERL@
+PKG_CONFIG = @PKG_CONFIG@
+PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
+PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
+PO2HTML = @PO2HTML@
+PO2TEXT = @PO2TEXT@
+POD2MAN = @POD2MAN@
+RANLIB = @RANLIB@
+REGEXLIB = @REGEXLIB@
+REPL_LIBS = @REPL_LIBS@
+REPL_OBJS = @REPL_OBJS@
+REPL_POLICIES = @REPL_POLICIES@
+RM = @RM@
+SECURITY_CERTGEN_HELPERS = @SECURITY_CERTGEN_HELPERS@
+SECURITY_CERTV_HELPERS = @SECURITY_CERTV_HELPERS@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SH = @SH@
+SHELL = @SHELL@
+SMBCLIENT = @SMBCLIENT@
+SNMPLIB = @SNMPLIB@
+SQUID_CFLAGS = @SQUID_CFLAGS@
+SQUID_CPPUNIT_INC = @SQUID_CPPUNIT_INC@
+SQUID_CPPUNIT_LA = @SQUID_CPPUNIT_LA@
+SQUID_CPPUNIT_LIBS = @SQUID_CPPUNIT_LIBS@
+SQUID_CXXFLAGS = @SQUID_CXXFLAGS@
+SSLLIB = @SSLLIB@
+STOREID_REWRITE_HELPERS = @STOREID_REWRITE_HELPERS@
+STORE_LIBS_TO_ADD = @STORE_LIBS_TO_ADD@
+STORE_LIBS_TO_BUILD = @STORE_LIBS_TO_BUILD@
+STORE_TESTS = @STORE_TESTS@
+STRIP = @STRIP@
+TR = @TR@
+TRUE = @TRUE@
+URL_REWRITE_HELPERS = @URL_REWRITE_HELPERS@
+VERSION = @VERSION@
+WBINFO = @WBINFO@
+WIN32_PSAPI = @WIN32_PSAPI@
+XMLLIB = @XMLLIB@
+XTRA_LIBS = @XTRA_LIBS@
+XTRA_OBJS = @XTRA_OBJS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+krb5_config = @krb5_config@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+ltdl_LIBOBJS = @ltdl_LIBOBJS@
+ltdl_LTLIBOBJS = @ltdl_LTLIBOBJS@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+runstatedir = @runstatedir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+subdirs = @subdirs@
+sys_symbol_underscore = @sys_symbol_underscore@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
+AM_CFLAGS = $(SQUID_CFLAGS)
+AM_CXXFLAGS = $(SQUID_CXXFLAGS)
+CLEANFILES = testHeaders
+TESTS = testHeaders
+AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/include \
+	-I$(top_srcdir)/lib -I$(top_srcdir)/src \
+	-I$(top_builddir)/include $(SQUID_CPPUNIT_INC) $(KRB5INCS) \
+	$(am__append_1)
+@ENABLE_XPROF_STATS_FALSE@LIBPROFILER = 
+@ENABLE_XPROF_STATS_TRUE@LIBPROFILER = $(top_builddir)/lib/profiler/libprofiler.la
+COMPAT_LIB = $(top_builddir)/compat/libcompatsquid.la $(LIBPROFILER)
+subst_perlshell = sed -e 's,[@]PERL[@],$(PERL),g' <$(srcdir)/$@.pl.in >$@ || ($(RM) -f $@ ; exit 1)
+noinst_LTLIBRARIES = libsbuf.la
+libsbuf_la_SOURCES = \
+	Algorithms.cc \
+	Algorithms.h \
+	DetailedStats.cc \
+	DetailedStats.h \
+	Exceptions.cc \
+	Exceptions.h \
+	forward.h \
+	List.cc \
+	List.h \
+	MemBlob.cc \
+	MemBlob.h \
+	OutOfBoundsException.h \
+	SBuf.cc \
+	SBuf.h \
+	Stats.cc \
+	Stats.h \
+	Stream.h
+
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .cc .lo .log .o .obj .test .test$(EXEEXT) .trs
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/src/Common.am $(top_srcdir)/src/TestHeaders.am $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/sbuf/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign src/sbuf/Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+$(top_srcdir)/src/Common.am $(top_srcdir)/src/TestHeaders.am $(am__empty):
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+
+clean-noinstLTLIBRARIES:
+	-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
+	@list='$(noinst_LTLIBRARIES)'; \
+	locs=`for p in $$list; do echo $$p; done | \
+	      sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
+	      sort -u`; \
+	test -z "$$locs" || { \
+	  echo rm -f $${locs}; \
+	  rm -f $${locs}; \
+	}
+
+libsbuf.la: $(libsbuf_la_OBJECTS) $(libsbuf_la_DEPENDENCIES) $(EXTRA_libsbuf_la_DEPENDENCIES) 
+	$(AM_V_CXXLD)$(CXXLINK)  $(libsbuf_la_OBJECTS) $(libsbuf_la_LIBADD) $(LIBS)
+
+clean-checkPROGRAMS:
+	@list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \
+	echo " rm -f" $$list; \
+	rm -f $$list || exit $$?; \
+	test -n "$(EXEEXT)" || exit 0; \
+	list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+	echo " rm -f" $$list; \
+	rm -f $$list
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Algorithms.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/DetailedStats.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Exceptions.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/List.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MemBlob.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SBuf.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Stats.Plo@am__quote@
+
+.cc.o:
+@am__fastdepCXX_TRUE@	$(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
+@am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCXX_TRUE@	$(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@	$(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $<
+
+.cc.obj:
+@am__fastdepCXX_TRUE@	$(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
+@am__fastdepCXX_TRUE@	$(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\
+@am__fastdepCXX_TRUE@	$(am__mv) $$depbase.Tpo $$depbase.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@	$(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+
+.cc.lo:
+@am__fastdepCXX_TRUE@	$(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
+@am__fastdepCXX_TRUE@	$(LTCXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
+@am__fastdepCXX_TRUE@	$(am__mv) $$depbase.Tpo $$depbase.Plo
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(AM_V_CXX)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@	$(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+ID: $(am__tagged_files)
+	$(am__define_uniq_tagged_files); mkid -fID $$unique
+tags: tags-am
+TAGS: tags
+
+tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+	set x; \
+	here=`pwd`; \
+	$(am__define_uniq_tagged_files); \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: ctags-am
+
+CTAGS: ctags
+ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
+	$(am__define_uniq_tagged_files); \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+cscopelist: cscopelist-am
+
+cscopelist-am: $(am__tagged_files)
+	list='$(am__tagged_files)'; \
+	case "$(srcdir)" in \
+	  [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
+	  *) sdir=$(subdir)/$(srcdir) ;; \
+	esac; \
+	for i in $$list; do \
+	  if test -f "$$i"; then \
+	    echo "$(subdir)/$$i"; \
+	  else \
+	    echo "$$sdir/$$i"; \
+	  fi; \
+	done >> $(top_builddir)/cscope.files
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+# Recover from deleted '.trs' file; this should ensure that
+# "rm -f foo.log; make foo.trs" re-run 'foo.test', and re-create
+# both 'foo.log' and 'foo.trs'.  Break the recipe in two subshells
+# to avoid problems with "make -n".
+.log.trs:
+	rm -f $< $@
+	$(MAKE) $(AM_MAKEFLAGS) $<
+
+# Leading 'am--fnord' is there to ensure the list of targets does not
+# expand to empty, as could happen e.g. with make check TESTS=''.
+am--fnord $(TEST_LOGS) $(TEST_LOGS:.log=.trs): $(am__force_recheck)
+am--force-recheck:
+	@:
+
+$(TEST_SUITE_LOG): $(TEST_LOGS)
+	@$(am__set_TESTS_bases); \
+	am__f_ok () { test -f "$$1" && test -r "$$1"; }; \
+	redo_bases=`for i in $$bases; do \
+	              am__f_ok $$i.trs && am__f_ok $$i.log || echo $$i; \
+	            done`; \
+	if test -n "$$redo_bases"; then \
+	  redo_logs=`for i in $$redo_bases; do echo $$i.log; done`; \
+	  redo_results=`for i in $$redo_bases; do echo $$i.trs; done`; \
+	  if $(am__make_dryrun); then :; else \
+	    rm -f $$redo_logs && rm -f $$redo_results || exit 1; \
+	  fi; \
+	fi; \
+	if test -n "$$am__remaking_logs"; then \
+	  echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \
+	       "recursion detected" >&2; \
+	elif test -n "$$redo_logs"; then \
+	  am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \
+	fi; \
+	if $(am__make_dryrun); then :; else \
+	  st=0;  \
+	  errmsg="fatal: making $(TEST_SUITE_LOG): failed to create"; \
+	  for i in $$redo_bases; do \
+	    test -f $$i.trs && test -r $$i.trs \
+	      || { echo "$$errmsg $$i.trs" >&2; st=1; }; \
+	    test -f $$i.log && test -r $$i.log \
+	      || { echo "$$errmsg $$i.log" >&2; st=1; }; \
+	  done; \
+	  test $$st -eq 0 || exit 1; \
+	fi
+	@$(am__sh_e_setup); $(am__tty_colors); $(am__set_TESTS_bases); \
+	ws='[ 	]'; \
+	results=`for b in $$bases; do echo $$b.trs; done`; \
+	test -n "$$results" || results=/dev/null; \
+	all=`  grep "^$$ws*:test-result:"           $$results | wc -l`; \
+	pass=` grep "^$$ws*:test-result:$$ws*PASS"  $$results | wc -l`; \
+	fail=` grep "^$$ws*:test-result:$$ws*FAIL"  $$results | wc -l`; \
+	skip=` grep "^$$ws*:test-result:$$ws*SKIP"  $$results | wc -l`; \
+	xfail=`grep "^$$ws*:test-result:$$ws*XFAIL" $$results | wc -l`; \
+	xpass=`grep "^$$ws*:test-result:$$ws*XPASS" $$results | wc -l`; \
+	error=`grep "^$$ws*:test-result:$$ws*ERROR" $$results | wc -l`; \
+	if test `expr $$fail + $$xpass + $$error` -eq 0; then \
+	  success=true; \
+	else \
+	  success=false; \
+	fi; \
+	br='==================='; br=$$br$$br$$br$$br; \
+	result_count () \
+	{ \
+	    if test x"$$1" = x"--maybe-color"; then \
+	      maybe_colorize=yes; \
+	    elif test x"$$1" = x"--no-color"; then \
+	      maybe_colorize=no; \
+	    else \
+	      echo "$@: invalid 'result_count' usage" >&2; exit 4; \
+	    fi; \
+	    shift; \
+	    desc=$$1 count=$$2; \
+	    if test $$maybe_colorize = yes && test $$count -gt 0; then \
+	      color_start=$$3 color_end=$$std; \
+	    else \
+	      color_start= color_end=; \
+	    fi; \
+	    echo "$${color_start}# $$desc $$count$${color_end}"; \
+	}; \
+	create_testsuite_report () \
+	{ \
+	  result_count $$1 "TOTAL:" $$all   "$$brg"; \
+	  result_count $$1 "PASS: " $$pass  "$$grn"; \
+	  result_count $$1 "SKIP: " $$skip  "$$blu"; \
+	  result_count $$1 "XFAIL:" $$xfail "$$lgn"; \
+	  result_count $$1 "FAIL: " $$fail  "$$red"; \
+	  result_count $$1 "XPASS:" $$xpass "$$red"; \
+	  result_count $$1 "ERROR:" $$error "$$mgn"; \
+	}; \
+	{								\
+	  echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" |	\
+	    $(am__rst_title);						\
+	  create_testsuite_report --no-color;				\
+	  echo;								\
+	  echo ".. contents:: :depth: 2";				\
+	  echo;								\
+	  for b in $$bases; do echo $$b; done				\
+	    | $(am__create_global_log);					\
+	} >$(TEST_SUITE_LOG).tmp || exit 1;				\
+	mv $(TEST_SUITE_LOG).tmp $(TEST_SUITE_LOG);			\
+	if $$success; then						\
+	  col="$$grn";							\
+	 else								\
+	  col="$$red";							\
+	  test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG);		\
+	fi;								\
+	echo "$${col}$$br$${std}"; 					\
+	echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}";	\
+	echo "$${col}$$br$${std}"; 					\
+	create_testsuite_report --maybe-color;				\
+	echo "$$col$$br$$std";						\
+	if $$success; then :; else					\
+	  echo "$${col}See $(subdir)/$(TEST_SUITE_LOG)$${std}";		\
+	  if test -n "$(PACKAGE_BUGREPORT)"; then			\
+	    echo "$${col}Please report to $(PACKAGE_BUGREPORT)$${std}";	\
+	  fi;								\
+	  echo "$$col$$br$$std";					\
+	fi;								\
+	$$success || exit 1
+
+check-TESTS:
+	@list='$(RECHECK_LOGS)';           test -z "$$list" || rm -f $$list
+	@list='$(RECHECK_LOGS:.log=.trs)'; test -z "$$list" || rm -f $$list
+	@test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG)
+	@set +e; $(am__set_TESTS_bases); \
+	log_list=`for i in $$bases; do echo $$i.log; done`; \
+	trs_list=`for i in $$bases; do echo $$i.trs; done`; \
+	log_list=`echo $$log_list`; trs_list=`echo $$trs_list`; \
+	$(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) TEST_LOGS="$$log_list"; \
+	exit $$?;
+recheck: all $(check_PROGRAMS)
+	@test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG)
+	@set +e; $(am__set_TESTS_bases); \
+	bases=`for i in $$bases; do echo $$i; done \
+	         | $(am__list_recheck_tests)` || exit 1; \
+	log_list=`for i in $$bases; do echo $$i.log; done`; \
+	log_list=`echo $$log_list`; \
+	$(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) \
+	        am__force_recheck=am--force-recheck \
+	        TEST_LOGS="$$log_list"; \
+	exit $$?
+testHeaders.log: testHeaders
+	@p='testHeaders'; \
+	b='testHeaders'; \
+	$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
+	--log-file $$b.log --trs-file $$b.trs \
+	$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
+	"$$tst" $(AM_TESTS_FD_REDIRECT)
+.test.log:
+	@p='$<'; \
+	$(am__set_b); \
+	$(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \
+	--log-file $$b.log --trs-file $$b.trs \
+	$(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \
+	"$$tst" $(AM_TESTS_FD_REDIRECT)
+@am__EXEEXT_TRUE@.test$(EXEEXT).log:
+@am__EXEEXT_TRUE@	@p='$<'; \
+@am__EXEEXT_TRUE@	$(am__set_b); \
+@am__EXEEXT_TRUE@	$(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \
+@am__EXEEXT_TRUE@	--log-file $$b.log --trs-file $$b.trs \
+@am__EXEEXT_TRUE@	$(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \
+@am__EXEEXT_TRUE@	"$$tst" $(AM_TESTS_FD_REDIRECT)
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+	$(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS)
+	$(MAKE) $(AM_MAKEFLAGS) check-TESTS
+check: check-am
+all-am: Makefile $(LTLIBRARIES)
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	if test -z '$(STRIP)'; then \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	      install; \
+	else \
+	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	    "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
+	fi
+mostlyclean-generic:
+	-test -z "$(TEST_LOGS)" || rm -f $(TEST_LOGS)
+	-test -z "$(TEST_LOGS:.log=.trs)" || rm -f $(TEST_LOGS:.log=.trs)
+	-test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG)
+
+clean-generic:
+	-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-checkPROGRAMS clean-generic clean-libtool \
+	clean-noinstLTLIBRARIES mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am:
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am:
+
+.MAKE: check-am install-am install-strip
+
+.PHONY: CTAGS GTAGS TAGS all all-am check check-TESTS check-am clean \
+	clean-checkPROGRAMS clean-generic clean-libtool \
+	clean-noinstLTLIBRARIES cscopelist-am ctags ctags-am distclean \
+	distclean-compile distclean-generic distclean-libtool \
+	distclean-tags distdir dvi dvi-am html html-am info info-am \
+	install install-am install-data install-data-am install-dvi \
+	install-dvi-am install-exec install-exec-am install-html \
+	install-html-am install-info install-info-am install-man \
+	install-pdf install-pdf-am install-ps install-ps-am \
+	install-strip installcheck installcheck-am installdirs \
+	maintainer-clean maintainer-clean-generic mostlyclean \
+	mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
+	pdf pdf-am ps ps-am recheck tags tags-am uninstall \
+	uninstall-am
+
+.PRECIOUS: Makefile
+
+
+$(OBJS): $(top_srcdir)/include/version.h $(top_builddir)/include/autoconf.h
+
+testHeaders: $(srcdir)/*.h
+	$(SHELL) $(top_srcdir)/test-suite/testheaders.sh "$(CXXCOMPILE)" $^ || exit 1
+
+.PHONY: testHeaders
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff -u -r -N squid-4.0.7/src/sbuf/MemBlob.cc squid-4.0.8/src/sbuf/MemBlob.cc
--- squid-4.0.7/src/sbuf/MemBlob.cc	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/MemBlob.cc	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "base/TextException.h"
+#include "Debug.h"
+#include "sbuf/DetailedStats.h"
+#include "sbuf/MemBlob.h"
+
+#include <iostream>
+
+MemBlobStats MemBlob::Stats;
+InstanceIdDefinitions(MemBlob, "blob");
+
+/* MemBlobStats */
+
+MemBlobStats::MemBlobStats(): alloc(0), live(0), append(0), liveBytes(0)
+{}
+
+MemBlobStats&
+MemBlobStats::operator += (const MemBlobStats& s)
+{
+    alloc+=s.alloc;
+    live+=s.live;
+    append+=s.append;
+    liveBytes+=s.liveBytes;
+
+    return *this;
+}
+
+std::ostream&
+MemBlobStats::dump(std::ostream &os) const
+{
+    os <<
+       "MemBlob created: " << alloc <<
+       "\nMemBlob alive: " << live <<
+       "\nMemBlob append calls: " << append <<
+       "\nMemBlob currently allocated size: " << liveBytes <<
+       "\nlive MemBlob mean current allocation size: " <<
+       (static_cast<double>(liveBytes)/(live?live:1)) << std::endl;
+    return os;
+}
+
+/* MemBlob */
+
+MemBlob::MemBlob(const MemBlob::size_type reserveSize) :
+    mem(NULL), capacity(0), size(0) // will be set by memAlloc
+{
+    debugs(MEMBLOB_DEBUGSECTION,9, HERE << "constructed, this="
+           << static_cast<void*>(this) << " id=" << id
+           << " reserveSize=" << reserveSize);
+    memAlloc(reserveSize);
+}
+
+MemBlob::MemBlob(const char *buffer, const MemBlob::size_type bufSize) :
+    mem(NULL), capacity(0), size(0) // will be set by memAlloc
+{
+    debugs(MEMBLOB_DEBUGSECTION,9, HERE << "constructed, this="
+           << static_cast<void*>(this) << " id=" << id
+           << " buffer=" << static_cast<const void*>(buffer)
+           << " bufSize=" << bufSize);
+    memAlloc(bufSize);
+    append(buffer, bufSize);
+}
+
+MemBlob::~MemBlob()
+{
+    if (mem || capacity)
+        memFreeString(capacity,mem);
+    Stats.liveBytes -= capacity;
+    --Stats.live;
+    recordMemBlobSizeAtDestruct(capacity);
+
+    debugs(MEMBLOB_DEBUGSECTION,9, HERE << "destructed, this="
+           << static_cast<void*>(this) << " id=" << id
+           << " capacity=" << capacity
+           << " size=" << size);
+}
+
+/** Allocate an available space area of at least minSize bytes in size.
+ *  Must be called by constructors and only by constructors.
+ */
+void
+MemBlob::memAlloc(const size_type minSize)
+{
+    size_t actualAlloc = minSize;
+
+    Must(!mem);
+    mem = static_cast<char*>(memAllocString(actualAlloc, &actualAlloc));
+    Must(mem);
+
+    capacity = actualAlloc;
+    size = 0;
+    debugs(MEMBLOB_DEBUGSECTION, 8,
+           id << " memAlloc: requested=" << minSize <<
+           ", received=" << capacity);
+    ++Stats.live;
+    ++Stats.alloc;
+    Stats.liveBytes += capacity;
+}
+
+void
+MemBlob::appended(const size_type n)
+{
+    Must(willFit(n));
+    size += n;
+    ++Stats.append;
+}
+
+void
+MemBlob::append(const char *source, const size_type n)
+{
+    if (n > 0) { // appending zero bytes is allowed but only affects the stats
+        Must(willFit(n));
+        Must(source);
+        memmove(mem + size, source, n);
+        size += n;
+    }
+    ++Stats.append;
+}
+
+const MemBlobStats&
+MemBlob::GetStats()
+{
+    return Stats;
+}
+
+std::ostream&
+MemBlob::dump(std::ostream &os) const
+{
+    os << "id @" << (void *)this
+       << "mem:" << static_cast<void*>(mem)
+       << ",capacity:" << capacity
+       << ",size:" << size
+       << ",refs:" << LockCount() << "; ";
+    return os;
+}
+
diff -u -r -N squid-4.0.7/src/sbuf/MemBlob.h squid-4.0.8/src/sbuf/MemBlob.h
--- squid-4.0.7/src/sbuf/MemBlob.h	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/MemBlob.h	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_MEMBLOB_H_
+#define SQUID_MEMBLOB_H_
+
+#define MEMBLOB_DEBUGSECTION 24
+
+#include "base/InstanceId.h"
+#include "base/RefCount.h"
+#include "mem/forward.h"
+
+/// Various MemBlob class-wide statistics.
+class MemBlobStats
+{
+public:
+    MemBlobStats();
+
+    /// dumps class-wide statistics
+    std::ostream& dump(std::ostream& os) const;
+
+    MemBlobStats& operator += (const MemBlobStats&);
+
+public:
+    uint64_t alloc;     ///< number of MemBlob instances created so far
+    uint64_t live;      ///< number of MemBlob instances currently alive
+    uint64_t append;    ///< number of MemBlob::append() calls
+    uint64_t liveBytes; ///< the total size of currently allocated storage
+};
+
+/** Refcountable, fixed-size, content-agnostic memory buffer.
+ *
+ * Allocated memory block is divided into two sequential areas:
+ * "used memory" and "available space". The used area can be filled during
+ * construction, grows via the append() call, and can be clear()ed.
+ *
+ * MemBlob users can cooperate to safely share the used area. However, MemBlob
+ * provides weak use accounting and no sharing protections besides refcounting.
+ */
+class MemBlob: public RefCountable
+{
+    MEMPROXY_CLASS(MemBlob);
+
+public:
+    typedef RefCount<MemBlob> Pointer;
+    typedef uint32_t size_type;
+
+    /// obtain a const view of class-wide statistics
+    static const MemBlobStats& GetStats();
+
+    /// create a new MemBlob with at least reserveSize capacity
+    explicit MemBlob(const size_type reserveSize);
+
+    /// create a MemBlob containing a copy of the buffer of a given size
+    MemBlob(const char *buffer, const size_type bufferSize);
+
+    virtual ~MemBlob();
+
+    /// the number unused bytes at the end of the allocated blob
+    size_type spaceSize() const { return capacity - size; }
+
+    /** check whether the caller can successfully append() n bytes
+     *
+     * \return true  the caller may append() n bytes to this blob now
+     * \param off    the end of the blob area currently used by the caller
+     * \param n      the total number of bytes the caller wants to append
+     */
+    bool canAppend(const size_type off, const size_type n) const {
+        // TODO: ignore offset (and adjust size) when the blob is not shared?
+        return isAppendOffset(off) && willFit(n);
+    }
+
+    /** adjusts internal object state as if exactly n bytes were append()ed
+     *
+     * \throw TextException if there was not enough space in the blob
+     * \param n the number of bytes that were appended
+     */
+    void appended(const size_type n);
+
+    /** copies exactly n bytes from the source to the available space area,
+     *  enlarging the used area by n bytes
+     *
+     * \throw TextException if there is not enough space in the blob
+     * \param source raw buffer to be copied
+     * \param n the number of bytes to copy from the source buffer
+     */
+    void append(const char *source, const size_type n);
+
+    /// extends the available space to the entire allocated blob
+    void clear() { size = 0; }
+
+    /// dump debugging information
+    std::ostream & dump(std::ostream &os) const;
+
+public:
+    /* MemBlob users should avoid these and must treat them as read-only */
+    char *mem;          ///< raw allocated memory block
+    size_type capacity; ///< size of the raw allocated memory block
+    size_type size;     ///< maximum allocated memory in use by callers
+    const InstanceId<MemBlob> id; ///< blob identifier
+
+private:
+    static MemBlobStats Stats; ///< class-wide statistics
+
+    void memAlloc(const size_type memSize);
+
+    /// whether the offset points to the end of the used area
+    bool isAppendOffset(const size_type off) const { return off == size; }
+
+    /// whether n more bytes can be appended
+    bool willFit(const size_type n) const { return n <= spaceSize(); }
+
+    /* copying is not implemented */
+    MemBlob(const MemBlob &);
+    MemBlob& operator =(const MemBlob &);
+};
+
+#endif /* SQUID_MEMBLOB_H_ */
+
diff -u -r -N squid-4.0.7/src/sbuf/OutOfBoundsException.h squid-4.0.8/src/sbuf/OutOfBoundsException.h
--- squid-4.0.7/src/sbuf/OutOfBoundsException.h	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/OutOfBoundsException.h	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef _SQUID_SRC_OUTOFBOUNDSEXCEPTION_H
+#define _SQUID_SRC_OUTOFBOUNDSEXCEPTION_H
+
+#include "base/TextException.h"
+#include "sbuf/SBuf.h"
+
+/**
+ * Exception raised when the user is going out of bounds when accessing
+ * a char within the SBuf
+ */
+class OutOfBoundsException : public TextException
+{
+public:
+    OutOfBoundsException(const SBuf &buf, SBuf::size_type &pos, const char *aFileName = 0, int aLineNo = -1);
+    virtual ~OutOfBoundsException() throw();
+
+protected:
+    SBuf theThrowingBuf;
+    SBuf::size_type accessedPosition;
+};
+
+#endif /* _SQUID_SRC_OUTOFBOUNDSEXCEPTION_H */
+
diff -u -r -N squid-4.0.7/src/sbuf/SBuf.cc squid-4.0.8/src/sbuf/SBuf.cc
--- squid-4.0.7/src/sbuf/SBuf.cc	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/SBuf.cc	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,917 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "base/CharacterSet.h"
+#include "base/RefCount.h"
+#include "Debug.h"
+#include "sbuf/DetailedStats.h"
+#include "sbuf/Exceptions.h"
+#include "sbuf/OutOfBoundsException.h"
+#include "sbuf/SBuf.h"
+#include "util.h"
+
+#include <cstring>
+#include <functional>
+#include <iostream>
+#include <sstream>
+
+#ifdef VA_COPY
+#undef VA_COPY
+#endif
+#if defined HAVE_VA_COPY
+#define VA_COPY va_copy
+#elif defined HAVE___VA_COPY
+#define VA_COPY __va_copy
+#endif
+
+InstanceIdDefinitions(SBuf, "SBuf");
+
+SBufStats SBuf::stats;
+const SBuf::size_type SBuf::npos;
+const SBuf::size_type SBuf::maxSize;
+
+SBuf::SBuf()
+    : store_(GetStorePrototype()), off_(0), len_(0)
+{
+    debugs(24, 8, id << " created");
+    ++stats.alloc;
+    ++stats.live;
+}
+
+SBuf::SBuf(const SBuf &S)
+    : store_(S.store_), off_(S.off_), len_(S.len_)
+{
+    debugs(24, 8, id << " created from id " << S.id);
+    ++stats.alloc;
+    ++stats.allocCopy;
+    ++stats.live;
+}
+
+SBuf::SBuf(const std::string &s)
+    : store_(GetStorePrototype()), off_(0), len_(0)
+{
+    debugs(24, 8, id << " created from std::string");
+    lowAppend(s.data(),s.length());
+    ++stats.alloc;
+    ++stats.live;
+}
+
+SBuf::SBuf(const char *S, size_type n)
+    : store_(GetStorePrototype()), off_(0), len_(0)
+{
+    append(S,n);
+    ++stats.alloc;
+    ++stats.allocFromCString;
+    ++stats.live;
+}
+
+SBuf::SBuf(const char *S)
+    : store_(GetStorePrototype()), off_(0), len_(0)
+{
+    append(S,npos);
+    ++stats.alloc;
+    ++stats.allocFromCString;
+    ++stats.live;
+}
+
+SBuf::~SBuf()
+{
+    debugs(24, 8, id << " destructed");
+    --stats.live;
+    recordSBufSizeAtDestruct(len_);
+}
+
+MemBlob::Pointer
+SBuf::GetStorePrototype()
+{
+    static MemBlob::Pointer InitialStore = new MemBlob(0);
+    return InitialStore;
+}
+
+SBuf&
+SBuf::assign(const SBuf &S)
+{
+    debugs(24, 7, "assigning " << id << " from " <<  S.id);
+    if (&S == this) //assignment to self. Noop.
+        return *this;
+    ++stats.assignFast;
+    store_ = S.store_;
+    off_ = S.off_;
+    len_ = S.len_;
+    return *this;
+}
+
+SBuf&
+SBuf::assign(const char *S, size_type n)
+{
+    const Locker blobKeeper(this, S);
+    debugs(24, 6, id << " from c-string, n=" << n << ")");
+    clear();
+    return append(S, n); //bounds checked in append()
+}
+
+void
+SBuf::reserveCapacity(size_type minCapacity)
+{
+    Must(minCapacity <= maxSize);
+    cow(minCapacity);
+}
+
+char *
+SBuf::rawSpace(size_type minSpace)
+{
+    Must(length() <= maxSize - minSpace);
+    debugs(24, 7, "reserving " << minSpace << " for " << id);
+    ++stats.rawAccess;
+    // we're not concerned about RefCounts here,
+    // the store knows the last-used portion. If
+    // it's available, we're effectively claiming ownership
+    // of it. If it's not, we need to go away (realloc)
+    if (store_->canAppend(off_+len_, minSpace)) {
+        debugs(24, 7, id << " not growing");
+        return bufEnd();
+    }
+    // TODO: we may try to memmove before realloc'ing in order to avoid
+    //   one allocation operation, if we're the sole owners of a MemBlob.
+    //   Maybe some heuristic on off_ and length()?
+    cow(minSpace+length());
+    return bufEnd();
+}
+
+void
+SBuf::clear()
+{
+#if 0
+    //enabling this code path, the store will be freed and reinitialized
+    store_ = GetStorePrototype(); //uncomment to actually free storage upon clear()
+#else
+    //enabling this code path, we try to release the store without deallocating it.
+    // will be lazily reallocated if needed.
+    if (store_->LockCount() == 1)
+        store_->clear();
+#endif
+    len_ = 0;
+    off_ = 0;
+    ++stats.clear;
+}
+
+SBuf&
+SBuf::append(const SBuf &S)
+{
+    const Locker blobKeeper(this, S.buf());
+    return lowAppend(S.buf(), S.length());
+}
+
+SBuf &
+SBuf::append(const char * S, size_type Ssize)
+{
+    const Locker blobKeeper(this, S);
+    if (S == NULL)
+        return *this;
+    if (Ssize == SBuf::npos)
+        Ssize = strlen(S);
+    debugs(24, 7, "from c-string to id " << id);
+    // coverity[access_dbuff_in_call]
+    return lowAppend(S, Ssize);
+}
+
+SBuf &
+SBuf::append(const char c)
+{
+    return lowAppend(&c, 1);
+}
+
+SBuf&
+SBuf::Printf(const char *fmt, ...)
+{
+    // with printf() the fmt or an arg might be a dangerous char*
+    // NP: cant rely on vappendf() Locker because of clear()
+    const Locker blobKeeper(this, buf());
+
+    va_list args;
+    va_start(args, fmt);
+    clear();
+    vappendf(fmt, args);
+    va_end(args);
+    return *this;
+}
+
+SBuf&
+SBuf::appendf(const char *fmt, ...)
+{
+    va_list args;
+    va_start(args, fmt);
+    vappendf(fmt, args);
+    va_end(args);
+    return *this;
+}
+
+SBuf&
+SBuf::vappendf(const char *fmt, va_list vargs)
+{
+    // with (v)appendf() the fmt or an arg might be a dangerous char*
+    const Locker blobKeeper(this, buf());
+
+    Must(fmt != NULL);
+    int sz = 0;
+    //reserve twice the format-string size, it's a likely heuristic
+    size_type requiredSpaceEstimate = strlen(fmt)*2;
+
+    char *space = rawSpace(requiredSpaceEstimate);
+#ifdef VA_COPY
+    va_list ap;
+    VA_COPY(ap, vargs);
+    sz = vsnprintf(space, spaceSize(), fmt, ap);
+    va_end(ap);
+#else
+    sz = vsnprintf(space, spaceSize(), fmt, vargs);
+#endif
+
+    /* check for possible overflow */
+    /* snprintf on Linux returns -1 on output errors, or the size
+     * that would have been written if enough space had been available */
+    /* vsnprintf is standard in C99 */
+
+    if (sz >= static_cast<int>(spaceSize())) {
+        // not enough space on the first go, we now know how much we need
+        requiredSpaceEstimate = sz*2; // TODO: tune heuristics
+        space = rawSpace(requiredSpaceEstimate);
+        sz = vsnprintf(space, spaceSize(), fmt, vargs);
+        if (sz < 0) // output error in vsnprintf
+            throw TextException("output error in second-go vsnprintf",__FILE__,
+                                __LINE__);
+    }
+
+    if (sz < 0) // output error in either vsnprintf
+        throw TextException("output error in vsnprintf",__FILE__, __LINE__);
+
+    // data was appended, update internal state
+    len_ += sz;
+
+    /* C99 specifies that the final '\0' is not counted in vsnprintf's
+     * return value. Older compilers/libraries might instead count it */
+    /* check whether '\0' was appended and counted */
+    static bool snPrintfTerminatorChecked = false;
+    static bool snPrintfTerminatorCounted = false;
+    if (!snPrintfTerminatorChecked) {
+        char testbuf[16];
+        snPrintfTerminatorCounted = snprintf(testbuf, sizeof(testbuf),
+                                             "%s", "1") == 2;
+        snPrintfTerminatorChecked = true;
+    }
+    if (snPrintfTerminatorCounted) {
+        --sz;
+        --len_;
+    }
+
+    store_->size += sz;
+    ++stats.append;
+
+    return *this;
+}
+
+std::ostream&
+SBuf::print(std::ostream &os) const
+{
+    os.write(buf(), length());
+    ++stats.toStream;
+    return os;
+}
+
+std::ostream&
+SBuf::dump(std::ostream &os) const
+{
+    os << id
+       << ": ";
+    store_->dump(os);
+    os << ", offset:" << off_
+       << ", len:" << len_
+       << ") : '";
+    print(os);
+    os << '\'' << std::endl;
+    return os;
+# if 0
+    // alternate implementation, based on Raw() API.
+    os << Raw("SBuf", buf(), length()) <<
+       ". id: " << id <<
+       ", offset:" << off_ <<
+       ", len:" << len_ <<
+       ", store: ";
+    store_->dump(os);
+    os << std::endl;
+    return os;
+#endif
+}
+
+void
+SBuf::setAt(size_type pos, char toset)
+{
+    checkAccessBounds(pos);
+    cow();
+    store_->mem[off_+pos] = toset;
+    ++stats.setChar;
+}
+
+static int
+memcasecmp(const char *b1, const char *b2, SBuf::size_type len)
+{
+    int rv=0;
+    while (len > 0) {
+        rv = tolower(*b1)-tolower(*b2);
+        if (rv != 0)
+            return rv;
+        ++b1;
+        ++b2;
+        --len;
+    }
+    return rv;
+}
+
+int
+SBuf::compare(const SBuf &S, const SBufCaseSensitive isCaseSensitive, const size_type n) const
+{
+    if (n != npos) {
+        debugs(24, 8, "length specified. substr and recurse");
+        return substr(0,n).compare(S.substr(0,n),isCaseSensitive);
+    }
+
+    const size_type byteCompareLen = min(S.length(), length());
+    ++stats.compareSlow;
+    int rv = 0;
+    debugs(24, 8, "comparing length " << byteCompareLen);
+    if (isCaseSensitive == caseSensitive) {
+        rv = memcmp(buf(), S.buf(), byteCompareLen);
+    } else {
+        rv = memcasecmp(buf(), S.buf(), byteCompareLen);
+    }
+    if (rv != 0) {
+        debugs(24, 8, "result: " << rv);
+        return rv;
+    }
+    if (n <= length() || n <= S.length()) {
+        debugs(24, 8, "same contents and bounded length. Equal");
+        return 0;
+    }
+    if (length() == S.length()) {
+        debugs(24, 8, "same contents and same length. Equal");
+        return 0;
+    }
+    if (length() > S.length()) {
+        debugs(24, 8, "lhs is longer than rhs. Result is 1");
+        return 1;
+    }
+    debugs(24, 8, "rhs is longer than lhs. Result is -1");
+    return -1;
+}
+
+int
+SBuf::compare(const char *s, const SBufCaseSensitive isCaseSensitive, const size_type n) const
+{
+    // 0-length comparison is always true regardless of buffer states
+    if (!n) {
+        ++stats.compareFast;
+        return 0;
+    }
+
+    // N-length compare MUST provide a non-NULL C-string pointer
+    assert(s);
+
+    // when this is a 0-length string, no need for any complexity.
+    if (!length()) {
+        ++stats.compareFast;
+        return '\0' - *s;
+    }
+
+    // brute-force scan in order to avoid ever needing strlen() on a c-string.
+    ++stats.compareSlow;
+    const char *left = buf();
+    const char *right = s;
+    int rv = 0;
+    // what area to scan.
+    // n may be npos, but we treat that as a huge positive value
+    size_type byteCount = min(length(), n);
+
+    // loop until we find a difference, a '\0', or reach the end of area to scan
+    if (isCaseSensitive == caseSensitive) {
+        while ((rv = *left - *right++) == 0) {
+            if (*left++ == '\0' || --byteCount == 0)
+                break;
+        }
+    } else {
+        while ((rv = tolower(*left) - tolower(*right++)) == 0) {
+            if (*left++ == '\0' || --byteCount == 0)
+                break;
+        }
+    }
+
+    // If we stopped scanning because we reached the end
+    //  of buf() before we reached the end of s,
+    // pretend we have a 0-terminator there to compare.
+    // NP: the loop already incremented "right" ready for this comparison
+    if (!byteCount && length() < n)
+        return '\0' - *right;
+
+    // If we found a difference within the scan area,
+    // or we found a '\0',
+    // or all n characters were identical (and none was \0).
+    return rv;
+}
+
+bool
+SBuf::startsWith(const SBuf &S, const SBufCaseSensitive isCaseSensitive) const
+{
+    debugs(24, 8, id << " startsWith " << S.id << ", caseSensitive: " <<
+           isCaseSensitive);
+    if (length() < S.length()) {
+        debugs(24, 8, "no, too short");
+        ++stats.compareFast;
+        return false;
+    }
+    return (compare(S, isCaseSensitive, S.length()) == 0);
+}
+
+bool
+SBuf::operator ==(const SBuf & S) const
+{
+    debugs(24, 8, id << " == " << S.id);
+    if (length() != S.length()) {
+        debugs(24, 8, "no, different lengths");
+        ++stats.compareFast;
+        return false; //shortcut: must be equal length
+    }
+    if (store_ == S.store_ && off_ == S.off_) {
+        debugs(24, 8, "yes, same length and backing store");
+        ++stats.compareFast;
+        return true;  //shortcut: same store, offset and length
+    }
+    ++stats.compareSlow;
+    const bool rv = (0 == memcmp(buf(), S.buf(), length()));
+    debugs(24, 8, "returning " << rv);
+    return rv;
+}
+
+bool
+SBuf::operator !=(const SBuf & S) const
+{
+    return !(*this == S);
+}
+
+SBuf
+SBuf::consume(size_type n)
+{
+    if (n == npos)
+        n = length();
+    else
+        n = min(n, length());
+    debugs(24, 8, id << " consume " << n);
+    SBuf rv(substr(0, n));
+    chop(n);
+    return rv;
+}
+
+const
+SBufStats& SBuf::GetStats()
+{
+    return stats;
+}
+
+SBuf::size_type
+SBuf::copy(char *dest, size_type n) const
+{
+    size_type toexport = min(n,length());
+    memcpy(dest, buf(), toexport);
+    ++stats.copyOut;
+    return toexport;
+}
+
+const char*
+SBuf::rawContent() const
+{
+    ++stats.rawAccess;
+    return buf();
+}
+
+void
+SBuf::forceSize(size_type newSize)
+{
+    debugs(24, 8, id << " force " << (newSize > length() ? "grow" : "shrink") << " to length=" << newSize);
+
+    Must(store_->LockCount() == 1);
+    if (newSize > min(maxSize,store_->capacity-off_))
+        throw SBufTooBigException(__FILE__,__LINE__);
+    len_ = newSize;
+    store_->size = newSize;
+}
+
+const char*
+SBuf::c_str()
+{
+    ++stats.rawAccess;
+    /* null-terminate the current buffer, by hand-appending a \0 at its tail but
+     * without increasing its length. May COW, the side-effect is to guarantee that
+     * the MemBlob's tail is availabe for us to use */
+    *rawSpace(1) = '\0';
+    ++store_->size;
+    ++stats.setChar;
+    ++stats.nulTerminate;
+    return buf();
+}
+
+SBuf&
+SBuf::chop(size_type pos, size_type n)
+{
+    if (pos == npos || pos > length())
+        pos = length();
+
+    if (n == npos || (pos+n) > length())
+        n = length() - pos;
+
+    // if there will be nothing left, reset the buffer while we can
+    if (pos == length() || n == 0) {
+        clear();
+        return *this;
+    }
+
+    ++stats.chop;
+    off_ += pos;
+    len_ = n;
+    return *this;
+}
+
+SBuf&
+SBuf::trim(const SBuf &toRemove, bool atBeginning, bool atEnd)
+{
+    ++stats.trim;
+    if (atEnd) {
+        const char *p = bufEnd()-1;
+        while (!isEmpty() && memchr(toRemove.buf(), *p, toRemove.length()) != NULL) {
+            //current end-of-buf is in the searched set
+            --len_;
+            --p;
+        }
+    }
+    if (atBeginning) {
+        const char *p = buf();
+        while (!isEmpty() && memchr(toRemove.buf(), *p, toRemove.length()) != NULL) {
+            --len_;
+            ++off_;
+            ++p;
+        }
+    }
+    if (isEmpty())
+        clear();
+    return *this;
+}
+
+SBuf
+SBuf::substr(size_type pos, size_type n) const
+{
+    SBuf rv(*this);
+    rv.chop(pos, n); //stats handled by callee
+    return rv;
+}
+
+SBuf::size_type
+SBuf::find(char c, size_type startPos) const
+{
+    ++stats.find;
+
+    if (startPos == npos) // can't find anything if we look past end of SBuf
+        return npos;
+
+    // std::string returns npos if needle is outside hay
+    if (startPos > length())
+        return npos;
+
+    const void *i = memchr(buf()+startPos, (int)c, (size_type)length()-startPos);
+
+    if (i == NULL)
+        return npos;
+
+    return (static_cast<const char *>(i)-buf());
+}
+
+SBuf::size_type
+SBuf::find(const SBuf &needle, size_type startPos) const
+{
+    if (startPos == npos) { // can't find anything if we look past end of SBuf
+        ++stats.find;
+        return npos;
+    }
+
+    // std::string allows needle to overhang hay but not start outside
+    if (startPos > length()) {
+        ++stats.find;
+        return npos;
+    }
+
+    // for empty needle std::string returns startPos
+    if (needle.length() == 0) {
+        ++stats.find;
+        return startPos;
+    }
+
+    // if needle length is 1 use the char search
+    if (needle.length() == 1)
+        return find(needle[0], startPos);
+
+    ++stats.find;
+
+    char *start = buf()+startPos;
+    char *lastPossible = buf()+length()-needle.length()+1;
+    char needleBegin = needle[0];
+
+    debugs(24, 7, "looking for " << needle << "starting at " << startPos <<
+           " in id " << id);
+    while (start < lastPossible) {
+        char *tmp;
+        debugs(24, 8, " begin=" << (void *) start <<
+               ", lastPossible=" << (void*) lastPossible );
+        tmp = static_cast<char *>(memchr(start, needleBegin, lastPossible-start));
+        if (tmp == NULL) {
+            debugs(24, 8 , "First byte not found");
+            return npos;
+        }
+        // lastPossible guarrantees no out-of-bounds with memcmp()
+        if (0 == memcmp(needle.buf(), tmp, needle.length())) {
+            debugs(24, 8, "Found at " << (tmp-buf()));
+            return (tmp-buf());
+        }
+        start = tmp+1;
+    }
+    debugs(24, 8, "not found");
+    return npos;
+}
+
+SBuf::size_type
+SBuf::rfind(const SBuf &needle, SBuf::size_type endPos) const
+{
+    // when the needle is 1 char, use the 1-char rfind()
+    if (needle.length() == 1)
+        return rfind(needle[0], endPos);
+
+    ++stats.find;
+
+    // needle is bigger than haystack, impossible find
+    if (length() < needle.length())
+        return npos;
+
+    // if startPos is npos, std::string scans from the end of hay
+    if (endPos == npos || endPos > length()-needle.length())
+        endPos = length()-needle.length();
+
+    // an empty needle found at the end of the haystack
+    if (needle.length() == 0)
+        return endPos;
+
+    char *bufBegin = buf();
+    char *cur = bufBegin+endPos;
+    const char needleBegin = needle[0];
+    while (cur >= bufBegin) {
+        if (*cur == needleBegin) {
+            if (0 == memcmp(needle.buf(), cur, needle.length())) {
+                // found
+                return (cur-buf());
+            }
+        }
+        --cur;
+    }
+    return npos;
+}
+
+SBuf::size_type
+SBuf::rfind(char c, SBuf::size_type endPos) const
+{
+    ++stats.find;
+
+    // shortcut: haystack is empty, can't find anything by definition
+    if (length() == 0)
+        return npos;
+
+    // on npos input std::string compares last octet of hay
+    if (endPos == npos || endPos >= length()) {
+        endPos = length();
+    } else {
+        // NP: off-by-one weirdness:
+        // endPos is an offset ... 0-based
+        // length() is a count ... 1-based
+        // memrhr() requires a 1-based count of space to scan.
+        ++endPos;
+    }
+
+    if (length() == 0)
+        return endPos;
+
+    const void *i = memrchr(buf(), (int)c, (size_type)endPos);
+
+    if (i == NULL)
+        return npos;
+
+    return (static_cast<const char *>(i)-buf());
+}
+
+SBuf::size_type
+SBuf::findFirstOf(const CharacterSet &set, size_type startPos) const
+{
+    ++stats.find;
+
+    if (startPos == npos)
+        return npos;
+
+    if (startPos >= length())
+        return npos;
+
+    debugs(24, 7, "first of characterset " << set.name << " in id " << id);
+    char *cur = buf()+startPos;
+    const char *bufend = bufEnd();
+    while (cur < bufend) {
+        if (set[*cur])
+            return cur-buf();
+        ++cur;
+    }
+    debugs(24, 7, "not found");
+    return npos;
+}
+
+SBuf::size_type
+SBuf::findFirstNotOf(const CharacterSet &set, size_type startPos) const
+{
+    ++stats.find;
+
+    if (startPos == npos)
+        return npos;
+
+    if (startPos >= length())
+        return npos;
+
+    debugs(24, 7, "first not of characterset " << set.name << " in id " << id);
+    char *cur = buf()+startPos;
+    const char *bufend = bufEnd();
+    while (cur < bufend) {
+        if (!set[*cur])
+            return cur-buf();
+        ++cur;
+    }
+    debugs(24, 7, "not found");
+    return npos;
+}
+
+SBuf::size_type
+SBuf::findLastOf(const CharacterSet &set, size_type endPos) const
+{
+    ++stats.find;
+
+    if (isEmpty())
+        return npos;
+
+    if (endPos == npos || endPos >= length())
+        endPos = length() - 1;
+
+    debugs(24, 7, "last of characterset " << set.name << " in id " << id);
+    const char *start = buf();
+    for (const char *cur = start + endPos; cur >= start; --cur) {
+        if (set[*cur])
+            return cur - start;
+    }
+    debugs(24, 7, "not found");
+    return npos;
+}
+
+SBuf::size_type
+SBuf::findLastNotOf(const CharacterSet &set, size_type endPos) const
+{
+    ++stats.find;
+
+    if (isEmpty())
+        return npos;
+
+    if (endPos == npos || endPos >= length())
+        endPos = length() - 1;
+
+    debugs(24, 7, "last not of characterset " << set.name << " in id " << id);
+    const char *start = buf();
+    for (const char *cur = start + endPos; cur >= start; --cur) {
+        if (!set[*cur])
+            return cur - start;
+    }
+    debugs(24, 7, "not found");
+    return npos;
+}
+
+/*
+ * TODO: borrow a sscanf implementation from Linux or similar?
+ * we'd really need a vsnscanf(3)... ? As an alternative, a
+ * light-regexp-like domain-specific syntax might be an idea.
+ */
+int
+SBuf::scanf(const char *format, ...)
+{
+    // with the format or an arg might be a dangerous char*
+    // that gets invalidated by c_str()
+    const Locker blobKeeper(this, buf());
+
+    va_list arg;
+    int rv;
+    ++stats.scanf;
+    va_start(arg, format);
+    rv = vsscanf(c_str(), format, arg);
+    va_end(arg);
+    return rv;
+}
+
+void
+SBuf::toLower()
+{
+    debugs(24, 8, "\"" << *this << "\"");
+    for (size_type j = 0; j < length(); ++j) {
+        const int c = (*this)[j];
+        if (isupper(c))
+            setAt(j, tolower(c));
+    }
+    debugs(24, 8, "result: \"" << *this << "\"");
+    ++stats.caseChange;
+}
+
+void
+SBuf::toUpper()
+{
+    debugs(24, 8, "\"" << *this << "\"");
+    for (size_type j = 0; j < length(); ++j) {
+        const int c = (*this)[j];
+        if (islower(c))
+            setAt(j, toupper(c));
+    }
+    debugs(24, 8, "result: \"" << *this << "\"");
+    ++stats.caseChange;
+}
+
+/**
+ * checks whether the requested 'pos' is within the bounds of the SBuf
+ * \throw OutOfBoundsException if access is out of bounds
+ */
+void
+SBuf::checkAccessBounds(size_type pos) const
+{
+    if (pos >= length())
+        throw OutOfBoundsException(*this, pos, __FILE__, __LINE__);
+}
+
+/** re-allocate the backing store of the SBuf.
+ *
+ * If there are contents in the SBuf, they will be copied over.
+ * NO verifications are made on the size parameters, it's up to the caller to
+ * make sure that the new size is big enough to hold the copied contents.
+ * The re-allocated storage MAY be bigger than the requested size due to size-chunking
+ * algorithms in MemBlock, it is guarranteed NOT to be smaller.
+ */
+void
+SBuf::reAlloc(size_type newsize)
+{
+    debugs(24, 8, id << " new size: " << newsize);
+    if (newsize > maxSize)
+        throw SBufTooBigException(__FILE__, __LINE__);
+    MemBlob::Pointer newbuf = new MemBlob(newsize);
+    if (length() > 0)
+        newbuf->append(buf(), length());
+    store_ = newbuf;
+    off_ = 0;
+    ++stats.cowSlow;
+    debugs(24, 7, id << " new store capacity: " << store_->capacity);
+}
+
+SBuf&
+SBuf::lowAppend(const char * memArea, size_type areaSize)
+{
+    rawSpace(areaSize); //called method also checks n <= maxSize()
+    store_->append(memArea, areaSize);
+    len_ += areaSize;
+    ++stats.append;
+    return *this;
+}
+
+/**
+ * copy-on-write: make sure that we are the only holder of the backing store.
+ * If not, reallocate. If a new size is specified, and it is greater than the
+ * current length, the backing store will be extended as needed
+ */
+void
+SBuf::cow(SBuf::size_type newsize)
+{
+    debugs(24, 8, id << " new size:" << newsize);
+    if (newsize == npos || newsize < length())
+        newsize = length();
+
+    if (store_->LockCount() == 1 && newsize == length()) {
+        debugs(24, 8, id << " no cow needed");
+        ++stats.cowFast;
+        return;
+    }
+    reAlloc(newsize);
+}
+
diff -u -r -N squid-4.0.7/src/sbuf/SBuf.h squid-4.0.8/src/sbuf/SBuf.h
--- squid-4.0.7/src/sbuf/SBuf.h	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/SBuf.h	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,772 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+/* DEBUG: section 24    SBuf */
+
+#ifndef SQUID_SBUF_H
+#define SQUID_SBUF_H
+
+#include "base/InstanceId.h"
+#include "Debug.h"
+#include "globals.h"
+#include "sbuf/Exceptions.h"
+#include "sbuf/MemBlob.h"
+#include "sbuf/Stats.h"
+
+#include <climits>
+#include <cstdarg>
+#include <iosfwd>
+#include <iterator>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+/* SBuf placeholder for printf */
+#ifndef SQUIDSBUFPH
+#define SQUIDSBUFPH "%.*s"
+#define SQUIDSBUFPRINT(s) (s).plength(),(s).rawContent()
+#endif /* SQUIDSBUFPH */
+
+// TODO: move within SBuf and rename
+typedef enum {
+    caseSensitive,
+    caseInsensitive
+} SBufCaseSensitive;
+
+class CharacterSet;
+class SBuf;
+
+/** Forward input const_iterator for SBufs
+ *
+ * Please note that any operation on the underlying SBuf may invalidate
+ * all iterators over it, resulting in undefined behavior by them.
+ */
+class SBufIterator : public std::iterator<std::input_iterator_tag, char>
+{
+public:
+    friend class SBuf;
+    typedef MemBlob::size_type size_type;
+    bool operator==(const SBufIterator &s) const;
+    bool operator!=(const SBufIterator &s) const;
+
+    const char &operator*() const { return *iter; }
+    SBufIterator& operator++() { ++iter; return *this; }
+
+protected:
+    SBufIterator(const SBuf &, size_type);
+
+    const char *iter;
+};
+
+/** Reverse input const_iterator for SBufs
+ *
+ * Please note that any operation on the underlying SBuf may invalidate
+ * all iterators over it, resulting in undefined behavior by them.
+ */
+class SBufReverseIterator : public SBufIterator
+{
+    friend class SBuf;
+public:
+    SBufReverseIterator& operator++() { --iter; return *this;}
+    const char &operator*() const { return *(iter-1); }
+protected:
+    SBufReverseIterator(const SBuf &s, size_type sz) : SBufIterator(s,sz) {}
+};
+
+/**
+ * A String or Buffer.
+ * Features: refcounted backing store, cheap copy and sub-stringing
+ * operations, copy-on-write to isolate change operations to each instance.
+ * Where possible, we're trying to mimic std::string's interface.
+ */
+class SBuf
+{
+public:
+    typedef MemBlob::size_type size_type;
+    typedef SBufIterator const_iterator;
+    typedef SBufReverseIterator const_reverse_iterator;
+    static const size_type npos = 0xffffffff; // max(uint32_t)
+
+    /// Maximum size of a SBuf. By design it MUST be < MAX(size_type)/2. Currently 256Mb.
+    static const size_type maxSize = 0xfffffff;
+
+    /// create an empty (zero-size) SBuf
+    SBuf();
+    SBuf(const SBuf &S);
+#if __cplusplus >= 201103L
+    SBuf(SBuf&& S) : store_(std::move(S.store_)), off_(S.off_), len_(S.len_) {
+        ++stats.moves;
+        S.store_=NULL; //RefCount supports NULL, and S is about to be destructed
+        S.off_=0;
+        S.len_=0;
+    }
+#endif
+
+    /** Constructor: import c-style string
+     *
+     * Create a new SBuf containing a COPY of the contents of the
+     * c-string
+     * \param S the c string to be copied
+     * \param n how many bytes to import into the SBuf. If it is npos
+     *              or unspecified, imports to end-of-cstring
+     * \note it is the caller's responsibility not to go out of bounds
+     * \note bounds is 0 <= pos < length(); caller must pay attention to signedness
+     */
+    explicit SBuf(const char *S, size_type n);
+    explicit SBuf(const char *S);
+
+    /// Constructor: import std::string. Contents are copied.
+    explicit SBuf(const std::string &s);
+
+    ~SBuf();
+
+    /** Explicit assignment.
+     *
+     * Current SBuf will share backing store with the assigned one.
+     */
+    SBuf& assign(const SBuf &S);
+
+    /** Assignment operator.
+     *
+     * Current SBuf will share backing store with the assigned one.
+     */
+    SBuf& operator =(const SBuf & S) {return assign(S);}
+#if __cplusplus >= 201103L
+    SBuf& operator =(SBuf &&S) {
+        ++stats.moves;
+        if (this != &S) {
+            store_ = std::move(S.store_);
+            off_ = S.off_;
+            len_ = S.len_;
+            S.store_ = NULL; //RefCount supports NULL, and S is about to be destructed
+            S.off_ = 0;
+            S.len_ = 0;
+        }
+        return *this;
+    }
+#endif
+
+    /** Import a c-string into a SBuf, copying the data.
+     *
+     * It is the caller's duty to free the imported string, if needed.
+     * \param S the c string to be copied
+     * \param n how many bytes to import into the SBuf. If it is npos
+     *              or unspecified, imports to end-of-cstring
+     * \note it is the caller's responsibility not to go out of bounds
+     * \note to assign a std::string use the pattern:
+     *    assign(stdstr.data(), stdstd.length())
+     */
+    SBuf& assign(const char *S, size_type n);
+    SBuf& assign(const char *S) {return assign(S,npos);}
+
+    /** Assignment operator. Copy a NULL-terminated c-style string into a SBuf.
+     *
+     * Copy a c-style string into a SBuf. Shortcut for SBuf.assign(S)
+     * It is the caller's duty to free the imported string, if needed.
+     * \note not \0-clean
+     */
+    SBuf& operator =(const char *S) {return assign(S);}
+
+    /** reset the SBuf as if it was just created.
+     *
+     * Resets the SBuf to empty, memory is freed lazily.
+     */
+    void clear();
+
+    /** Append operation
+     *
+     * Append the supplied SBuf to the current one; extend storage as needed.
+     */
+    SBuf& append(const SBuf & S);
+
+    /// Append a single character. The character may be NUL (\0).
+    SBuf& append(const char c);
+
+    /** Append operation for C-style strings.
+     *
+     * Append the supplied c-string to the SBuf; extend storage
+     * as needed.
+     *
+     * \param S the c string to be copied. Can be NULL.
+     * \param Ssize how many bytes to import into the SBuf. If it is npos
+     *              or unspecified, imports to end-of-cstring. If S is NULL,
+     *              Ssize is ignored.
+     * \note to append a std::string use the pattern
+     *     cstr_append(stdstr.data(), stdstd.length())
+     */
+    SBuf& append(const char * S, size_type Ssize);
+    SBuf& append(const char * S) { return append(S,npos); }
+
+    /** Assignment operation with printf(3)-style definition
+     * \note arguments may be evaluated more than once, be careful
+     *       of side-effects
+     */
+    SBuf& Printf(const char *fmt, ...);
+
+    /** Append operation with printf-style arguments
+     * \note arguments may be evaluated more than once, be careful
+     *       of side-effects
+     */
+    SBuf& appendf(const char *fmt, ...);
+
+    /** Append operation, with vsprintf(3)-style arguments.
+     * \note arguments may be evaluated more than once, be careful
+     *       of side-effects
+     */
+    SBuf& vappendf(const char *fmt, va_list vargs);
+
+    /// print the SBuf contents to the supplied ostream
+    std::ostream& print(std::ostream &os) const;
+
+    /** print SBuf contents and debug information about the SBuf to an ostream
+     *
+     * Debug function, dumps to a stream informations on the current SBuf,
+     * including low-level details and statistics.
+     */
+    std::ostream& dump(std::ostream &os) const;
+
+    /** random-access read to any char within the SBuf
+     *
+     * does not check access bounds. If you need that, use at()
+     */
+    char operator [](size_type pos) const {++stats.getChar; return store_->mem[off_+pos];}
+
+    /** random-access read to any char within the SBuf.
+     *
+     * \throw OutOfBoundsException when access is out of bounds
+     * \note bounds is 0 <= pos < length(); caller must pay attention to signedness
+     */
+    char at(size_type pos) const {checkAccessBounds(pos); return operator[](pos);}
+
+    /** direct-access set a byte at a specified operation.
+     *
+     * \param pos the position to be overwritten
+     * \param toset the value to be written
+     * \throw OutOfBoundsException when pos is of bounds
+     * \note bounds is 0 <= pos < length(); caller must pay attention to signedness
+     * \note performs a copy-on-write if needed.
+     */
+    void setAt(size_type pos, char toset);
+
+    /** compare to other SBuf, str(case)cmp-style
+     *
+     * \param isCaseSensitive one of caseSensitive or caseInsensitive
+     * \param n compare up to this many bytes. if npos (default), compare whole SBufs
+     * \retval >0 argument of the call is greater than called SBuf
+     * \retval <0 argument of the call is smaller than called SBuf
+     * \retval 0  argument of the call has the same contents of called SBuf
+     */
+    int compare(const SBuf &S, const SBufCaseSensitive isCaseSensitive, const size_type n) const;
+    int compare(const SBuf &S, const SBufCaseSensitive isCaseSensitive) const {
+        return compare(S, isCaseSensitive, npos);
+    }
+
+    /// shorthand version for compare()
+    inline int cmp(const SBuf &S, const size_type n) const {
+        return compare(S,caseSensitive,n);
+    }
+    inline int cmp(const SBuf &S) const {
+        return compare(S,caseSensitive,npos);
+    }
+
+    /// shorthand version for case-insensitive compare()
+    inline int caseCmp(const SBuf &S, const size_type n) const {
+        return compare(S,caseInsensitive,n);
+    }
+    inline int caseCmp(const SBuf &S) const {
+        return compare(S,caseInsensitive,npos);
+    }
+
+    /// Comparison with a C-string.
+    int compare(const char *s, const SBufCaseSensitive isCaseSensitive, const size_type n) const;
+    int compare(const char *s, const SBufCaseSensitive isCaseSensitive) const {
+        return compare(s,isCaseSensitive,npos);
+    }
+
+    /// Shorthand version for C-string compare().
+    inline int cmp(const char *S, const size_type n) const {
+        return compare(S,caseSensitive,n);
+    }
+    inline int cmp(const char *S) const {
+        return compare(S,caseSensitive,npos);
+    }
+
+    /// Shorthand version for case-insensitive C-string compare().
+    inline int caseCmp(const char *S, const size_type n) const {
+        return compare(S,caseInsensitive,n);
+    }
+    inline int caseCmp(const char *S) const {
+        return compare(S,caseInsensitive,npos);
+    }
+
+    /** check whether the entire supplied argument is a prefix of the SBuf.
+     *  \param S the prefix to match against
+     *  \param isCaseSensitive one of caseSensitive or caseInsensitive
+     *  \retval true argument is a prefix of the SBuf
+     */
+    bool startsWith(const SBuf &S, const SBufCaseSensitive isCaseSensitive = caseSensitive) const;
+
+    bool operator ==(const SBuf & S) const;
+    bool operator !=(const SBuf & S) const;
+    bool operator <(const SBuf &S) const {return (cmp(S) < 0);}
+    bool operator >(const SBuf &S) const {return (cmp(S) > 0);}
+    bool operator <=(const SBuf &S) const {return (cmp(S) <= 0);}
+    bool operator >=(const SBuf &S) const {return (cmp(S) >= 0);}
+
+    /** Consume bytes at the head of the SBuf
+     *
+     * Consume N chars at SBuf head, or to SBuf's end,
+     * whichever is shorter. If more bytes are consumed than available,
+     * the SBuf is emptied
+     * \param n how many bytes to remove; could be zero.
+     *     npos (or no argument) means 'to the end of SBuf'
+     * \return a new SBuf containing the consumed bytes.
+     */
+    SBuf consume(size_type n = npos);
+
+    /// gets global statistic informations
+    static const SBufStats& GetStats();
+
+    /** Copy SBuf contents into user-supplied C buffer.
+     *
+     * Export a copy of the SBuf's contents into the user-supplied
+     * buffer, up to the user-supplied-length. No zero-termination is performed
+     * \return num the number of actually-copied chars.
+     */
+    size_type copy(char *dest, size_type n) const;
+
+    /** exports a pointer to the SBuf internal storage.
+     * \warning ACCESSING RAW STORAGE IS DANGEROUS!
+     *
+     * Returns a ead-only pointer to SBuf's content. No terminating null
+     * character is appended (use c_str() for that).
+     * The returned value points to an internal location whose contents
+     * are guaranteed to remain unchanged only until the next call
+     * to a non-constant member function of the SBuf object. Such a
+     * call may be implicit (e.g., when SBuf is destroyed
+     * upon leaving the current context).
+     * This is a very UNSAFE way of accessing the data.
+     * This call never returns NULL.
+     * \see c_str
+     * \note the memory management system guarantees that the exported region
+     *    of memory will remain valid if the caller keeps holding
+     *    a valid reference to the SBuf object and does not write or append to
+     *    it. For example:
+     * \code
+     * SBuf foo("some string");
+     * const char *bar = foo.rawContent();
+     * doSomething(bar); //safe
+     * foo.append(" other string");
+     * doSomething(bar); //unsafe
+     * \endcode
+     */
+    const char* rawContent() const;
+
+    /** Exports a writable pointer to the SBuf internal storage.
+     * \warning Use with EXTREME caution, this is a dangerous operation.
+     *
+     * Returns a pointer to the first unused byte in the SBuf's storage,
+     * which can be be used for appending. At least minSize bytes will
+     * be available for writing.
+     * The returned pointer must not be stored by the caller, as it will
+     * be invalidated by the first call to a non-const method call
+     * on the SBuf.
+     * This call guarantees to never return NULL.
+     * \see reserveSpace
+     * \note Unlike reserveSpace(), this method does not guarantee exclusive
+     *       buffer ownership. It is instead optimized for a one writer
+     *       (appender), many readers scenario by avoiding unnecessary
+     *       copying and allocations.
+     * \throw SBufTooBigException if the user tries to allocate too big a SBuf
+     */
+    char *rawSpace(size_type minSize);
+
+    /** Obtain how much free space is available in the backing store.
+     *
+     * \note: unless the client just cow()ed, it is not guaranteed that
+     *        the free space can be used.
+     */
+    size_type spaceSize() const { return store_->spaceSize(); }
+
+    /** Force a SBuf's size
+     * \warning use with EXTREME caution, this is a dangerous operation
+     *
+     * Adapt the SBuf internal state after external interference
+     * such as writing into it via rawSpace.
+     * \throw TextException if SBuf doesn't have exclusive ownership of store
+     * \throw SBufTooBigException if new size is bigger than available store space
+     */
+    void forceSize(size_type newSize);
+
+    /** exports a null-terminated reference to the SBuf internal storage.
+     * \warning ACCESSING RAW STORAGE IS DANGEROUS! DO NOT EVER USE
+     *  THE RETURNED POINTER FOR WRITING
+     *
+     * The returned value points to an internal location whose contents
+     * are guaranteed to remain unchanged only until the next call
+     * to a non-constant member function of the SBuf object. Such a
+     * call may be implicit (e.g., when SBuf is destroyed
+     * upon leaving the current context).
+     * This is a very UNSAFE way of accessing the data.
+     * This call never returns NULL.
+     * \see rawContent
+     * \note the memory management system guarantees that the exported region
+     *    of memory will remain valid will remain valid only if the
+     *    caller keeps holding a valid reference to the SBuf object and
+     *    does not write or append to it
+     */
+    const char* c_str();
+
+    /// Returns the number of bytes stored in SBuf.
+    size_type length() const {return len_;}
+
+    /** Get the length of the SBuf, as a signed integer
+     *
+     * Compatibility function for printf(3) which requires a signed int
+     * \throw SBufTooBigException if the SBuf is too big for a signed integer
+     */
+    int plength() const {
+        if (length()>INT_MAX)
+            throw SBufTooBigException(__FILE__, __LINE__);
+        return static_cast<int>(length());
+    }
+
+    /** Check whether the SBuf is empty
+     *
+     * \return true if length() == 0
+     */
+    bool isEmpty() const {return (len_==0);}
+
+    /** Request to guarantee the SBuf's free store space.
+     *
+     * After the reserveSpace request, the SBuf is guaranteed to have at
+     * least minSpace bytes of unused backing store following the currently
+     * used portion and single ownership of the backing store.
+     * \throw SBufTooBigException if the user tries to allocate too big a SBuf
+     */
+    void reserveSpace(size_type minSpace) {
+        Must(minSpace <= maxSize);
+        Must(length() <= maxSize - minSpace);
+        reserveCapacity(length()+minSpace);
+    }
+
+    /** Request to guarantee the SBuf's store capacity
+     *
+     * After this method is called, the SBuf is guaranteed to have at least
+     * minCapacity bytes of total buffer size, including the currently-used
+     * portion; it is also guaranteed that after this call this SBuf
+     * has unique ownership of the underlying memory store.
+     * \throw SBufTooBigException if the user tries to allocate too big a SBuf
+     */
+    void reserveCapacity(size_type minCapacity);
+
+    /** slicing method
+     *
+     * Removes SBuf prefix and suffix, leaving a sequence of 'n'
+     * bytes starting from position 'pos', first byte is at pos 0.
+     * It is an in-place-modifying version of substr.
+     * \param pos start sub-stringing from this byte. If it is
+     *      npos or it is greater than the SBuf length, the SBuf is cleared and
+     *      an empty SBuf is returned.
+     * \param n maximum number of bytes of the resulting SBuf.
+     *     npos means "to end of SBuf".
+     *     if it is 0, the SBuf is cleared and an empty SBuf is returned.
+     *     if it overflows the end of the SBuf, it is capped to the end of SBuf
+     * \see substr, trim
+     */
+    SBuf& chop(size_type pos, size_type n = npos);
+
+    /** Remove characters in the toremove set at the beginning, end or both
+     *
+     * \param toremove characters to be removed. Stops chomping at the first
+     *        found char not in the set
+     * \param atBeginning if true (default), strips at the beginning of the SBuf
+     * \param atEnd if true (default), strips at the end of the SBuf
+     */
+    SBuf& trim(const SBuf &toRemove, bool atBeginning = true, bool atEnd = true);
+
+    /** Extract a part of the current SBuf.
+     *
+     * Return a fresh a fresh copy of a portion the current SBuf, which is
+     * left untouched. The same parameter convetions apply as for chop.
+     * \see trim, chop
+     */
+    SBuf substr(size_type pos, size_type n = npos) const;
+
+    /** Find first occurrence of character in SBuf
+     *
+     * Returns the index in the SBuf of the first occurrence of char c.
+     * \return npos if the char was not found
+     * \param startPos if specified, ignore any occurrences before that position
+     *     if startPos is npos or greater than length() npos is always returned
+     *     if startPos is less than zero, it is ignored
+     */
+    size_type find(char c, size_type startPos = 0) const;
+
+    /** Find first occurrence of SBuf in SBuf.
+     *
+     * Returns the index in the SBuf of the first occurrence of the
+     * sequence contained in the str argument.
+     * \param startPos if specified, ignore any occurrences before that position
+     *     if startPos is npos or greater than length() npos is always returned
+     * \return npos if the SBuf was not found
+     */
+    size_type find(const SBuf & str, size_type startPos = 0) const;
+
+    /** Find last occurrence of character in SBuf
+     *
+     * Returns the index in the SBuf of the last occurrence of char c.
+     * \return npos if the char was not found
+     * \param endPos if specified, ignore any occurrences after that position.
+     *   if npos or greater than length(), the whole SBuf is considered
+     */
+    size_type rfind(char c, size_type endPos = npos) const;
+
+    /** Find last occurrence of SBuf in SBuf
+     *
+     * Returns the index in the SBuf of the last occurrence of the
+     * sequence contained in the str argument.
+     * \return npos if the sequence  was not found
+     * \param endPos if specified, ignore any occurrences after that position
+     *   if npos or greater than length(), the whole SBuf is considered
+     */
+    size_type rfind(const SBuf &str, size_type endPos = npos) const;
+
+    /** Find first occurrence of character of set in SBuf
+     *
+     * Finds the first occurrence of ANY of the characters in the supplied set in
+     * the SBuf.
+     * \return npos if no character in the set could be found
+     * \param startPos if specified, ignore any occurrences before that position
+     *   if npos, then npos is always returned
+     *
+     * TODO: rename to camelCase
+     */
+    size_type findFirstOf(const CharacterSet &set, size_type startPos = 0) const;
+
+    /** Find last occurrence of character of set in SBuf
+     *
+     * Finds the last occurrence of ANY of the characters in the supplied set in
+     * the SBuf.
+     * \return npos if no character in the set could be found
+     * \param endPos if specified, ignore any occurrences after that position
+     *   if npos, the entire SBuf is searched
+     */
+    size_type findLastOf(const CharacterSet &set, size_type endPos = npos) const;
+
+    /** Find first occurrence character NOT in character set
+     *
+     * \return npos if all characters in the SBuf are from set
+     * \param startPos if specified, ignore any occurrences before that position
+     *   if npos, then npos is always returned
+     *
+     * TODO: rename to camelCase
+     */
+    size_type findFirstNotOf(const CharacterSet &set, size_type startPos = 0) const;
+
+    /** Find last occurrence character NOT in character set
+     *
+     * \return npos if all characters in the SBuf are from set
+     * \param endPos if specified, ignore any occurrences after that position
+     *   if npos, then the entire SBuf is searched
+     */
+    size_type findLastNotOf(const CharacterSet &set, size_type endPos = npos) const;
+
+    /** sscanf-alike
+     *
+     * sscanf re-implementation. Non-const, and not \0-clean.
+     * \return same as sscanf
+     * \see man sscanf(3)
+     */
+    int scanf(const char *format, ...);
+
+    /// converts all characters to lower case; \see man tolower(3)
+    void toLower();
+
+    /// converts all characters to upper case; \see man toupper(3)
+    void toUpper();
+
+    /// std::string export function
+    std::string toStdString() const { return std::string(buf(),length()); }
+
+    const_iterator begin() const {
+        return const_iterator(*this, 0);
+    }
+
+    const_iterator end() const {
+        return const_iterator(*this, length());
+    }
+
+    const_reverse_iterator rbegin() const {
+        return const_reverse_iterator(*this, length());
+    }
+
+    const_reverse_iterator rend() const {
+        return const_reverse_iterator(*this, 0);
+    }
+
+    // TODO: possibly implement erase() similar to std::string's erase
+    // TODO: possibly implement a replace() call
+private:
+
+    /**
+     * Keeps SBuf's MemBlob alive in a blob-destroying context where
+     * a seemingly unrelated memory pointer may belong to the same blob.
+     * For [an extreme] example, consider: a.append(a).
+     * Compared to an SBuf temporary, this class is optimized to
+     * preserve blobs only if needed and to reduce debugging noise.
+     */
+    class Locker
+    {
+    public:
+        Locker(SBuf *parent, const char *otherBuffer) {
+            // lock if otherBuffer intersects the parents buffer area
+            const MemBlob *blob = parent->store_.getRaw();
+            if (blob->mem <= otherBuffer && otherBuffer < (blob->mem + blob->capacity))
+                locket = blob;
+        }
+    private:
+        MemBlob::Pointer locket;
+    };
+    friend class Locker;
+
+    MemBlob::Pointer store_; ///< memory block, possibly shared with other SBufs
+    size_type off_; ///< our content start offset from the beginning of shared store_
+    size_type len_; ///< number of our content bytes in shared store_
+    static SBufStats stats; ///< class-wide statistics
+
+    /// SBuf object identifier; does not change when contents do,
+    ///   including during assignment
+    const InstanceId<SBuf> id;
+
+    /** obtain prototype store
+     *
+     * Just-created SBufs all share to the same MemBlob.
+     * This call instantiates and returns it.
+     */
+    static MemBlob::Pointer GetStorePrototype();
+
+    /**
+     * obtains a char* to the beginning of this SBuf in memory.
+     * \note the obtained string is NOT null-terminated.
+     */
+    char * buf() const {return (store_->mem+off_);}
+
+    /** returns the pointer to the first char after this SBuf end
+     *
+     *  No checks are made that the space returned is safe, checking that is
+     *  up to the caller.
+     */
+    char * bufEnd() const {return (store_->mem+off_+len_);}
+
+    /**
+     * Try to guesstimate how big a MemBlob to allocate.
+     * The result is guarranteed to be to be at least the desired size.
+     */
+    size_type estimateCapacity(size_type desired) const {return (2*desired);}
+
+    void reAlloc(size_type newsize);
+
+    void cow(size_type minsize = npos);
+
+    void checkAccessBounds(size_type pos) const;
+
+    /** Low-level append operation
+     *
+     * Takes as input a contiguous area of memory and appends its contents
+     * to the SBuf, taking care of memory management. Does no bounds checking
+     * on the supplied memory buffer, it is the duty of the caller to ensure
+     * that the supplied area is valid.
+     */
+    SBuf& lowAppend(const char * memArea, size_type areaSize);
+};
+
+/// ostream output operator
+inline std::ostream &
+operator <<(std::ostream& os, const SBuf& S)
+{
+    return S.print(os);
+}
+
+/// Returns a lower-cased copy of its parameter.
+inline SBuf
+ToUpper(SBuf buf)
+{
+    buf.toUpper();
+    return buf;
+}
+
+/// Returns an upper-cased copy of its parameter.
+inline SBuf
+ToLower(SBuf buf)
+{
+    buf.toLower();
+    return buf;
+}
+
+/**
+ * Copy an SBuf into a C-string.
+ *
+ * Guarantees that the output is a c-string of length
+ * no more than SBuf::length()+1 by appending a \0 byte
+ * to the C-string copy of the SBuf contents.
+ *
+ * \note The destination c-string memory MUST be of at least
+ *       length()+1 bytes.
+ *
+ * No protection is added to prevent \0 bytes within the string.
+ * Unexpectedly short strings are a problem for the receiver
+ * to deal with if it cares.
+ *
+ * Unlike SBuf::c_str() does not alter the SBuf in any way.
+ */
+inline void
+SBufToCstring(char *d, const SBuf &s)
+{
+    s.copy(d, s.length());
+    d[s.length()] = '\0'; // 0-terminate the destination
+    debugs(1, DBG_DATA, "built c-string '" << d << "' from " << s);
+}
+
+/**
+ * Copy an SBuf into a C-string.
+ *
+ * \see SBufToCstring(char *d, const SBuf &s)
+ *
+ * \returns A dynamically allocated c-string based on SBuf.
+ *          Use xfree() / safe_free() to release the c-string.
+ */
+inline char *
+SBufToCstring(const SBuf &s)
+{
+    char *d = static_cast<char*>(xmalloc(s.length()+1));
+    SBufToCstring(d, s);
+    return d;
+}
+
+inline
+SBufIterator::SBufIterator(const SBuf &s, size_type pos)
+    : iter(s.rawContent()+pos)
+{}
+
+inline bool
+SBufIterator::operator==(const SBufIterator &s) const
+{
+    // note: maybe the sbuf comparison is unnecessary?
+    return iter == s.iter;
+}
+
+inline bool
+SBufIterator::operator!=(const SBufIterator &s) const
+{
+    // note: maybe the sbuf comparison is unnecessary?
+    return iter != s.iter;
+}
+
+#endif /* SQUID_SBUF_H */
+
diff -u -r -N squid-4.0.7/src/sbuf/Stats.cc squid-4.0.8/src/sbuf/Stats.cc
--- squid-4.0.7/src/sbuf/Stats.cc	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/Stats.cc	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "sbuf/MemBlob.h"
+#include "sbuf/SBuf.h"
+#include "sbuf/Stats.h"
+
+#include <iostream>
+
+SBufStats::SBufStats()
+    : alloc(0), allocCopy(0), allocFromCString(0),
+      assignFast(0), clear(0), append(0), moves(0), toStream(0), setChar(0),
+      getChar(0), compareSlow(0), compareFast(0), copyOut(0),
+      rawAccess(0), nulTerminate(0), chop(0), trim(0), find(0), scanf(0),
+      caseChange(0), cowFast(0), cowSlow(0), live(0)
+{}
+
+SBufStats&
+SBufStats::operator +=(const SBufStats& ss)
+{
+    alloc += ss.alloc;
+    allocCopy += ss.allocCopy;
+    allocFromCString += ss.allocFromCString;
+    assignFast += ss.assignFast;
+    clear += ss.clear;
+    append += ss.append;
+    moves += ss.moves;
+    toStream += ss.toStream;
+    setChar += ss.setChar;
+    getChar += ss.getChar;
+    compareSlow += ss.compareSlow;
+    compareFast += ss.compareFast;
+    copyOut += ss.copyOut;
+    rawAccess += ss.rawAccess;
+    nulTerminate += ss.nulTerminate;
+    chop += ss.chop;
+    trim += ss.trim;
+    find += ss.find;
+    scanf += ss.scanf;
+    caseChange += ss.caseChange;
+    cowFast += ss.cowFast;
+    cowSlow += ss.cowSlow;
+    live += ss.live;
+
+    return *this;
+}
+
+std::ostream &
+SBufStats::dump(std::ostream& os) const
+{
+    MemBlobStats ststats = MemBlob::GetStats();
+    os <<
+       "SBuf stats:\nnumber of allocations: " << alloc <<
+       "\ncopy-allocations: " << allocCopy <<
+       "\ncopy-allocations from C String: " << allocFromCString <<
+       "\nlive references: " << live <<
+       "\nno-copy assignments: " << assignFast <<
+       "\nclearing operations: " << clear <<
+       "\nappend operations: " << append <<
+       "\nmove operations: " << moves <<
+       "\ndump-to-ostream: " << toStream <<
+       "\nset-char: " << setChar <<
+       "\nget-char: " << getChar <<
+       "\ncomparisons with data-scan: " << compareSlow <<
+       "\ncomparisons not requiring data-scan: " << compareFast <<
+       "\ncopy-out ops: " << copyOut <<
+       "\nraw access to memory: " << rawAccess <<
+       "\nNULL terminate C string: " << nulTerminate <<
+       "\nchop operations: " << chop <<
+       "\ntrim operations: " << trim <<
+       "\nfind: " << find <<
+       "\nscanf: " << scanf <<
+       "\ncase-change ops: " << caseChange <<
+       "\nCOW not actually requiring a copy: " << cowFast <<
+       "\nCOW: " << cowSlow <<
+       "\naverage store share factor: " <<
+       (ststats.live != 0 ? static_cast<float>(live)/ststats.live : 0) <<
+       std::endl;
+    return os;
+}
+
diff -u -r -N squid-4.0.7/src/sbuf/Stats.h squid-4.0.8/src/sbuf/Stats.h
--- squid-4.0.7/src/sbuf/Stats.h	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/Stats.h	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SBUF_STATS_H
+#define SQUID_SBUF_STATS_H
+
+#include <iosfwd>
+
+/**
+ * Container for various SBuf class-wide statistics.
+ *
+ * The stats are not completely accurate; they're mostly meant to
+ * understand whether Squid is leaking resources
+ * and whether SBuf is paying off the expected gains.
+ */
+class SBufStats
+{
+public:
+    uint64_t alloc; ///<number of calls to SBuf constructors
+    uint64_t allocCopy; ///<number of calls to SBuf copy-constructor
+    uint64_t allocFromCString; ///<number of copy-allocations from c-strings
+    uint64_t assignFast; ///<number of no-copy assignment operations
+    uint64_t clear; ///<number of clear operations
+    uint64_t append; ///<number of append operations
+    uint64_t moves; ///<number of move constructions/assignments
+    uint64_t toStream;  ///<number of write operations to ostreams
+    uint64_t setChar; ///<number of calls to setAt
+    uint64_t getChar; ///<number of calls to at() and operator[]
+    uint64_t compareSlow; ///<number of comparison operations requiring data scan
+    uint64_t compareFast; ///<number of comparison operations not requiring data scan
+    uint64_t copyOut; ///<number of data-copies to other forms of buffers
+    uint64_t rawAccess; ///<number of accesses to raw contents
+    uint64_t nulTerminate; ///<number of c_str() terminations
+    uint64_t chop;  ///<number of chop operations
+    uint64_t trim;  ///<number of trim operations
+    uint64_t find;  ///<number of find operations
+    uint64_t scanf;  ///<number of scanf operations
+    uint64_t caseChange; ///<number of toUpper and toLower operations
+    uint64_t cowFast; ///<number of cow operations not actually requiring a copy
+    uint64_t cowSlow; ///<number of cow operations requiring a copy
+    uint64_t live;  ///<number of currently-allocated SBuf
+
+    ///Dump statistics to an ostream.
+    std::ostream& dump(std::ostream &os) const;
+    SBufStats();
+
+    SBufStats& operator +=(const SBufStats&);
+};
+
+#endif /* SQUID_SBUF_STATS_H */
+
diff -u -r -N squid-4.0.7/src/sbuf/Stream.h squid-4.0.8/src/sbuf/Stream.h
--- squid-4.0.7/src/sbuf/Stream.h	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/Stream.h	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SBUFSTREAM_H
+#define SQUID_SBUFSTREAM_H
+
+#include "sbuf/SBuf.h"
+
+#include <ostream>
+
+/** streambuf class for a SBuf-backed stream interface.
+ *
+ * Auxiliary class to be able to leverage an ostream generating SBuf's
+ * analogous to std::ostrstream.
+ */
+class SBufStreamBuf : public std::streambuf
+{
+public:
+    /// initialize streambuf; use supplied SBuf as backing store
+    explicit SBufStreamBuf(SBuf aBuf) : theBuf(aBuf) {}
+
+    /// get a copy of the stream's contents
+    SBuf getBuf() {
+        return theBuf;
+    }
+
+    /// clear the stream's store
+    void clearBuf() {
+        theBuf.clear();
+    }
+
+protected:
+    virtual int_type overflow(int_type aChar = traits_type::eof()) {
+        std::streamsize pending(pptr() - pbase());
+
+        if (pending && sync())
+            return traits_type::eof();
+
+        if (aChar != traits_type::eof()) {
+            char chars[1] = {static_cast<char>(aChar)};
+
+            if (aChar != traits_type::eof())
+                theBuf.append(chars, 1);
+        }
+
+        pbump(-pending);  // Reset pptr().
+        return aChar;
+    }
+
+    /// push the streambuf to the backing SBuf
+    virtual int sync() {
+        std::streamsize pending(pptr() - pbase());
+
+        if (pending)
+            theBuf.append(pbase(), pending);
+
+        return 0;
+    }
+
+    /** write multiple characters to the store entry
+     * \note this is an optimisation consistent with std::streambuf API
+     */
+    virtual std::streamsize xsputn(const char * chars, std::streamsize number) {
+        if (number)
+            theBuf.append(chars, number);
+
+        return number;
+    }
+
+private:
+    SBuf theBuf;
+    SBufStreamBuf(); // no default constructor
+};
+
+/** Stream interface to write to a SBuf.
+ *
+ * Data is appended using standard operator << semantics, and extracted
+ * using the buf() method, in analogy with std::strstream .
+ */
+class SBufStream : public std::ostream
+{
+public:
+    /** Create a SBufStream preinitialized with the contents of a SBuf
+     *
+     * The supplied SBuf copied: in order to retrieve the written-to contents
+     * they must be later fetched using the buf() class method.
+     */
+    SBufStream(SBuf aBuf): std::ostream(0), theBuffer(aBuf) {
+        rdbuf(&theBuffer); // set the buffer to now-initialized theBuffer
+        clear(); //clear badbit set by calling init(0)
+    }
+
+    /// Create an empty SBufStream
+    SBufStream(): std::ostream(0), theBuffer(SBuf()) {
+        rdbuf(&theBuffer); // set the buffer to now-initialized theBuffer
+        clear(); //clear badbit set by calling init(0)
+    }
+
+    /// Retrieve a copy of the current stream status
+    SBuf buf() {
+        flush();
+        return theBuffer.getBuf();
+    }
+
+    /// Clear the stream's backing store
+    SBufStream& clearBuf() {
+        flush();
+        theBuffer.clearBuf();
+        return *this;
+    }
+
+private:
+    SBufStreamBuf theBuffer;
+};
+
+#endif /* SQUID_SBUFSTREAM_H */
+
diff -u -r -N squid-4.0.7/src/sbuf/StringConvert.h squid-4.0.8/src/sbuf/StringConvert.h
--- squid-4.0.7/src/sbuf/StringConvert.h	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/sbuf/StringConvert.h	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_SRC_SBUF_SBUFSTRING_H_
+#define SQUID_SRC_SBUF_SBUFSTRING_H_
+
+#include "sbuf/SBuf.h"
+#include "SquidString.h"
+
+/// create a new SBuf from a String by copying contents
+inline SBuf
+StringToSBuf(const String &s)
+{
+    return SBuf(s.rawBuf(), s.size());
+}
+
+/** create a new String from a SBuf by copying contents
+ * \deprecated
+ */
+inline String
+SBufToString(const SBuf &s)
+{
+    String rv;
+    rv.limitInit(s.rawContent(), s.length());
+    return rv;
+}
+
+#endif /* SQUID_SRC_SBUF_SBUFSTRING_H_ */
+
diff -u -r -N squid-4.0.7/src/SBufAlgos.cc squid-4.0.8/src/SBufAlgos.cc
--- squid-4.0.7/src/SBufAlgos.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/SBufAlgos.cc	1970-01-01 12:00:00.000000000 +1200
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-#include "squid.h"
-#include "SBufAlgos.h"
-
-// private common implementation for SBuf hash variants
-static std::size_t
-SBufHashCommon_ (const SBuf & sbuf, bool caseInsensitive) noexcept
-{
-    //ripped and adapted from hash_string
-    const char *s = sbuf.rawContent();
-    size_t rv = 0;
-    SBuf::size_type len=sbuf.length();
-    while (len != 0) {
-        rv ^= 271 * (caseInsensitive? xtolower(*s) : *s);
-        ++s;
-        --len;
-    }
-    return rv ^ (sbuf.length() * 271);
-}
-
-std::size_t
-std::hash<SBuf>::operator() (const SBuf & sbuf) const noexcept
-{
-    return SBufHashCommon_(sbuf, false);
-}
-
-std::size_t
-CaseInsensitiveSBufHash::operator() (const SBuf & sbuf) const noexcept
-{
-    return SBufHashCommon_(sbuf, true);
-}
-
diff -u -r -N squid-4.0.7/src/SBufAlgos.h squid-4.0.8/src/SBufAlgos.h
--- squid-4.0.7/src/SBufAlgos.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/SBufAlgos.h	1970-01-01 12:00:00.000000000 +1200
@@ -1,107 +0,0 @@
-/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-#ifndef SQUID_SBUFALGOS_H_
-#define SQUID_SBUFALGOS_H_
-
-#include "SBuf.h"
-
-#include <algorithm>
-#include <numeric>
-
-/// SBuf equality predicate for STL algorithms etc
-class SBufEqual
-{
-public:
-    explicit SBufEqual(const SBuf &reference, SBufCaseSensitive sensitivity = caseSensitive) :
-        reference_(reference), sensitivity_(sensitivity) {}
-    bool operator() (const SBuf & checking) { return checking.compare(reference_,sensitivity_) == 0; }
-private:
-    SBuf reference_;
-    SBufCaseSensitive sensitivity_;
-};
-
-/// SBuf "starts with" predicate for STL algorithms etc
-class SBufStartsWith
-{
-public:
-    explicit SBufStartsWith(const SBuf &prefix, SBufCaseSensitive sensitivity = caseSensitive) :
-        prefix_(prefix), sensitivity_(sensitivity) {}
-    bool operator() (const SBuf & checking) { return checking.startsWith(prefix_,sensitivity_); }
-private:
-    SBuf prefix_;
-    SBufCaseSensitive sensitivity_;
-};
-
-/** SBuf size addition accumulator for STL contaniners
- *
- * Equivalent to prefix_length +  SBuf.length() +  separator.length()
- */
-class SBufAddLength
-{
-public:
-    explicit SBufAddLength(const SBuf &separator) :
-        separatorLen_(separator.length()) {}
-    SBuf::size_type operator()(const SBuf::size_type sz, const SBuf & item) {
-        return sz + item.length() + separatorLen_;
-    }
-private:
-    SBuf::size_type separatorLen_;
-};
-
-/// join all the SBuf in a container of SBuf into a single SBuf, separating with separator
-template <class Container>
-SBuf
-SBufContainerJoin(const Container &items, const SBuf& separator)
-{
-    // optimization: pre-calculate needed storage
-    const SBuf::size_type sz = std::accumulate(items.begin(), items.end(), 0, SBufAddLength(separator));
-
-    // sz can be zero in two cases: either items is empty, or all items
-    //  are zero-length. In the former case, we must protect against
-    //  dereferencing the iterator later on, and checking sz is more efficient
-    //  than checking items.size(). This check also provides an optimization
-    //  for the latter case without adding complexity.
-    if (sz == 0)
-        return SBuf();
-
-    SBuf rv;
-    rv.reserveSpace(sz);
-
-    typename Container::const_iterator i(items.begin());
-    rv.append(*i);
-    ++i;
-    for (; i != items.end(); ++i)
-        rv.append(separator).append(*i);
-    return rv;
-}
-
-namespace std {
-/// default hash functor to support std::unordered_map<SBuf,*>
-template <>
-struct hash<SBuf>
-{
-    size_t operator()(const SBuf &) const noexcept;
-};
-}
-
-/** hash functor for SBufs, meant so support case-insensitive std::unordered_map
- *
- * Typical use:
- * \code
- * auto m = std::unordered_map<SBuf, ValueType, CaseInsensitiveSBufHash>();
- * \endcode
- */
-class CaseInsensitiveSBufHash
-{
-public:
-    std::size_t operator()(const SBuf &) const noexcept;
-};
-
-#endif /* SQUID_SBUFALGOS_H_ */
-
diff -u -r -N squid-4.0.7/src/SBuf.cc squid-4.0.8/src/SBuf.cc
--- squid-4.0.7/src/SBuf.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/SBuf.cc	1970-01-01 12:00:00.000000000 +1200
@@ -1,1011 +0,0 @@
-/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-#include "squid.h"
-#include "base/CharacterSet.h"
-#include "base/RefCount.h"
-#include "Debug.h"
-#include "OutOfBoundsException.h"
-#include "SBuf.h"
-#include "SBufDetailedStats.h"
-#include "SBufExceptions.h"
-#include "util.h"
-
-#include <cstring>
-#include <functional>
-#include <iostream>
-#include <sstream>
-
-#ifdef VA_COPY
-#undef VA_COPY
-#endif
-#if defined HAVE_VA_COPY
-#define VA_COPY va_copy
-#elif defined HAVE___VA_COPY
-#define VA_COPY __va_copy
-#endif
-
-InstanceIdDefinitions(SBuf, "SBuf");
-
-SBufStats SBuf::stats;
-const SBuf::size_type SBuf::npos;
-const SBuf::size_type SBuf::maxSize;
-
-SBufStats::SBufStats()
-    : alloc(0), allocCopy(0), allocFromString(0), allocFromCString(0),
-      assignFast(0), clear(0), append(0), moves(0), toStream(0), setChar(0),
-      getChar(0), compareSlow(0), compareFast(0), copyOut(0),
-      rawAccess(0), nulTerminate(0), chop(0), trim(0), find(0), scanf(0),
-      caseChange(0), cowFast(0), cowSlow(0), live(0)
-{}
-
-SBufStats&
-SBufStats::operator +=(const SBufStats& ss)
-{
-    alloc += ss.alloc;
-    allocCopy += ss.allocCopy;
-    allocFromString += ss.allocFromString;
-    allocFromCString += ss.allocFromCString;
-    assignFast += ss.assignFast;
-    clear += ss.clear;
-    append += ss.append;
-    moves += ss.moves;
-    toStream += ss.toStream;
-    setChar += ss.setChar;
-    getChar += ss.getChar;
-    compareSlow += ss.compareSlow;
-    compareFast += ss.compareFast;
-    copyOut += ss.copyOut;
-    rawAccess += ss.rawAccess;
-    nulTerminate += ss.nulTerminate;
-    chop += ss.chop;
-    trim += ss.trim;
-    find += ss.find;
-    scanf += ss.scanf;
-    caseChange += ss.caseChange;
-    cowFast += ss.cowFast;
-    cowSlow += ss.cowSlow;
-    live += ss.live;
-
-    return *this;
-}
-
-SBuf::SBuf()
-    : store_(GetStorePrototype()), off_(0), len_(0)
-{
-    debugs(24, 8, id << " created");
-    ++stats.alloc;
-    ++stats.live;
-}
-
-SBuf::SBuf(const SBuf &S)
-    : store_(S.store_), off_(S.off_), len_(S.len_)
-{
-    debugs(24, 8, id << " created from id " << S.id);
-    ++stats.alloc;
-    ++stats.allocCopy;
-    ++stats.live;
-}
-
-SBuf::SBuf(const String &S)
-    : store_(GetStorePrototype()), off_(0), len_(0)
-{
-    debugs(24, 8, id << " created from string");
-    assign(S.rawBuf(), S.size());
-    ++stats.alloc;
-    ++stats.allocFromString;
-    ++stats.live;
-}
-
-SBuf::SBuf(const std::string &s)
-    : store_(GetStorePrototype()), off_(0), len_(0)
-{
-    debugs(24, 8, id << " created from std::string");
-    lowAppend(s.data(),s.length());
-    ++stats.alloc;
-    ++stats.allocFromString;
-    ++stats.live;
-}
-
-SBuf::SBuf(const char *S, size_type n)
-    : store_(GetStorePrototype()), off_(0), len_(0)
-{
-    append(S,n);
-    ++stats.alloc;
-    ++stats.allocFromCString;
-    ++stats.live;
-}
-
-SBuf::SBuf(const char *S)
-    : store_(GetStorePrototype()), off_(0), len_(0)
-{
-    append(S,npos);
-    ++stats.alloc;
-    ++stats.allocFromCString;
-    ++stats.live;
-}
-
-SBuf::~SBuf()
-{
-    debugs(24, 8, id << " destructed");
-    --stats.live;
-    recordSBufSizeAtDestruct(len_);
-}
-
-MemBlob::Pointer
-SBuf::GetStorePrototype()
-{
-    static MemBlob::Pointer InitialStore = new MemBlob(0);
-    return InitialStore;
-}
-
-SBuf&
-SBuf::assign(const SBuf &S)
-{
-    debugs(24, 7, "assigning " << id << " from " <<  S.id);
-    if (&S == this) //assignment to self. Noop.
-        return *this;
-    ++stats.assignFast;
-    store_ = S.store_;
-    off_ = S.off_;
-    len_ = S.len_;
-    return *this;
-}
-
-SBuf&
-SBuf::assign(const char *S, size_type n)
-{
-    const Locker blobKeeper(this, S);
-    debugs(24, 6, id << " from c-string, n=" << n << ")");
-    clear();
-    return append(S, n); //bounds checked in append()
-}
-
-void
-SBuf::reserveCapacity(size_type minCapacity)
-{
-    Must(minCapacity <= maxSize);
-    cow(minCapacity);
-}
-
-char *
-SBuf::rawSpace(size_type minSpace)
-{
-    Must(length() <= maxSize - minSpace);
-    debugs(24, 7, "reserving " << minSpace << " for " << id);
-    ++stats.rawAccess;
-    // we're not concerned about RefCounts here,
-    // the store knows the last-used portion. If
-    // it's available, we're effectively claiming ownership
-    // of it. If it's not, we need to go away (realloc)
-    if (store_->canAppend(off_+len_, minSpace)) {
-        debugs(24, 7, id << " not growing");
-        return bufEnd();
-    }
-    // TODO: we may try to memmove before realloc'ing in order to avoid
-    //   one allocation operation, if we're the sole owners of a MemBlob.
-    //   Maybe some heuristic on off_ and length()?
-    cow(minSpace+length());
-    return bufEnd();
-}
-
-void
-SBuf::clear()
-{
-#if 0
-    //enabling this code path, the store will be freed and reinitialized
-    store_ = GetStorePrototype(); //uncomment to actually free storage upon clear()
-#else
-    //enabling this code path, we try to release the store without deallocating it.
-    // will be lazily reallocated if needed.
-    if (store_->LockCount() == 1)
-        store_->clear();
-#endif
-    len_ = 0;
-    off_ = 0;
-    ++stats.clear;
-}
-
-SBuf&
-SBuf::append(const SBuf &S)
-{
-    const Locker blobKeeper(this, S.buf());
-    return lowAppend(S.buf(), S.length());
-}
-
-SBuf &
-SBuf::append(const char * S, size_type Ssize)
-{
-    const Locker blobKeeper(this, S);
-    if (S == NULL)
-        return *this;
-    if (Ssize == SBuf::npos)
-        Ssize = strlen(S);
-    debugs(24, 7, "from c-string to id " << id);
-    // coverity[access_dbuff_in_call]
-    return lowAppend(S, Ssize);
-}
-
-SBuf &
-SBuf::append(const char c)
-{
-    return lowAppend(&c, 1);
-}
-
-SBuf&
-SBuf::Printf(const char *fmt, ...)
-{
-    // with printf() the fmt or an arg might be a dangerous char*
-    // NP: cant rely on vappendf() Locker because of clear()
-    const Locker blobKeeper(this, buf());
-
-    va_list args;
-    va_start(args, fmt);
-    clear();
-    vappendf(fmt, args);
-    va_end(args);
-    return *this;
-}
-
-SBuf&
-SBuf::appendf(const char *fmt, ...)
-{
-    va_list args;
-    va_start(args, fmt);
-    vappendf(fmt, args);
-    va_end(args);
-    return *this;
-}
-
-SBuf&
-SBuf::vappendf(const char *fmt, va_list vargs)
-{
-    // with (v)appendf() the fmt or an arg might be a dangerous char*
-    const Locker blobKeeper(this, buf());
-
-    Must(fmt != NULL);
-    int sz = 0;
-    //reserve twice the format-string size, it's a likely heuristic
-    size_type requiredSpaceEstimate = strlen(fmt)*2;
-
-    char *space = rawSpace(requiredSpaceEstimate);
-#ifdef VA_COPY
-    va_list ap;
-    VA_COPY(ap, vargs);
-    sz = vsnprintf(space, spaceSize(), fmt, ap);
-    va_end(ap);
-#else
-    sz = vsnprintf(space, spaceSize(), fmt, vargs);
-#endif
-
-    /* check for possible overflow */
-    /* snprintf on Linux returns -1 on output errors, or the size
-     * that would have been written if enough space had been available */
-    /* vsnprintf is standard in C99 */
-
-    if (sz >= static_cast<int>(spaceSize())) {
-        // not enough space on the first go, we now know how much we need
-        requiredSpaceEstimate = sz*2; // TODO: tune heuristics
-        space = rawSpace(requiredSpaceEstimate);
-        sz = vsnprintf(space, spaceSize(), fmt, vargs);
-        if (sz < 0) // output error in vsnprintf
-            throw TextException("output error in second-go vsnprintf",__FILE__,
-                                __LINE__);
-    }
-
-    if (sz < 0) // output error in either vsnprintf
-        throw TextException("output error in vsnprintf",__FILE__, __LINE__);
-
-    // data was appended, update internal state
-    len_ += sz;
-
-    /* C99 specifies that the final '\0' is not counted in vsnprintf's
-     * return value. Older compilers/libraries might instead count it */
-    /* check whether '\0' was appended and counted */
-    static bool snPrintfTerminatorChecked = false;
-    static bool snPrintfTerminatorCounted = false;
-    if (!snPrintfTerminatorChecked) {
-        char testbuf[16];
-        snPrintfTerminatorCounted = snprintf(testbuf, sizeof(testbuf),
-                                             "%s", "1") == 2;
-        snPrintfTerminatorChecked = true;
-    }
-    if (snPrintfTerminatorCounted) {
-        --sz;
-        --len_;
-    }
-
-    store_->size += sz;
-    ++stats.append;
-
-    return *this;
-}
-
-std::ostream&
-SBuf::print(std::ostream &os) const
-{
-    os.write(buf(), length());
-    ++stats.toStream;
-    return os;
-}
-
-std::ostream&
-SBuf::dump(std::ostream &os) const
-{
-    os << id
-       << ": ";
-    store_->dump(os);
-    os << ", offset:" << off_
-       << ", len:" << len_
-       << ") : '";
-    print(os);
-    os << '\'' << std::endl;
-    return os;
-# if 0
-    // alternate implementation, based on Raw() API.
-    os << Raw("SBuf", buf(), length()) <<
-       ". id: " << id <<
-       ", offset:" << off_ <<
-       ", len:" << len_ <<
-       ", store: ";
-    store_->dump(os);
-    os << std::endl;
-    return os;
-#endif
-}
-
-void
-SBuf::setAt(size_type pos, char toset)
-{
-    checkAccessBounds(pos);
-    cow();
-    store_->mem[off_+pos] = toset;
-    ++stats.setChar;
-}
-
-static int
-memcasecmp(const char *b1, const char *b2, SBuf::size_type len)
-{
-    int rv=0;
-    while (len > 0) {
-        rv = tolower(*b1)-tolower(*b2);
-        if (rv != 0)
-            return rv;
-        ++b1;
-        ++b2;
-        --len;
-    }
-    return rv;
-}
-
-int
-SBuf::compare(const SBuf &S, const SBufCaseSensitive isCaseSensitive, const size_type n) const
-{
-    if (n != npos) {
-        debugs(24, 8, "length specified. substr and recurse");
-        return substr(0,n).compare(S.substr(0,n),isCaseSensitive);
-    }
-
-    const size_type byteCompareLen = min(S.length(), length());
-    ++stats.compareSlow;
-    int rv = 0;
-    debugs(24, 8, "comparing length " << byteCompareLen);
-    if (isCaseSensitive == caseSensitive) {
-        rv = memcmp(buf(), S.buf(), byteCompareLen);
-    } else {
-        rv = memcasecmp(buf(), S.buf(), byteCompareLen);
-    }
-    if (rv != 0) {
-        debugs(24, 8, "result: " << rv);
-        return rv;
-    }
-    if (n <= length() || n <= S.length()) {
-        debugs(24, 8, "same contents and bounded length. Equal");
-        return 0;
-    }
-    if (length() == S.length()) {
-        debugs(24, 8, "same contents and same length. Equal");
-        return 0;
-    }
-    if (length() > S.length()) {
-        debugs(24, 8, "lhs is longer than rhs. Result is 1");
-        return 1;
-    }
-    debugs(24, 8, "rhs is longer than lhs. Result is -1");
-    return -1;
-}
-
-int
-SBuf::compare(const char *s, const SBufCaseSensitive isCaseSensitive, const size_type n) const
-{
-    // 0-length comparison is always true regardless of buffer states
-    if (!n) {
-        ++stats.compareFast;
-        return 0;
-    }
-
-    // N-length compare MUST provide a non-NULL C-string pointer
-    assert(s);
-
-    // when this is a 0-length string, no need for any complexity.
-    if (!length()) {
-        ++stats.compareFast;
-        return '\0' - *s;
-    }
-
-    // brute-force scan in order to avoid ever needing strlen() on a c-string.
-    ++stats.compareSlow;
-    const char *left = buf();
-    const char *right = s;
-    int rv = 0;
-    // what area to scan.
-    // n may be npos, but we treat that as a huge positive value
-    size_type byteCount = min(length(), n);
-
-    // loop until we find a difference, a '\0', or reach the end of area to scan
-    if (isCaseSensitive == caseSensitive) {
-        while ((rv = *left - *right++) == 0) {
-            if (*left++ == '\0' || --byteCount == 0)
-                break;
-        }
-    } else {
-        while ((rv = tolower(*left) - tolower(*right++)) == 0) {
-            if (*left++ == '\0' || --byteCount == 0)
-                break;
-        }
-    }
-
-    // If we stopped scanning because we reached the end
-    //  of buf() before we reached the end of s,
-    // pretend we have a 0-terminator there to compare.
-    // NP: the loop already incremented "right" ready for this comparison
-    if (!byteCount && length() < n)
-        return '\0' - *right;
-
-    // If we found a difference within the scan area,
-    // or we found a '\0',
-    // or all n characters were identical (and none was \0).
-    return rv;
-}
-
-bool
-SBuf::startsWith(const SBuf &S, const SBufCaseSensitive isCaseSensitive) const
-{
-    debugs(24, 8, id << " startsWith " << S.id << ", caseSensitive: " <<
-           isCaseSensitive);
-    if (length() < S.length()) {
-        debugs(24, 8, "no, too short");
-        ++stats.compareFast;
-        return false;
-    }
-    return (compare(S, isCaseSensitive, S.length()) == 0);
-}
-
-bool
-SBuf::operator ==(const SBuf & S) const
-{
-    debugs(24, 8, id << " == " << S.id);
-    if (length() != S.length()) {
-        debugs(24, 8, "no, different lengths");
-        ++stats.compareFast;
-        return false; //shortcut: must be equal length
-    }
-    if (store_ == S.store_ && off_ == S.off_) {
-        debugs(24, 8, "yes, same length and backing store");
-        ++stats.compareFast;
-        return true;  //shortcut: same store, offset and length
-    }
-    ++stats.compareSlow;
-    const bool rv = (0 == memcmp(buf(), S.buf(), length()));
-    debugs(24, 8, "returning " << rv);
-    return rv;
-}
-
-bool
-SBuf::operator !=(const SBuf & S) const
-{
-    return !(*this == S);
-}
-
-SBuf
-SBuf::consume(size_type n)
-{
-    if (n == npos)
-        n = length();
-    else
-        n = min(n, length());
-    debugs(24, 8, id << " consume " << n);
-    SBuf rv(substr(0, n));
-    chop(n);
-    return rv;
-}
-
-const
-SBufStats& SBuf::GetStats()
-{
-    return stats;
-}
-
-SBuf::size_type
-SBuf::copy(char *dest, size_type n) const
-{
-    size_type toexport = min(n,length());
-    memcpy(dest, buf(), toexport);
-    ++stats.copyOut;
-    return toexport;
-}
-
-const char*
-SBuf::rawContent() const
-{
-    ++stats.rawAccess;
-    return buf();
-}
-
-void
-SBuf::forceSize(size_type newSize)
-{
-    debugs(24, 8, id << " force " << (newSize > length() ? "grow" : "shrink") << " to length=" << newSize);
-
-    Must(store_->LockCount() == 1);
-    if (newSize > min(maxSize,store_->capacity-off_))
-        throw SBufTooBigException(__FILE__,__LINE__);
-    len_ = newSize;
-    store_->size = newSize;
-}
-
-const char*
-SBuf::c_str()
-{
-    ++stats.rawAccess;
-    /* null-terminate the current buffer, by hand-appending a \0 at its tail but
-     * without increasing its length. May COW, the side-effect is to guarantee that
-     * the MemBlob's tail is availabe for us to use */
-    *rawSpace(1) = '\0';
-    ++store_->size;
-    ++stats.setChar;
-    ++stats.nulTerminate;
-    return buf();
-}
-
-SBuf&
-SBuf::chop(size_type pos, size_type n)
-{
-    if (pos == npos || pos > length())
-        pos = length();
-
-    if (n == npos || (pos+n) > length())
-        n = length() - pos;
-
-    // if there will be nothing left, reset the buffer while we can
-    if (pos == length() || n == 0) {
-        clear();
-        return *this;
-    }
-
-    ++stats.chop;
-    off_ += pos;
-    len_ = n;
-    return *this;
-}
-
-SBuf&
-SBuf::trim(const SBuf &toRemove, bool atBeginning, bool atEnd)
-{
-    ++stats.trim;
-    if (atEnd) {
-        const char *p = bufEnd()-1;
-        while (!isEmpty() && memchr(toRemove.buf(), *p, toRemove.length()) != NULL) {
-            //current end-of-buf is in the searched set
-            --len_;
-            --p;
-        }
-    }
-    if (atBeginning) {
-        const char *p = buf();
-        while (!isEmpty() && memchr(toRemove.buf(), *p, toRemove.length()) != NULL) {
-            --len_;
-            ++off_;
-            ++p;
-        }
-    }
-    if (isEmpty())
-        clear();
-    return *this;
-}
-
-SBuf
-SBuf::substr(size_type pos, size_type n) const
-{
-    SBuf rv(*this);
-    rv.chop(pos, n); //stats handled by callee
-    return rv;
-}
-
-SBuf::size_type
-SBuf::find(char c, size_type startPos) const
-{
-    ++stats.find;
-
-    if (startPos == npos) // can't find anything if we look past end of SBuf
-        return npos;
-
-    // std::string returns npos if needle is outside hay
-    if (startPos > length())
-        return npos;
-
-    const void *i = memchr(buf()+startPos, (int)c, (size_type)length()-startPos);
-
-    if (i == NULL)
-        return npos;
-
-    return (static_cast<const char *>(i)-buf());
-}
-
-SBuf::size_type
-SBuf::find(const SBuf &needle, size_type startPos) const
-{
-    if (startPos == npos) { // can't find anything if we look past end of SBuf
-        ++stats.find;
-        return npos;
-    }
-
-    // std::string allows needle to overhang hay but not start outside
-    if (startPos > length()) {
-        ++stats.find;
-        return npos;
-    }
-
-    // for empty needle std::string returns startPos
-    if (needle.length() == 0) {
-        ++stats.find;
-        return startPos;
-    }
-
-    // if needle length is 1 use the char search
-    if (needle.length() == 1)
-        return find(needle[0], startPos);
-
-    ++stats.find;
-
-    char *start = buf()+startPos;
-    char *lastPossible = buf()+length()-needle.length()+1;
-    char needleBegin = needle[0];
-
-    debugs(24, 7, "looking for " << needle << "starting at " << startPos <<
-           " in id " << id);
-    while (start < lastPossible) {
-        char *tmp;
-        debugs(24, 8, " begin=" << (void *) start <<
-               ", lastPossible=" << (void*) lastPossible );
-        tmp = static_cast<char *>(memchr(start, needleBegin, lastPossible-start));
-        if (tmp == NULL) {
-            debugs(24, 8 , "First byte not found");
-            return npos;
-        }
-        // lastPossible guarrantees no out-of-bounds with memcmp()
-        if (0 == memcmp(needle.buf(), tmp, needle.length())) {
-            debugs(24, 8, "Found at " << (tmp-buf()));
-            return (tmp-buf());
-        }
-        start = tmp+1;
-    }
-    debugs(24, 8, "not found");
-    return npos;
-}
-
-SBuf::size_type
-SBuf::rfind(const SBuf &needle, SBuf::size_type endPos) const
-{
-    // when the needle is 1 char, use the 1-char rfind()
-    if (needle.length() == 1)
-        return rfind(needle[0], endPos);
-
-    ++stats.find;
-
-    // needle is bigger than haystack, impossible find
-    if (length() < needle.length())
-        return npos;
-
-    // if startPos is npos, std::string scans from the end of hay
-    if (endPos == npos || endPos > length()-needle.length())
-        endPos = length()-needle.length();
-
-    // an empty needle found at the end of the haystack
-    if (needle.length() == 0)
-        return endPos;
-
-    char *bufBegin = buf();
-    char *cur = bufBegin+endPos;
-    const char needleBegin = needle[0];
-    while (cur >= bufBegin) {
-        if (*cur == needleBegin) {
-            if (0 == memcmp(needle.buf(), cur, needle.length())) {
-                // found
-                return (cur-buf());
-            }
-        }
-        --cur;
-    }
-    return npos;
-}
-
-SBuf::size_type
-SBuf::rfind(char c, SBuf::size_type endPos) const
-{
-    ++stats.find;
-
-    // shortcut: haystack is empty, can't find anything by definition
-    if (length() == 0)
-        return npos;
-
-    // on npos input std::string compares last octet of hay
-    if (endPos == npos || endPos >= length()) {
-        endPos = length();
-    } else {
-        // NP: off-by-one weirdness:
-        // endPos is an offset ... 0-based
-        // length() is a count ... 1-based
-        // memrhr() requires a 1-based count of space to scan.
-        ++endPos;
-    }
-
-    if (length() == 0)
-        return endPos;
-
-    const void *i = memrchr(buf(), (int)c, (size_type)endPos);
-
-    if (i == NULL)
-        return npos;
-
-    return (static_cast<const char *>(i)-buf());
-}
-
-SBuf::size_type
-SBuf::findFirstOf(const CharacterSet &set, size_type startPos) const
-{
-    ++stats.find;
-
-    if (startPos == npos)
-        return npos;
-
-    if (startPos >= length())
-        return npos;
-
-    debugs(24, 7, "first of characterset " << set.name << " in id " << id);
-    char *cur = buf()+startPos;
-    const char *bufend = bufEnd();
-    while (cur < bufend) {
-        if (set[*cur])
-            return cur-buf();
-        ++cur;
-    }
-    debugs(24, 7, "not found");
-    return npos;
-}
-
-SBuf::size_type
-SBuf::findFirstNotOf(const CharacterSet &set, size_type startPos) const
-{
-    ++stats.find;
-
-    if (startPos == npos)
-        return npos;
-
-    if (startPos >= length())
-        return npos;
-
-    debugs(24, 7, "first not of characterset " << set.name << " in id " << id);
-    char *cur = buf()+startPos;
-    const char *bufend = bufEnd();
-    while (cur < bufend) {
-        if (!set[*cur])
-            return cur-buf();
-        ++cur;
-    }
-    debugs(24, 7, "not found");
-    return npos;
-}
-
-SBuf::size_type
-SBuf::findLastOf(const CharacterSet &set, size_type endPos) const
-{
-    ++stats.find;
-
-    if (isEmpty())
-        return npos;
-
-    if (endPos == npos || endPos >= length())
-        endPos = length() - 1;
-
-    debugs(24, 7, "last of characterset " << set.name << " in id " << id);
-    const char *start = buf();
-    for (const char *cur = start + endPos; cur >= start; --cur) {
-        if (set[*cur])
-            return cur - start;
-    }
-    debugs(24, 7, "not found");
-    return npos;
-}
-
-SBuf::size_type
-SBuf::findLastNotOf(const CharacterSet &set, size_type endPos) const
-{
-    ++stats.find;
-
-    if (isEmpty())
-        return npos;
-
-    if (endPos == npos || endPos >= length())
-        endPos = length() - 1;
-
-    debugs(24, 7, "last not of characterset " << set.name << " in id " << id);
-    const char *start = buf();
-    for (const char *cur = start + endPos; cur >= start; --cur) {
-        if (!set[*cur])
-            return cur - start;
-    }
-    debugs(24, 7, "not found");
-    return npos;
-}
-
-/*
- * TODO: borrow a sscanf implementation from Linux or similar?
- * we'd really need a vsnscanf(3)... ? As an alternative, a
- * light-regexp-like domain-specific syntax might be an idea.
- */
-int
-SBuf::scanf(const char *format, ...)
-{
-    // with the format or an arg might be a dangerous char*
-    // that gets invalidated by c_str()
-    const Locker blobKeeper(this, buf());
-
-    va_list arg;
-    int rv;
-    ++stats.scanf;
-    va_start(arg, format);
-    rv = vsscanf(c_str(), format, arg);
-    va_end(arg);
-    return rv;
-}
-
-std::ostream &
-SBufStats::dump(std::ostream& os) const
-{
-    MemBlobStats ststats = MemBlob::GetStats();
-    os <<
-       "SBuf stats:\nnumber of allocations: " << alloc <<
-       "\ncopy-allocations: " << allocCopy <<
-       "\ncopy-allocations from SquidString: " << allocFromString <<
-       "\ncopy-allocations from C String: " << allocFromCString <<
-       "\nlive references: " << live <<
-       "\nno-copy assignments: " << assignFast <<
-       "\nclearing operations: " << clear <<
-       "\nappend operations: " << append <<
-       "\nmove operations: " << moves <<
-       "\ndump-to-ostream: " << toStream <<
-       "\nset-char: " << setChar <<
-       "\nget-char: " << getChar <<
-       "\ncomparisons with data-scan: " << compareSlow <<
-       "\ncomparisons not requiring data-scan: " << compareFast <<
-       "\ncopy-out ops: " << copyOut <<
-       "\nraw access to memory: " << rawAccess <<
-       "\nNULL terminate C string: " << nulTerminate <<
-       "\nchop operations: " << chop <<
-       "\ntrim operations: " << trim <<
-       "\nfind: " << find <<
-       "\nscanf: " << scanf <<
-       "\ncase-change ops: " << caseChange <<
-       "\nCOW not actually requiring a copy: " << cowFast <<
-       "\nCOW: " << cowSlow <<
-       "\naverage store share factor: " <<
-       (ststats.live != 0 ? static_cast<float>(live)/ststats.live : 0) <<
-       std::endl;
-    return os;
-}
-
-void
-SBuf::toLower()
-{
-    debugs(24, 8, "\"" << *this << "\"");
-    for (size_type j = 0; j < length(); ++j) {
-        const int c = (*this)[j];
-        if (isupper(c))
-            setAt(j, tolower(c));
-    }
-    debugs(24, 8, "result: \"" << *this << "\"");
-    ++stats.caseChange;
-}
-
-void
-SBuf::toUpper()
-{
-    debugs(24, 8, "\"" << *this << "\"");
-    for (size_type j = 0; j < length(); ++j) {
-        const int c = (*this)[j];
-        if (islower(c))
-            setAt(j, toupper(c));
-    }
-    debugs(24, 8, "result: \"" << *this << "\"");
-    ++stats.caseChange;
-}
-
-/**
- * checks whether the requested 'pos' is within the bounds of the SBuf
- * \throw OutOfBoundsException if access is out of bounds
- */
-void
-SBuf::checkAccessBounds(size_type pos) const
-{
-    if (pos >= length())
-        throw OutOfBoundsException(*this, pos, __FILE__, __LINE__);
-}
-
-String
-SBuf::toString() const
-{
-    String rv;
-    rv.limitInit(buf(), length());
-    ++stats.copyOut;
-    return rv;
-}
-
-/** re-allocate the backing store of the SBuf.
- *
- * If there are contents in the SBuf, they will be copied over.
- * NO verifications are made on the size parameters, it's up to the caller to
- * make sure that the new size is big enough to hold the copied contents.
- * The re-allocated storage MAY be bigger than the requested size due to size-chunking
- * algorithms in MemBlock, it is guarranteed NOT to be smaller.
- */
-void
-SBuf::reAlloc(size_type newsize)
-{
-    debugs(24, 8, id << " new size: " << newsize);
-    if (newsize > maxSize)
-        throw SBufTooBigException(__FILE__, __LINE__);
-    MemBlob::Pointer newbuf = new MemBlob(newsize);
-    if (length() > 0)
-        newbuf->append(buf(), length());
-    store_ = newbuf;
-    off_ = 0;
-    ++stats.cowSlow;
-    debugs(24, 7, id << " new store capacity: " << store_->capacity);
-}
-
-SBuf&
-SBuf::lowAppend(const char * memArea, size_type areaSize)
-{
-    rawSpace(areaSize); //called method also checks n <= maxSize()
-    store_->append(memArea, areaSize);
-    len_ += areaSize;
-    ++stats.append;
-    return *this;
-}
-
-/**
- * copy-on-write: make sure that we are the only holder of the backing store.
- * If not, reallocate. If a new size is specified, and it is greater than the
- * current length, the backing store will be extended as needed
- */
-void
-SBuf::cow(SBuf::size_type newsize)
-{
-    debugs(24, 8, id << " new size:" << newsize);
-    if (newsize == npos || newsize < length())
-        newsize = length();
-
-    if (store_->LockCount() == 1 && newsize == length()) {
-        debugs(24, 8, id << " no cow needed");
-        ++stats.cowFast;
-        return;
-    }
-    reAlloc(newsize);
-}
-
diff -u -r -N squid-4.0.7/src/SBufDetailedStats.cc squid-4.0.8/src/SBufDetailedStats.cc
--- squid-4.0.7/src/SBufDetailedStats.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/SBufDetailedStats.cc	1970-01-01 12:00:00.000000000 +1200
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-#include "squid.h"
-#include "SBufDetailedStats.h"
-#include "StatHist.h"
-
-/*
- * Implementation note: the purpose of this construct is to avoid adding
- * external dependencies to the SBuf code
- */
-
-static StatHist sbufDestructTimeStats;
-static StatHist memblobDestructTimeStats;
-
-namespace SBufDetailedStatsHistInitializer
-{
-// run the post-instantiation initialization methods for StatHist objects
-struct Initializer {
-    Initializer() {
-        sbufDestructTimeStats.logInit(100,30.0,128000.0);
-        memblobDestructTimeStats.logInit(100,30.0,128000.0);
-    }
-};
-Initializer initializer;
-}
-
-void
-recordSBufSizeAtDestruct(SBuf::size_type sz)
-{
-    sbufDestructTimeStats.count(static_cast<double>(sz));
-}
-
-const StatHist *
-collectSBufDestructTimeStats()
-{
-    return &sbufDestructTimeStats;
-}
-
-void
-recordMemBlobSizeAtDestruct(SBuf::size_type sz)
-{
-    memblobDestructTimeStats.count(static_cast<double>(sz));
-}
-
-const StatHist *
-collectMemBlobDestructTimeStats()
-{
-    return &memblobDestructTimeStats;
-}
-
diff -u -r -N squid-4.0.7/src/SBufDetailedStats.h squid-4.0.8/src/SBufDetailedStats.h
--- squid-4.0.7/src/SBufDetailedStats.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/SBufDetailedStats.h	1970-01-01 12:00:00.000000000 +1200
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-#ifndef SQUID_SBUFDETAILEDSTATS_H
-#define SQUID_SBUFDETAILEDSTATS_H
-
-#include "SBuf.h"
-
-class StatHist;
-
-/// Record the size a SBuf had when it was destructed
-void recordSBufSizeAtDestruct(SBuf::size_type sz);
-
-/** Collect the SBuf size-at-destruct-time histogram
- *
- * \note the returned StatHist object must not be freed
- */
-const StatHist * collectSBufDestructTimeStats();
-
-/// Record the size a MemBlob had when it was destructed
-void recordMemBlobSizeAtDestruct(MemBlob::size_type sz);
-
-/** Collect the MemBlob size-at-destruct-time histogram
- *
- * \note the returned StatHist object must not be freed
- */
-const StatHist * collectMemBlobDestructTimeStats();
-
-#endif /* SQUID_SBUFDETAILEDSTATS_H */
-
diff -u -r -N squid-4.0.7/src/SBufExceptions.cc squid-4.0.8/src/SBufExceptions.cc
--- squid-4.0.7/src/SBufExceptions.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/SBufExceptions.cc	1970-01-01 12:00:00.000000000 +1200
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-#include "squid.h"
-#include "OutOfBoundsException.h"
-#include "SBuf.h"
-#include "SBufExceptions.h"
-
-OutOfBoundsException::OutOfBoundsException(const SBuf &throwingBuf,
-        SBuf::size_type &pos,
-        const char *aFileName, int aLineNo)
-    : TextException(NULL, aFileName, aLineNo),
-      theThrowingBuf(throwingBuf),
-      accessedPosition(pos)
-{
-    SBuf explanatoryText("OutOfBoundsException");
-    if (aLineNo != -1)
-        explanatoryText.appendf(" at line %d", aLineNo);
-    if (aFileName != NULL)
-        explanatoryText.appendf(" in file %s", aFileName);
-    explanatoryText.appendf(" while accessing position %d in a SBuf long %d",
-                            pos, throwingBuf.length());
-    // we can safely alias c_str as both are local to the object
-    //  and will not further manipulated.
-    message = xstrndup(explanatoryText.c_str(),explanatoryText.length());
-}
-
-OutOfBoundsException::~OutOfBoundsException() throw()
-{ }
-
-InvalidParamException::InvalidParamException(const char *aFilename, int aLineNo)
-    : TextException("Invalid parameter", aFilename, aLineNo)
-{ }
-
-SBufTooBigException::SBufTooBigException(const char *aFilename, int aLineNo)
-    : TextException("Trying to create an oversize SBuf", aFilename, aLineNo)
-{ }
-
diff -u -r -N squid-4.0.7/src/SBufExceptions.h squid-4.0.8/src/SBufExceptions.h
--- squid-4.0.7/src/SBufExceptions.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/SBufExceptions.h	1970-01-01 12:00:00.000000000 +1200
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-#ifndef SQUID_SBUFEXCEPTIONS_H
-#define SQUID_SBUFEXCEPTIONS_H
-
-#include "base/TextException.h"
-
-/**
- * Exception raised when call parameters are not valid
- * \todo move to an Exceptions.h?
- */
-class InvalidParamException : public TextException
-{
-public:
-    explicit InvalidParamException(const char *aFilename = 0, int aLineNo = -1);
-};
-
-/**
- * Exception raised when an attempt to resize a SBuf would cause it to reserve too big
- */
-class SBufTooBigException : public TextException
-{
-public:
-    explicit SBufTooBigException(const char *aFilename = 0, int aLineNo = -1);
-};
-
-#endif /* SQUID_SBUFEXCEPTIONS_H */
-
diff -u -r -N squid-4.0.7/src/SBuf.h squid-4.0.8/src/SBuf.h
--- squid-4.0.7/src/SBuf.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/SBuf.h	1970-01-01 12:00:00.000000000 +1200
@@ -1,826 +0,0 @@
-/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-/* DEBUG: section 24    SBuf */
-
-#ifndef SQUID_SBUF_H
-#define SQUID_SBUF_H
-
-#include "base/InstanceId.h"
-#include "Debug.h"
-#include "globals.h"
-#include "MemBlob.h"
-#include "SBufExceptions.h"
-#include "SquidString.h"
-
-#include <climits>
-#include <cstdarg>
-#include <iosfwd>
-#include <iterator>
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-/* SBuf placeholder for printf */
-#ifndef SQUIDSBUFPH
-#define SQUIDSBUFPH "%.*s"
-#define SQUIDSBUFPRINT(s) (s).plength(),(s).rawContent()
-#endif /* SQUIDSBUFPH */
-
-// TODO: move within SBuf and rename
-typedef enum {
-    caseSensitive,
-    caseInsensitive
-} SBufCaseSensitive;
-
-/**
- * Container for various SBuf class-wide statistics.
- *
- * The stats are not completely accurate; they're mostly meant to
- * understand whether Squid is leaking resources
- * and whether SBuf is paying off the expected gains.
- */
-class SBufStats
-{
-public:
-    uint64_t alloc; ///<number of calls to SBuf constructors
-    uint64_t allocCopy; ///<number of calls to SBuf copy-constructor
-    uint64_t allocFromString; ///<number of copy-allocations from Strings
-    uint64_t allocFromCString; ///<number of copy-allocations from c-strings
-    uint64_t assignFast; ///<number of no-copy assignment operations
-    uint64_t clear; ///<number of clear operations
-    uint64_t append; ///<number of append operations
-    uint64_t moves; ///<number of move constructions/assignments
-    uint64_t toStream;  ///<number of write operations to ostreams
-    uint64_t setChar; ///<number of calls to setAt
-    uint64_t getChar; ///<number of calls to at() and operator[]
-    uint64_t compareSlow; ///<number of comparison operations requiring data scan
-    uint64_t compareFast; ///<number of comparison operations not requiring data scan
-    uint64_t copyOut; ///<number of data-copies to other forms of buffers
-    uint64_t rawAccess; ///<number of accesses to raw contents
-    uint64_t nulTerminate; ///<number of c_str() terminations
-    uint64_t chop;  ///<number of chop operations
-    uint64_t trim;  ///<number of trim operations
-    uint64_t find;  ///<number of find operations
-    uint64_t scanf;  ///<number of scanf operations
-    uint64_t caseChange; ///<number of toUpper and toLower operations
-    uint64_t cowFast; ///<number of cow operations not actually requiring a copy
-    uint64_t cowSlow; ///<number of cow operations requiring a copy
-    uint64_t live;  ///<number of currently-allocated SBuf
-
-    ///Dump statistics to an ostream.
-    std::ostream& dump(std::ostream &os) const;
-    SBufStats();
-
-    SBufStats& operator +=(const SBufStats&);
-};
-
-class CharacterSet;
-class SBuf;
-
-/** Forward input const_iterator for SBufs
- *
- * Please note that any operation on the underlying SBuf may invalidate
- * all iterators over it, resulting in undefined behavior by them.
- */
-class SBufIterator : public std::iterator<std::input_iterator_tag, char>
-{
-public:
-    friend class SBuf;
-    typedef MemBlob::size_type size_type;
-    bool operator==(const SBufIterator &s) const;
-    bool operator!=(const SBufIterator &s) const;
-
-    const char &operator*() const { return *iter; }
-    SBufIterator& operator++() { ++iter; return *this; }
-
-protected:
-    SBufIterator(const SBuf &, size_type);
-
-    const char *iter;
-};
-
-/** Reverse input const_iterator for SBufs
- *
- * Please note that any operation on the underlying SBuf may invalidate
- * all iterators over it, resulting in undefined behavior by them.
- */
-class SBufReverseIterator : public SBufIterator
-{
-    friend class SBuf;
-public:
-    SBufReverseIterator& operator++() { --iter; return *this;}
-    const char &operator*() const { return *(iter-1); }
-protected:
-    SBufReverseIterator(const SBuf &s, size_type sz) : SBufIterator(s,sz) {}
-};
-
-/**
- * A String or Buffer.
- * Features: refcounted backing store, cheap copy and sub-stringing
- * operations, copy-on-write to isolate change operations to each instance.
- * Where possible, we're trying to mimic std::string's interface.
- */
-class SBuf
-{
-public:
-    typedef MemBlob::size_type size_type;
-    typedef SBufIterator const_iterator;
-    typedef SBufReverseIterator const_reverse_iterator;
-    static const size_type npos = 0xffffffff; // max(uint32_t)
-
-    /// Maximum size of a SBuf. By design it MUST be < MAX(size_type)/2. Currently 256Mb.
-    static const size_type maxSize = 0xfffffff;
-
-    /// create an empty (zero-size) SBuf
-    SBuf();
-    SBuf(const SBuf &S);
-#if __cplusplus >= 201103L
-    SBuf(SBuf&& S) : store_(std::move(S.store_)), off_(S.off_), len_(S.len_) {
-        ++stats.moves;
-        S.store_=NULL; //RefCount supports NULL, and S is about to be destructed
-        S.off_=0;
-        S.len_=0;
-    }
-#endif
-
-    /** Constructor: import c-style string
-     *
-     * Create a new SBuf containing a COPY of the contents of the
-     * c-string
-     * \param S the c string to be copied
-     * \param n how many bytes to import into the SBuf. If it is npos
-     *              or unspecified, imports to end-of-cstring
-     * \note it is the caller's responsibility not to go out of bounds
-     * \note bounds is 0 <= pos < length(); caller must pay attention to signedness
-     */
-    explicit SBuf(const char *S, size_type n);
-    explicit SBuf(const char *S);
-
-    /** Constructor: import SquidString, copying contents.
-     *
-     * This method will be removed once SquidString has gone.
-     */
-    explicit SBuf(const String &S);
-
-    /// Constructor: import std::string. Contents are copied.
-    explicit SBuf(const std::string &s);
-
-    ~SBuf();
-
-    /** Explicit assignment.
-     *
-     * Current SBuf will share backing store with the assigned one.
-     */
-    SBuf& assign(const SBuf &S);
-
-    /** Assignment operator.
-     *
-     * Current SBuf will share backing store with the assigned one.
-     */
-    SBuf& operator =(const SBuf & S) {return assign(S);}
-#if __cplusplus >= 201103L
-    SBuf& operator =(SBuf &&S) {
-        ++stats.moves;
-        if (this != &S) {
-            store_ = std::move(S.store_);
-            off_ = S.off_;
-            len_ = S.len_;
-            S.store_ = NULL; //RefCount supports NULL, and S is about to be destructed
-            S.off_ = 0;
-            S.len_ = 0;
-        }
-        return *this;
-    }
-#endif
-
-    /** Import a c-string into a SBuf, copying the data.
-     *
-     * It is the caller's duty to free the imported string, if needed.
-     * \param S the c string to be copied
-     * \param n how many bytes to import into the SBuf. If it is npos
-     *              or unspecified, imports to end-of-cstring
-     * \note it is the caller's responsibility not to go out of bounds
-     * \note to assign a std::string use the pattern:
-     *    assign(stdstr.data(), stdstd.length())
-     */
-    SBuf& assign(const char *S, size_type n);
-    SBuf& assign(const char *S) {return assign(S,npos);}
-
-    /** Assignment operator. Copy a NULL-terminated c-style string into a SBuf.
-     *
-     * Copy a c-style string into a SBuf. Shortcut for SBuf.assign(S)
-     * It is the caller's duty to free the imported string, if needed.
-     * \note not \0-clean
-     */
-    SBuf& operator =(const char *S) {return assign(S);}
-
-    /** reset the SBuf as if it was just created.
-     *
-     * Resets the SBuf to empty, memory is freed lazily.
-     */
-    void clear();
-
-    /** Append operation
-     *
-     * Append the supplied SBuf to the current one; extend storage as needed.
-     */
-    SBuf& append(const SBuf & S);
-
-    /// Append a single character. The character may be NUL (\0).
-    SBuf& append(const char c);
-
-    /** Append operation for C-style strings.
-     *
-     * Append the supplied c-string to the SBuf; extend storage
-     * as needed.
-     *
-     * \param S the c string to be copied. Can be NULL.
-     * \param Ssize how many bytes to import into the SBuf. If it is npos
-     *              or unspecified, imports to end-of-cstring. If S is NULL,
-     *              Ssize is ignored.
-     * \note to append a std::string use the pattern
-     *     cstr_append(stdstr.data(), stdstd.length())
-     */
-    SBuf& append(const char * S, size_type Ssize);
-    SBuf& append(const char * S) { return append(S,npos); }
-
-    /** Assignment operation with printf(3)-style definition
-     * \note arguments may be evaluated more than once, be careful
-     *       of side-effects
-     */
-    SBuf& Printf(const char *fmt, ...);
-
-    /** Append operation with printf-style arguments
-     * \note arguments may be evaluated more than once, be careful
-     *       of side-effects
-     */
-    SBuf& appendf(const char *fmt, ...);
-
-    /** Append operation, with vsprintf(3)-style arguments.
-     * \note arguments may be evaluated more than once, be careful
-     *       of side-effects
-     */
-    SBuf& vappendf(const char *fmt, va_list vargs);
-
-    /// print the SBuf contents to the supplied ostream
-    std::ostream& print(std::ostream &os) const;
-
-    /** print SBuf contents and debug information about the SBuf to an ostream
-     *
-     * Debug function, dumps to a stream informations on the current SBuf,
-     * including low-level details and statistics.
-     */
-    std::ostream& dump(std::ostream &os) const;
-
-    /** random-access read to any char within the SBuf
-     *
-     * does not check access bounds. If you need that, use at()
-     */
-    char operator [](size_type pos) const {++stats.getChar; return store_->mem[off_+pos];}
-
-    /** random-access read to any char within the SBuf.
-     *
-     * \throw OutOfBoundsException when access is out of bounds
-     * \note bounds is 0 <= pos < length(); caller must pay attention to signedness
-     */
-    char at(size_type pos) const {checkAccessBounds(pos); return operator[](pos);}
-
-    /** direct-access set a byte at a specified operation.
-     *
-     * \param pos the position to be overwritten
-     * \param toset the value to be written
-     * \throw OutOfBoundsException when pos is of bounds
-     * \note bounds is 0 <= pos < length(); caller must pay attention to signedness
-     * \note performs a copy-on-write if needed.
-     */
-    void setAt(size_type pos, char toset);
-
-    /** compare to other SBuf, str(case)cmp-style
-     *
-     * \param isCaseSensitive one of caseSensitive or caseInsensitive
-     * \param n compare up to this many bytes. if npos (default), compare whole SBufs
-     * \retval >0 argument of the call is greater than called SBuf
-     * \retval <0 argument of the call is smaller than called SBuf
-     * \retval 0  argument of the call has the same contents of called SBuf
-     */
-    int compare(const SBuf &S, const SBufCaseSensitive isCaseSensitive, const size_type n) const;
-    int compare(const SBuf &S, const SBufCaseSensitive isCaseSensitive) const {
-        return compare(S, isCaseSensitive, npos);
-    }
-
-    /// shorthand version for compare()
-    inline int cmp(const SBuf &S, const size_type n) const {
-        return compare(S,caseSensitive,n);
-    }
-    inline int cmp(const SBuf &S) const {
-        return compare(S,caseSensitive,npos);
-    }
-
-    /// shorthand version for case-insensitive compare()
-    inline int caseCmp(const SBuf &S, const size_type n) const {
-        return compare(S,caseInsensitive,n);
-    }
-    inline int caseCmp(const SBuf &S) const {
-        return compare(S,caseInsensitive,npos);
-    }
-
-    /// Comparison with a C-string.
-    int compare(const char *s, const SBufCaseSensitive isCaseSensitive, const size_type n) const;
-    int compare(const char *s, const SBufCaseSensitive isCaseSensitive) const {
-        return compare(s,isCaseSensitive,npos);
-    }
-
-    /// Shorthand version for C-string compare().
-    inline int cmp(const char *S, const size_type n) const {
-        return compare(S,caseSensitive,n);
-    }
-    inline int cmp(const char *S) const {
-        return compare(S,caseSensitive,npos);
-    }
-
-    /// Shorthand version for case-insensitive C-string compare().
-    inline int caseCmp(const char *S, const size_type n) const {
-        return compare(S,caseInsensitive,n);
-    }
-    inline int caseCmp(const char *S) const {
-        return compare(S,caseInsensitive,npos);
-    }
-
-    /** check whether the entire supplied argument is a prefix of the SBuf.
-     *  \param S the prefix to match against
-     *  \param isCaseSensitive one of caseSensitive or caseInsensitive
-     *  \retval true argument is a prefix of the SBuf
-     */
-    bool startsWith(const SBuf &S, const SBufCaseSensitive isCaseSensitive = caseSensitive) const;
-
-    bool operator ==(const SBuf & S) const;
-    bool operator !=(const SBuf & S) const;
-    bool operator <(const SBuf &S) const {return (cmp(S) < 0);}
-    bool operator >(const SBuf &S) const {return (cmp(S) > 0);}
-    bool operator <=(const SBuf &S) const {return (cmp(S) <= 0);}
-    bool operator >=(const SBuf &S) const {return (cmp(S) >= 0);}
-
-    /** Consume bytes at the head of the SBuf
-     *
-     * Consume N chars at SBuf head, or to SBuf's end,
-     * whichever is shorter. If more bytes are consumed than available,
-     * the SBuf is emptied
-     * \param n how many bytes to remove; could be zero.
-     *     npos (or no argument) means 'to the end of SBuf'
-     * \return a new SBuf containing the consumed bytes.
-     */
-    SBuf consume(size_type n = npos);
-
-    /// gets global statistic informations
-    static const SBufStats& GetStats();
-
-    /** Copy SBuf contents into user-supplied C buffer.
-     *
-     * Export a copy of the SBuf's contents into the user-supplied
-     * buffer, up to the user-supplied-length. No zero-termination is performed
-     * \return num the number of actually-copied chars.
-     */
-    size_type copy(char *dest, size_type n) const;
-
-    /** exports a pointer to the SBuf internal storage.
-     * \warning ACCESSING RAW STORAGE IS DANGEROUS!
-     *
-     * Returns a ead-only pointer to SBuf's content. No terminating null
-     * character is appended (use c_str() for that).
-     * The returned value points to an internal location whose contents
-     * are guaranteed to remain unchanged only until the next call
-     * to a non-constant member function of the SBuf object. Such a
-     * call may be implicit (e.g., when SBuf is destroyed
-     * upon leaving the current context).
-     * This is a very UNSAFE way of accessing the data.
-     * This call never returns NULL.
-     * \see c_str
-     * \note the memory management system guarantees that the exported region
-     *    of memory will remain valid if the caller keeps holding
-     *    a valid reference to the SBuf object and does not write or append to
-     *    it. For example:
-     * \code
-     * SBuf foo("some string");
-     * const char *bar = foo.rawContent();
-     * doSomething(bar); //safe
-     * foo.append(" other string");
-     * doSomething(bar); //unsafe
-     * \endcode
-     */
-    const char* rawContent() const;
-
-    /** Exports a writable pointer to the SBuf internal storage.
-     * \warning Use with EXTREME caution, this is a dangerous operation.
-     *
-     * Returns a pointer to the first unused byte in the SBuf's storage,
-     * which can be be used for appending. At least minSize bytes will
-     * be available for writing.
-     * The returned pointer must not be stored by the caller, as it will
-     * be invalidated by the first call to a non-const method call
-     * on the SBuf.
-     * This call guarantees to never return NULL.
-     * \see reserveSpace
-     * \note Unlike reserveSpace(), this method does not guarantee exclusive
-     *       buffer ownership. It is instead optimized for a one writer
-     *       (appender), many readers scenario by avoiding unnecessary
-     *       copying and allocations.
-     * \throw SBufTooBigException if the user tries to allocate too big a SBuf
-     */
-    char *rawSpace(size_type minSize);
-
-    /** Obtain how much free space is available in the backing store.
-     *
-     * \note: unless the client just cow()ed, it is not guaranteed that
-     *        the free space can be used.
-     */
-    size_type spaceSize() const { return store_->spaceSize(); }
-
-    /** Force a SBuf's size
-     * \warning use with EXTREME caution, this is a dangerous operation
-     *
-     * Adapt the SBuf internal state after external interference
-     * such as writing into it via rawSpace.
-     * \throw TextException if SBuf doesn't have exclusive ownership of store
-     * \throw SBufTooBigException if new size is bigger than available store space
-     */
-    void forceSize(size_type newSize);
-
-    /** exports a null-terminated reference to the SBuf internal storage.
-     * \warning ACCESSING RAW STORAGE IS DANGEROUS! DO NOT EVER USE
-     *  THE RETURNED POINTER FOR WRITING
-     *
-     * The returned value points to an internal location whose contents
-     * are guaranteed to remain unchanged only until the next call
-     * to a non-constant member function of the SBuf object. Such a
-     * call may be implicit (e.g., when SBuf is destroyed
-     * upon leaving the current context).
-     * This is a very UNSAFE way of accessing the data.
-     * This call never returns NULL.
-     * \see rawContent
-     * \note the memory management system guarantees that the exported region
-     *    of memory will remain valid will remain valid only if the
-     *    caller keeps holding a valid reference to the SBuf object and
-     *    does not write or append to it
-     */
-    const char* c_str();
-
-    /// Returns the number of bytes stored in SBuf.
-    size_type length() const {return len_;}
-
-    /** Get the length of the SBuf, as a signed integer
-     *
-     * Compatibility function for printf(3) which requires a signed int
-     * \throw SBufTooBigException if the SBuf is too big for a signed integer
-     */
-    int plength() const {
-        if (length()>INT_MAX)
-            throw SBufTooBigException(__FILE__, __LINE__);
-        return static_cast<int>(length());
-    }
-
-    /** Check whether the SBuf is empty
-     *
-     * \return true if length() == 0
-     */
-    bool isEmpty() const {return (len_==0);}
-
-    /** Request to guarantee the SBuf's free store space.
-     *
-     * After the reserveSpace request, the SBuf is guaranteed to have at
-     * least minSpace bytes of unused backing store following the currently
-     * used portion and single ownership of the backing store.
-     * \throw SBufTooBigException if the user tries to allocate too big a SBuf
-     */
-    void reserveSpace(size_type minSpace) {
-        Must(minSpace <= maxSize);
-        Must(length() <= maxSize - minSpace);
-        reserveCapacity(length()+minSpace);
-    }
-
-    /** Request to guarantee the SBuf's store capacity
-     *
-     * After this method is called, the SBuf is guaranteed to have at least
-     * minCapacity bytes of total buffer size, including the currently-used
-     * portion; it is also guaranteed that after this call this SBuf
-     * has unique ownership of the underlying memory store.
-     * \throw SBufTooBigException if the user tries to allocate too big a SBuf
-     */
-    void reserveCapacity(size_type minCapacity);
-
-    /** slicing method
-     *
-     * Removes SBuf prefix and suffix, leaving a sequence of 'n'
-     * bytes starting from position 'pos', first byte is at pos 0.
-     * It is an in-place-modifying version of substr.
-     * \param pos start sub-stringing from this byte. If it is
-     *      npos or it is greater than the SBuf length, the SBuf is cleared and
-     *      an empty SBuf is returned.
-     * \param n maximum number of bytes of the resulting SBuf.
-     *     npos means "to end of SBuf".
-     *     if it is 0, the SBuf is cleared and an empty SBuf is returned.
-     *     if it overflows the end of the SBuf, it is capped to the end of SBuf
-     * \see substr, trim
-     */
-    SBuf& chop(size_type pos, size_type n = npos);
-
-    /** Remove characters in the toremove set at the beginning, end or both
-     *
-     * \param toremove characters to be removed. Stops chomping at the first
-     *        found char not in the set
-     * \param atBeginning if true (default), strips at the beginning of the SBuf
-     * \param atEnd if true (default), strips at the end of the SBuf
-     */
-    SBuf& trim(const SBuf &toRemove, bool atBeginning = true, bool atEnd = true);
-
-    /** Extract a part of the current SBuf.
-     *
-     * Return a fresh a fresh copy of a portion the current SBuf, which is
-     * left untouched. The same parameter convetions apply as for chop.
-     * \see trim, chop
-     */
-    SBuf substr(size_type pos, size_type n = npos) const;
-
-    /** Find first occurrence of character in SBuf
-     *
-     * Returns the index in the SBuf of the first occurrence of char c.
-     * \return npos if the char was not found
-     * \param startPos if specified, ignore any occurrences before that position
-     *     if startPos is npos or greater than length() npos is always returned
-     *     if startPos is less than zero, it is ignored
-     */
-    size_type find(char c, size_type startPos = 0) const;
-
-    /** Find first occurrence of SBuf in SBuf.
-     *
-     * Returns the index in the SBuf of the first occurrence of the
-     * sequence contained in the str argument.
-     * \param startPos if specified, ignore any occurrences before that position
-     *     if startPos is npos or greater than length() npos is always returned
-     * \return npos if the SBuf was not found
-     */
-    size_type find(const SBuf & str, size_type startPos = 0) const;
-
-    /** Find last occurrence of character in SBuf
-     *
-     * Returns the index in the SBuf of the last occurrence of char c.
-     * \return npos if the char was not found
-     * \param endPos if specified, ignore any occurrences after that position.
-     *   if npos or greater than length(), the whole SBuf is considered
-     */
-    size_type rfind(char c, size_type endPos = npos) const;
-
-    /** Find last occurrence of SBuf in SBuf
-     *
-     * Returns the index in the SBuf of the last occurrence of the
-     * sequence contained in the str argument.
-     * \return npos if the sequence  was not found
-     * \param endPos if specified, ignore any occurrences after that position
-     *   if npos or greater than length(), the whole SBuf is considered
-     */
-    size_type rfind(const SBuf &str, size_type endPos = npos) const;
-
-    /** Find first occurrence of character of set in SBuf
-     *
-     * Finds the first occurrence of ANY of the characters in the supplied set in
-     * the SBuf.
-     * \return npos if no character in the set could be found
-     * \param startPos if specified, ignore any occurrences before that position
-     *   if npos, then npos is always returned
-     *
-     * TODO: rename to camelCase
-     */
-    size_type findFirstOf(const CharacterSet &set, size_type startPos = 0) const;
-
-    /** Find last occurrence of character of set in SBuf
-     *
-     * Finds the last occurrence of ANY of the characters in the supplied set in
-     * the SBuf.
-     * \return npos if no character in the set could be found
-     * \param endPos if specified, ignore any occurrences after that position
-     *   if npos, the entire SBuf is searched
-     */
-    size_type findLastOf(const CharacterSet &set, size_type endPos = npos) const;
-
-    /** Find first occurrence character NOT in character set
-     *
-     * \return npos if all characters in the SBuf are from set
-     * \param startPos if specified, ignore any occurrences before that position
-     *   if npos, then npos is always returned
-     *
-     * TODO: rename to camelCase
-     */
-    size_type findFirstNotOf(const CharacterSet &set, size_type startPos = 0) const;
-
-    /** Find last occurrence character NOT in character set
-     *
-     * \return npos if all characters in the SBuf are from set
-     * \param endPos if specified, ignore any occurrences after that position
-     *   if npos, then the entire SBuf is searched
-     */
-    size_type findLastNotOf(const CharacterSet &set, size_type endPos = npos) const;
-
-    /** sscanf-alike
-     *
-     * sscanf re-implementation. Non-const, and not \0-clean.
-     * \return same as sscanf
-     * \see man sscanf(3)
-     */
-    int scanf(const char *format, ...);
-
-    /// converts all characters to lower case; \see man tolower(3)
-    void toLower();
-
-    /// converts all characters to upper case; \see man toupper(3)
-    void toUpper();
-
-    /** String export function
-     * converts the SBuf to a legacy String, by copy.
-     * \deprecated
-     */
-    String toString() const;
-
-    /// std::string export function
-    std::string toStdString() const { return std::string(buf(),length()); }
-
-    const_iterator begin() const {
-        return const_iterator(*this, 0);
-    }
-
-    const_iterator end() const {
-        return const_iterator(*this, length());
-    }
-
-    const_reverse_iterator rbegin() const {
-        return const_reverse_iterator(*this, length());
-    }
-
-    const_reverse_iterator rend() const {
-        return const_reverse_iterator(*this, 0);
-    }
-
-    // TODO: possibly implement erase() similar to std::string's erase
-    // TODO: possibly implement a replace() call
-private:
-
-    /**
-     * Keeps SBuf's MemBlob alive in a blob-destroying context where
-     * a seemingly unrelated memory pointer may belong to the same blob.
-     * For [an extreme] example, consider: a.append(a).
-     * Compared to an SBuf temporary, this class is optimized to
-     * preserve blobs only if needed and to reduce debugging noise.
-     */
-    class Locker
-    {
-    public:
-        Locker(SBuf *parent, const char *otherBuffer) {
-            // lock if otherBuffer intersects the parents buffer area
-            const MemBlob *blob = parent->store_.getRaw();
-            if (blob->mem <= otherBuffer && otherBuffer < (blob->mem + blob->capacity))
-                locket = blob;
-        }
-    private:
-        MemBlob::Pointer locket;
-    };
-    friend class Locker;
-
-    MemBlob::Pointer store_; ///< memory block, possibly shared with other SBufs
-    size_type off_; ///< our content start offset from the beginning of shared store_
-    size_type len_; ///< number of our content bytes in shared store_
-    static SBufStats stats; ///< class-wide statistics
-
-    /// SBuf object identifier; does not change when contents do,
-    ///   including during assignment
-    const InstanceId<SBuf> id;
-
-    /** obtain prototype store
-     *
-     * Just-created SBufs all share to the same MemBlob.
-     * This call instantiates and returns it.
-     */
-    static MemBlob::Pointer GetStorePrototype();
-
-    /**
-     * obtains a char* to the beginning of this SBuf in memory.
-     * \note the obtained string is NOT null-terminated.
-     */
-    char * buf() const {return (store_->mem+off_);}
-
-    /** returns the pointer to the first char after this SBuf end
-     *
-     *  No checks are made that the space returned is safe, checking that is
-     *  up to the caller.
-     */
-    char * bufEnd() const {return (store_->mem+off_+len_);}
-
-    /**
-     * Try to guesstimate how big a MemBlob to allocate.
-     * The result is guarranteed to be to be at least the desired size.
-     */
-    size_type estimateCapacity(size_type desired) const {return (2*desired);}
-
-    void reAlloc(size_type newsize);
-
-    void cow(size_type minsize = npos);
-
-    void checkAccessBounds(size_type pos) const;
-
-    /** Low-level append operation
-     *
-     * Takes as input a contiguous area of memory and appends its contents
-     * to the SBuf, taking care of memory management. Does no bounds checking
-     * on the supplied memory buffer, it is the duty of the caller to ensure
-     * that the supplied area is valid.
-     */
-    SBuf& lowAppend(const char * memArea, size_type areaSize);
-};
-
-/// ostream output operator
-inline std::ostream &
-operator <<(std::ostream& os, const SBuf& S)
-{
-    return S.print(os);
-}
-
-/// Returns a lower-cased copy of its parameter.
-inline SBuf
-ToUpper(SBuf buf)
-{
-    buf.toUpper();
-    return buf;
-}
-
-/// Returns an upper-cased copy of its parameter.
-inline SBuf
-ToLower(SBuf buf)
-{
-    buf.toLower();
-    return buf;
-}
-
-/**
- * Copy an SBuf into a C-string.
- *
- * Guarantees that the output is a c-string of length
- * no more than SBuf::length()+1 by appending a \0 byte
- * to the C-string copy of the SBuf contents.
- *
- * \note The destination c-string memory MUST be of at least
- *       length()+1 bytes.
- *
- * No protection is added to prevent \0 bytes within the string.
- * Unexpectedly short strings are a problem for the receiver
- * to deal with if it cares.
- *
- * Unlike SBuf::c_str() does not alter the SBuf in any way.
- */
-inline void
-SBufToCstring(char *d, const SBuf &s)
-{
-    s.copy(d, s.length());
-    d[s.length()] = '\0'; // 0-terminate the destination
-    debugs(1, DBG_DATA, "built c-string '" << d << "' from " << s);
-}
-
-/**
- * Copy an SBuf into a C-string.
- *
- * \see SBufToCstring(char *d, const SBuf &s)
- *
- * \returns A dynamically allocated c-string based on SBuf.
- *          Use xfree() / safe_free() to release the c-string.
- */
-inline char *
-SBufToCstring(const SBuf &s)
-{
-    char *d = static_cast<char*>(xmalloc(s.length()+1));
-    SBufToCstring(d, s);
-    return d;
-}
-
-inline
-SBufIterator::SBufIterator(const SBuf &s, size_type pos)
-    : iter(s.rawContent()+pos)
-{}
-
-inline bool
-SBufIterator::operator==(const SBufIterator &s) const
-{
-    // note: maybe the sbuf comparison is unnecessary?
-    return iter == s.iter;
-}
-
-inline bool
-SBufIterator::operator!=(const SBufIterator &s) const
-{
-    // note: maybe the sbuf comparison is unnecessary?
-    return iter != s.iter;
-}
-
-#endif /* SQUID_SBUF_H */
-
diff -u -r -N squid-4.0.7/src/SBufList.cc squid-4.0.8/src/SBufList.cc
--- squid-4.0.7/src/SBufList.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/SBufList.cc	1970-01-01 12:00:00.000000000 +1200
@@ -1,18 +0,0 @@
-/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-#include "squid.h"
-#include "SBufAlgos.h"
-#include "SBufList.h"
-
-bool
-IsMember(const SBufList & sl, const SBuf &S, const SBufCaseSensitive case_sensitive)
-{
-    return std::find_if(sl.begin(), sl.end(), SBufEqual(S,case_sensitive)) != sl.end();
-}
-
diff -u -r -N squid-4.0.7/src/SBufList.h squid-4.0.8/src/SBufList.h
--- squid-4.0.7/src/SBufList.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/SBufList.h	1970-01-01 12:00:00.000000000 +1200
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-#ifndef SQUID_SBUFLIST_H
-#define SQUID_SBUFLIST_H
-
-#include "SBuf.h"
-
-#include <list>
-
-typedef std::list<SBuf> SBufList;
-
-/** check for membership
- *
- * \return true if the supplied SBuf is a member of the list
- * \param case_sensitive one of caseSensitive or caseInsensitive
- */
-bool IsMember(const SBufList &, const SBuf &, const SBufCaseSensitive isCaseSensitive = caseSensitive);
-
-#endif /* SQUID_SBUFLIST_H */
-
diff -u -r -N squid-4.0.7/src/SBufStatsAction.cc squid-4.0.8/src/SBufStatsAction.cc
--- squid-4.0.7/src/SBufStatsAction.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/SBufStatsAction.cc	2016-04-02 10:04:07.000000000 +1300
@@ -11,7 +11,7 @@
 #include "ipc/Messages.h"
 #include "ipc/TypedMsgHdr.h"
 #include "mgr/Registration.h"
-#include "SBufDetailedStats.h"
+#include "sbuf/DetailedStats.h"
 #include "SBufStatsAction.h"
 
 SBufStatsAction::SBufStatsAction(const Mgr::CommandPointer &cmd_):
diff -u -r -N squid-4.0.7/src/SBufStatsAction.h squid-4.0.8/src/SBufStatsAction.h
--- squid-4.0.7/src/SBufStatsAction.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/SBufStatsAction.h	2016-04-02 10:04:07.000000000 +1300
@@ -10,7 +10,7 @@
 #define SQUID_SBUFEXTRAS_H
 
 #include "mgr/Action.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "StatHist.h"
 
 class StoreEntry;
diff -u -r -N squid-4.0.7/src/SBufStream.h squid-4.0.8/src/SBufStream.h
--- squid-4.0.7/src/SBufStream.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/SBufStream.h	1970-01-01 12:00:00.000000000 +1200
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
- */
-
-#ifndef SQUID_SBUFSTREAM_H
-#define SQUID_SBUFSTREAM_H
-
-#include "SBuf.h"
-
-#include <ostream>
-
-/** streambuf class for a SBuf-backed stream interface.
- *
- * Auxiliary class to be able to leverage an ostream generating SBuf's
- * analogous to std::ostrstream.
- */
-class SBufStreamBuf : public std::streambuf
-{
-public:
-    /// initialize streambuf; use supplied SBuf as backing store
-    explicit SBufStreamBuf(SBuf aBuf) : theBuf(aBuf) {}
-
-    /// get a copy of the stream's contents
-    SBuf getBuf() {
-        return theBuf;
-    }
-
-    /// clear the stream's store
-    void clearBuf() {
-        theBuf.clear();
-    }
-
-protected:
-    virtual int_type overflow(int_type aChar = traits_type::eof()) {
-        std::streamsize pending(pptr() - pbase());
-
-        if (pending && sync())
-            return traits_type::eof();
-
-        if (aChar != traits_type::eof()) {
-            char chars[1] = {static_cast<char>(aChar)};
-
-            if (aChar != traits_type::eof())
-                theBuf.append(chars, 1);
-        }
-
-        pbump(-pending);  // Reset pptr().
-        return aChar;
-    }
-
-    /// push the streambuf to the backing SBuf
-    virtual int sync() {
-        std::streamsize pending(pptr() - pbase());
-
-        if (pending)
-            theBuf.append(pbase(), pending);
-
-        return 0;
-    }
-
-    /** write multiple characters to the store entry
-     * \note this is an optimisation consistent with std::streambuf API
-     */
-    virtual std::streamsize xsputn(const char * chars, std::streamsize number) {
-        if (number)
-            theBuf.append(chars, number);
-
-        return number;
-    }
-
-private:
-    SBuf theBuf;
-    SBufStreamBuf(); // no default constructor
-};
-
-/** Stream interface to write to a SBuf.
- *
- * Data is appended using standard operator << semantics, and extracted
- * using the buf() method, in analogy with std::strstream .
- */
-class SBufStream : public std::ostream
-{
-public:
-    /** Create a SBufStream preinitialized with the contents of a SBuf
-     *
-     * The supplied SBuf copied: in order to retrieve the written-to contents
-     * they must be later fetched using the buf() class method.
-     */
-    SBufStream(SBuf aBuf): std::ostream(0), theBuffer(aBuf) {
-        rdbuf(&theBuffer); // set the buffer to now-initialized theBuffer
-        clear(); //clear badbit set by calling init(0)
-    }
-
-    /// Create an empty SBufStream
-    SBufStream(): std::ostream(0), theBuffer(SBuf()) {
-        rdbuf(&theBuffer); // set the buffer to now-initialized theBuffer
-        clear(); //clear badbit set by calling init(0)
-    }
-
-    /// Retrieve a copy of the current stream status
-    SBuf buf() {
-        flush();
-        return theBuffer.getBuf();
-    }
-
-    /// Clear the stream's backing store
-    SBufStream& clearBuf() {
-        flush();
-        theBuffer.clearBuf();
-        return *this;
-    }
-
-private:
-    SBufStreamBuf theBuffer;
-};
-
-#endif /* SQUID_SBUFSTREAM_H */
-
diff -u -r -N squid-4.0.7/src/security/cert_generators/file/Makefile.am squid-4.0.8/src/security/cert_generators/file/Makefile.am
--- squid-4.0.7/src/security/cert_generators/file/Makefile.am	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/security/cert_generators/file/Makefile.am	2016-04-02 10:04:07.000000000 +1300
@@ -7,18 +7,24 @@
 
 include $(top_srcdir)/src/Common.am
 include $(top_srcdir)/src/TestHeaders.am
+include $(top_srcdir)/doc/manuals/Substitute.am
+
+security_file_certgen.8: $(srcdir)/security_file_certgen.8.in Makefile
+	$(SUBSTITUTE) < $(srcdir)/security_file_certgen.8.in > $@
 
 man_MANS = security_file_certgen.8
+CLEANFILES += security_file_certgen.8
+EXTRA_DIST = security_file_certgen.8.in
+
 libexec_PROGRAMS = security_file_certgen
 
 security_file_certgen_SOURCES = \
 	certificate_db.cc \
 	certificate_db.h \
 	security_file_certgen.cc
+
 security_file_certgen_LDADD = \
 	$(top_builddir)/src/ssl/libsslutil.la \
 	$(SSLLIB) \
 	$(COMPAT_LIB)
 
-EXTRA_DIST = security_file_certgen.8
-
diff -u -r -N squid-4.0.7/src/security/cert_generators/file/Makefile.in squid-4.0.8/src/security/cert_generators/file/Makefile.in
--- squid-4.0.7/src/security/cert_generators/file/Makefile.in	2016-02-24 06:49:43.000000000 +1300
+++ squid-4.0.8/src/security/cert_generators/file/Makefile.in	2016-04-02 10:08:00.000000000 +1300
@@ -464,8 +464,9 @@
 TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \
 	$(TEST_LOG_FLAGS)
 am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/cfgaux/depcomp \
-	$(top_srcdir)/cfgaux/test-driver $(top_srcdir)/src/Common.am \
-	$(top_srcdir)/src/TestHeaders.am
+	$(top_srcdir)/cfgaux/test-driver \
+	$(top_srcdir)/doc/manuals/Substitute.am \
+	$(top_srcdir)/src/Common.am $(top_srcdir)/src/TestHeaders.am
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 ACLOCAL = @ACLOCAL@
 ADAPTATION_LIBS = @ADAPTATION_LIBS@
@@ -697,9 +698,28 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
-CLEANFILES = testHeaders
+CLEANFILES = testHeaders security_file_certgen.8
 TESTS = testHeaders
 AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/include \
 	-I$(top_srcdir)/lib -I$(top_srcdir)/src \
@@ -709,7 +729,17 @@
 @ENABLE_XPROF_STATS_TRUE@LIBPROFILER = $(top_builddir)/lib/profiler/libprofiler.la
 COMPAT_LIB = $(top_builddir)/compat/libcompatsquid.la $(LIBPROFILER)
 subst_perlshell = sed -e 's,[@]PERL[@],$(PERL),g' <$(srcdir)/$@.pl.in >$@ || ($(RM) -f $@ ; exit 1)
+SUBSTITUTE = sed "\
+	s%@DEFAULT_ERROR_DIR@%$(DEFAULT_ERROR_DIR)%g;\
+	s%@DEFAULT_MIME_TABLE@%$(DEFAULT_MIME_TABLE)%g;\
+	s%@DEFAULT_SSL_CRTD@%$(DEFAULT_SSL_CRTD)%g;\
+	s%@DEFAULT_SSL_DB_DIR@%$(DEFAULT_SSL_DB_DIR)%g;\
+	s%@""PACKAGE_STRING""@%$(PACKAGE_STRING)%g;\
+	s%@SYSCONFDIR@%$(sysconfdir)%g;\
+	"
+
 man_MANS = security_file_certgen.8
+EXTRA_DIST = security_file_certgen.8.in
 security_file_certgen_SOURCES = \
 	certificate_db.cc \
 	certificate_db.h \
@@ -720,12 +750,11 @@
 	$(SSLLIB) \
 	$(COMPAT_LIB)
 
-EXTRA_DIST = security_file_certgen.8
 all: all-am
 
 .SUFFIXES:
 .SUFFIXES: .cc .lo .log .o .obj .test .test$(EXEEXT) .trs
-$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/src/Common.am $(top_srcdir)/src/TestHeaders.am $(am__configure_deps)
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(top_srcdir)/src/Common.am $(top_srcdir)/src/TestHeaders.am $(top_srcdir)/doc/manuals/Substitute.am $(am__configure_deps)
 	@for dep in $?; do \
 	  case '$(am__configure_deps)' in \
 	    *$$dep*) \
@@ -745,7 +774,7 @@
 	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
 	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
 	esac;
-$(top_srcdir)/src/Common.am $(top_srcdir)/src/TestHeaders.am $(am__empty):
+$(top_srcdir)/src/Common.am $(top_srcdir)/src/TestHeaders.am $(top_srcdir)/doc/manuals/Substitute.am $(am__empty):
 
 $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
 	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
@@ -1289,6 +1318,9 @@
 
 .PHONY: testHeaders
 
+security_file_certgen.8: $(srcdir)/security_file_certgen.8.in Makefile
+	$(SUBSTITUTE) < $(srcdir)/security_file_certgen.8.in > $@
+
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
diff -u -r -N squid-4.0.7/src/security/cert_generators/file/security_file_certgen.8 squid-4.0.8/src/security/cert_generators/file/security_file_certgen.8
--- squid-4.0.7/src/security/cert_generators/file/security_file_certgen.8	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/security/cert_generators/file/security_file_certgen.8	1970-01-01 12:00:00.000000000 +1200
@@ -1,184 +0,0 @@
-.if !'po4a'hide' .TH security_file_certgen 8
-.
-.SH NAME
-security_file_certgen \- SSL certificate generator for Squid.
-.PP
-Version 1.0
-.
-.SH SYNOPSIS
-.if !'po4a'hide' .B security_file_certgen
-.if !'po4a'hide' .B [\-dhv]
-.
-.if !'po4a'hide' .B security_file_certgen
-.if !'po4a'hide' .B "[\-d] -s "
-directory
-.if !'po4a'hide' .B "[\-M "
-size
-.if !'po4a'hide' .B ]
-.
-.if !'po4a'hide' .B security_file_certgen
-.if !'po4a'hide' .B "[\-d] \-c \-s "
-directory
-.if !'po4a'hide' .B [\-n]
-serial number
-.
-.if !'po4a'hide' .B security_file_certgen
-.if !'po4a'hide' .B "[\-d] \-g \-s "
-directory
-.
-.SH DESCRIPTION
-.B security_file_certgen
-is an installed binary.
-.PP
-Because the generation and signing of SSL certificates takes time
-Squid must use external process to handle the work.
-.
-This process generates new SSL certificates and uses a disk cache of certificatess
-to improve response times on repeated requests.
-Communication occurs via TCP sockets bound to the loopback interface.
-.
-.SH OPTIONS
-.if !'po4a'hide' .TP 12
-.if !'po4a'hide' .B \-b fs_block_size
-File system block size in bytes. Needed for processing natural size of certificate on disk.
-Default value is 2048 bytes.
-.
-.if !'po4a'hide' .TP
-.if !'po4a'hide' .B \-c
-Initialize the SSL storage database and exit.
-Requires the 
-.B -s 
-option to determine the storage location being created.
-.
-.if !'po4a'hide' .TP
-.if !'po4a'hide' .B \-d
-Write debug info to stderr.
-.
-.if !'po4a'hide' .TP
-.if !'po4a'hide' .B \-g
-Display the current serial number using stderr and exit.
-Requires 
-.B \-s 
-option to determine which storage directory the serial is located in.
-.
-.if !'po4a'hide' .TP
-.if !'po4a'hide' .B \-h
-Display the binary help and command line syntax info using stderr.
-.
-.if !'po4a'hide' .TP
-.if !'po4a'hide' .B \-s directory
-Directory path of disk storage for new SSL certificates.
-.
-.if !'po4a'hide' .TP
-.if !'po4a'hide' .B \-M size
-Maximum size of SSL certificate disk storage.
-.
-.if !'po4a'hide' .TP
-.if !'po4a'hide' .B \-n serial number
-HEX 
-.B "serial number "
-to use when initializing an SSL storage database.
-The default value of serial number is the number of seconds since Epoch minus 1200000000.
-.
-.if !'po4a'hide' .TP
-.if !'po4a'hide' .B \-v
-Display the binary version details using stderr.
-.
-.SH KNOWN ISSUES
-.PP
-.B SSL errors after changing the CA
-.
-.PP
-Certificates are stored in this database in signed form.
-After any change to the signing CA in squid.conf be sure to erase and re-initialize the certificate database.
-.
-.PP
-.B Certificate chaining
-.
-.PP
-The version 1.0 of this helper will not add chained intermediate CA certificates.
-The client must have a full chain of trust from the root CA all the way
-down to the end certificate generated by this program.
-.
-Signing with an intermediate CA needs to install both the
-root and the intermediate public CA on the clients.
-.
-.SH CONFIGURATION
-.PP
-Before this helper can be used the storage area for new certificates must be initialized manually.
-This is done from the command line using the 
-.B \-c 
-parameters.
-.
-.PP
-For example:
-.if !'po4a'hide' .RS
-.if !'po4a'hide' .B security_file_certgen -c -s /var/lib/ssl_db
-.if !'po4a'hide' .RE
-.
-.PP
-Certificates are stored in this database in signed form.
-After any change to the signing CA in squid.conf be sure to erase and re-initialize the certificate database.
-.
-.PP
-For simple configuration the helper defaults can be used.
-Only HTTP listening port options are required to enable generation and set the signign CA certificate.
-For Example:
-.if !'po4a'hide' .RS
-.if !'po4a'hide' .B http_port 3128 ssl-bump generate-host-certificates=on dynamic_cert_mem_cache_size=4MB cert=/usr/local/squid/ssl_cert/www.sample.com.pem
-.if !'po4a'hide' .RE
-.
-.PP
-For more customized configuration the helper certificate storage directory location and size can be altered with the
-.B sslcrtd_program 
-configuration directive.
-For example:
-.if !'po4a'hide' .RS
-.if !'po4a'hide' .B sslcrtd_program /usr/local/squid/libexec/security_file_certgen -s /usr/local/squid/var/lib/ssl_db -M 4MB
-.if !'po4a'hide' .
-.if !'po4a'hide' .B sslcrtd_children 5
-.if !'po4a'hide' .RE
-.
-.SH AUTHOR
-This program was written by
-.if !'po4a'hide' .I Christos Tsantilas <christos@chtsanti.net>
-.PP
-This manual was written by
-.if !'po4a'hide' .I Christos Tsantilas <christos@chtsanti.net>
-.if !'po4a'hide' .I Amos Jeffries <squid3@treenet.co.nz>
-.
-.SH COPYRIGHT
-.PP
- * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
- *
- * Squid software is distributed under GPLv2+ license and includes
- * contributions from numerous individuals and organizations.
- * Please see the COPYING and CONTRIBUTORS files for details.
-.
-.SH QUESTIONS
-Questions on the usage of this program can be sent to the
-.I Squid Users mailing list
-.if !'po4a'hide' <squid-users@squid-cache.org>
-.
-.SH REPORTING BUGS
-Bug reports need to be made in English.
-See http://wiki.squid-cache.org/SquidFaq/BugReporting for details of what you need to include with your bug report.
-.PP
-Report bugs or bug fixes using http://bugs.squid-cache.org/
-.PP
-Report serious security bugs to
-.I Squid Bugs <squid-bugs@squid-cache.org>
-.PP
-Report ideas for new improvements to the
-.I Squid Developers mailing list
-.if !'po4a'hide' <squid-dev@squid-cache.org>
-.
-.SH SEE ALSO
-.if !'po4a'hide' .BR squid "(8), "
-.if !'po4a'hide' .BR GPL "(7), "
-.br
-The Squid FAQ wiki
-.if !'po4a'hide' http://wiki.squid-cache.org/SquidFaq
-.br
-The Squid Configuration Manual
-.if !'po4a'hide' http://www.squid-cache.org/Doc/config/
diff -u -r -N squid-4.0.7/src/security/cert_generators/file/security_file_certgen.8.in squid-4.0.8/src/security/cert_generators/file/security_file_certgen.8.in
--- squid-4.0.7/src/security/cert_generators/file/security_file_certgen.8.in	1970-01-01 12:00:00.000000000 +1200
+++ squid-4.0.8/src/security/cert_generators/file/security_file_certgen.8.in	2016-04-02 10:04:07.000000000 +1300
@@ -0,0 +1,185 @@
+.if !'po4a'hide' .TH security_file_certgen 8
+.
+.SH NAME
+security_file_certgen \- SSL certificate generator for Squid.
+.PP
+Version 1.0
+.
+.SH SYNOPSIS
+.if !'po4a'hide' .B security_file_certgen
+.if !'po4a'hide' .B [\-dhv]
+.br
+.if !'po4a'hide' .B security_file_certgen
+.if !'po4a'hide' .B "[\-d] \-s "
+directory
+.if !'po4a'hide' .B "[\-M "
+size
+.if !'po4a'hide' .B ]
+.br
+.if !'po4a'hide' .B security_file_certgen
+.if !'po4a'hide' .B "[\-d] \-c \-s "
+directory
+.if !'po4a'hide' .B "[\-n "
+serial number
+.if !'po4a'hide' .B ]
+.br
+.if !'po4a'hide' .B security_file_certgen
+.if !'po4a'hide' .B "[\-d] \-g \-s "
+directory
+.
+.SH DESCRIPTION
+.B security_file_certgen
+is an installed binary.
+.PP
+Because the generation and signing of SSL certificates takes time
+Squid must use external process to handle the work.
+.
+This process generates new SSL certificates and uses a disk cache of certificatess
+to improve response times on repeated requests.
+Communication occurs via TCP sockets bound to the loopback interface.
+.
+.SH OPTIONS
+.if !'po4a'hide' .TP 12
+.if !'po4a'hide' .B \-b fs_block_size
+File system block size in bytes. Needed for processing natural size of certificate on disk.
+Default value is 2048 bytes.
+.
+.if !'po4a'hide' .TP
+.if !'po4a'hide' .B \-c
+Initialize the SSL storage database and exit.
+Requires the 
+.B -s 
+option to determine the storage location being created.
+.
+.if !'po4a'hide' .TP
+.if !'po4a'hide' .B \-d
+Write debug info to stderr.
+.
+.if !'po4a'hide' .TP
+.if !'po4a'hide' .B \-g
+Display the current serial number using stderr and exit.
+Requires 
+.B \-s 
+option to determine which storage directory the serial is located in.
+.
+.if !'po4a'hide' .TP
+.if !'po4a'hide' .B \-h
+Display the binary help and command line syntax info using stderr.
+.
+.if !'po4a'hide' .TP
+.if !'po4a'hide' .B \-s directory
+Directory path of disk storage for new SSL certificates.
+.
+.if !'po4a'hide' .TP
+.if !'po4a'hide' .B \-M size
+Maximum size of SSL certificate disk storage.
+.
+.if !'po4a'hide' .TP
+.if !'po4a'hide' .B \-n serial number
+HEX 
+.B "serial number "
+to use when initializing an SSL storage database.
+The default value of serial number is the number of seconds since Epoch minus 1200000000.
+.
+.if !'po4a'hide' .TP
+.if !'po4a'hide' .B \-v
+Display the binary version details using stderr.
+.
+.SH KNOWN ISSUES
+.PP
+.B SSL errors after changing the CA
+.
+.PP
+Certificates are stored in this database in signed form.
+After any change to the signing CA in squid.conf be sure to erase and re-initialize the certificate database.
+.
+.PP
+.B Certificate chaining
+.
+.PP
+The version 1.0 of this helper will not add chained intermediate CA certificates.
+The client must have a full chain of trust from the root CA all the way
+down to the end certificate generated by this program.
+.
+Signing with an intermediate CA needs to install both the
+root and the intermediate public CA on the clients.
+.
+.SH CONFIGURATION
+.PP
+Before this helper can be used the storage area for new certificates must be initialized manually.
+This is done from the command line using the 
+.B \-c 
+parameters.
+.
+.PP
+For example:
+.if !'po4a'hide' .RS
+.if !'po4a'hide' .B security_file_certgen -c -s @DEFAULT_SSL_DB_DIR@
+.if !'po4a'hide' .RE
+.
+.PP
+Certificates are stored in this database in signed form.
+After any change to the signing CA in squid.conf be sure to erase and re-initialize the certificate database.
+.
+.PP
+For simple configuration the helper defaults can be used.
+Only HTTP listening port options are required to enable generation and set the signign CA certificate.
+For Example:
+.if !'po4a'hide' .RS
+.if !'po4a'hide' .B http_port 3128 ssl-bump generate-host-certificates=on dynamic_cert_mem_cache_size=4MB cert=@SYSCONFDIR@/ssl_cert/www.sample.com.pem
+.if !'po4a'hide' .RE
+.
+.PP
+For more customized configuration the helper certificate storage directory location and size can be altered with the
+.B sslcrtd_program 
+configuration directive.
+For example:
+.if !'po4a'hide' .RS
+.if !'po4a'hide' .B sslcrtd_program @DEFAULT_SSL_CRTD@ -s @DEFAULT_SSL_DB_DIR@ -M 4MB
+.if !'po4a'hide' .br
+.if !'po4a'hide' .B sslcrtd_children 5
+.if !'po4a'hide' .RE
+.
+.SH AUTHOR
+This program was written by
+.if !'po4a'hide' .I Christos Tsantilas <christos@chtsanti.net>
+.PP
+This manual was written by
+.if !'po4a'hide' .I Christos Tsantilas <christos@chtsanti.net>
+.if !'po4a'hide' .I Amos Jeffries <squid3@treenet.co.nz>
+.
+.SH COPYRIGHT
+.PP
+ * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+.
+.SH QUESTIONS
+Questions on the usage of this program can be sent to the
+.I Squid Users mailing list
+.if !'po4a'hide' <squid-users@squid-cache.org>
+.
+.SH REPORTING BUGS
+Bug reports need to be made in English.
+See http://wiki.squid-cache.org/SquidFaq/BugReporting for details of what you need to include with your bug report.
+.PP
+Report bugs or bug fixes using http://bugs.squid-cache.org/
+.PP
+Report serious security bugs to
+.I Squid Bugs <squid-bugs@squid-cache.org>
+.PP
+Report ideas for new improvements to the
+.I Squid Developers mailing list
+.if !'po4a'hide' <squid-dev@squid-cache.org>
+.
+.SH SEE ALSO
+.if !'po4a'hide' .BR squid "(8), "
+.if !'po4a'hide' .BR GPL "(7), "
+.br
+The Squid FAQ wiki
+.if !'po4a'hide' http://wiki.squid-cache.org/SquidFaq
+.br
+The Squid Configuration Manual
+.if !'po4a'hide' http://www.squid-cache.org/Doc/config/
diff -u -r -N squid-4.0.7/src/security/cert_validators/fake/Makefile.in squid-4.0.8/src/security/cert_validators/fake/Makefile.in
--- squid-4.0.7/src/security/cert_validators/fake/Makefile.in	2016-02-24 06:49:43.000000000 +1300
+++ squid-4.0.8/src/security/cert_validators/fake/Makefile.in	2016-04-02 10:08:01.000000000 +1300
@@ -624,6 +624,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = security_fake_certverify $(am__append_2)
diff -u -r -N squid-4.0.7/src/security/cert_validators/fake/security_fake_certverify.8 squid-4.0.8/src/security/cert_validators/fake/security_fake_certverify.8
--- squid-4.0.7/src/security/cert_validators/fake/security_fake_certverify.8	2016-02-24 07:40:35.000000000 +1300
+++ squid-4.0.8/src/security/cert_validators/fake/security_fake_certverify.8	2016-04-02 11:49:33.000000000 +1300
@@ -133,7 +133,7 @@
 .\" ========================================================================
 .\"
 .IX Title "SECURITY_FAKE_CERTVERIFY 8"
-.TH SECURITY_FAKE_CERTVERIFY 8 "2016-02-23" "perl v5.22.1" "User Contributed Perl Documentation"
+.TH SECURITY_FAKE_CERTVERIFY 8 "2016-04-01" "perl v5.22.1" "User Contributed Perl Documentation"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
diff -u -r -N squid-4.0.7/src/security/KeyData.h squid-4.0.8/src/security/KeyData.h
--- squid-4.0.7/src/security/KeyData.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/security/KeyData.h	2016-04-02 10:04:07.000000000 +1300
@@ -9,7 +9,7 @@
 #ifndef SQUID_SRC_SECURITY_KEYDATA_H
 #define SQUID_SRC_SECURITY_KEYDATA_H
 
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "security/forward.h"
 
 namespace Security
diff -u -r -N squid-4.0.7/src/security/LockingPointer.h squid-4.0.8/src/security/LockingPointer.h
--- squid-4.0.7/src/security/LockingPointer.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/security/LockingPointer.h	2016-04-02 10:04:07.000000000 +1300
@@ -58,15 +58,12 @@
     }
 
 #if __cplusplus >= 201103L
-    explicit LockingPointer(LockingPointer<T, DeAllocator, lock> &&o): Parent(o.get()) {
-        *o.addr() = nullptr;
+    explicit LockingPointer(LockingPointer<T, DeAllocator, lock> &&o): Parent(o.release()) {
     }
 
     LockingPointer<T, DeAllocator, lock> &operator =(LockingPointer<T, DeAllocator, lock> &&o) {
-        if (o.get() != this->get()) {
-            this->reset(o.get());
-            *o.addr() = nullptr;
-        }
+        if (o.get() != this->get())
+            this->reset(o.release());
         return *this;
     }
 #endif
diff -u -r -N squid-4.0.7/src/security/Makefile.in squid-4.0.8/src/security/Makefile.in
--- squid-4.0.7/src/security/Makefile.in	2016-02-24 06:49:42.000000000 +1300
+++ squid-4.0.8/src/security/Makefile.in	2016-04-02 10:07:58.000000000 +1300
@@ -727,6 +727,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/security/PeerOptions.cc squid-4.0.8/src/security/PeerOptions.cc
--- squid-4.0.7/src/security/PeerOptions.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/security/PeerOptions.cc	2016-04-02 10:04:07.000000000 +1300
@@ -12,7 +12,6 @@
 #include "fatal.h"
 #include "globals.h"
 #include "parser/Tokenizer.h"
-#include "parser/Tokenizer.h"
 #include "Parsing.h"
 #include "security/PeerOptions.h"
 
diff -u -r -N squid-4.0.7/src/servers/FtpServer.cc squid-4.0.8/src/servers/FtpServer.cc
--- squid-4.0.7/src/servers/FtpServer.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/servers/FtpServer.cc	2016-04-02 10:04:07.000000000 +1300
@@ -62,7 +62,9 @@
     uploadAvailSize(0),
     listener(),
     connector(),
-    reader()
+    reader(),
+    waitingForOrigin(false),
+    originDataDownloadAbortedOnError(false)
 {
     flags.readMore = false; // we need to announce ourselves first
     *uploadBuf = 0;
@@ -720,7 +722,7 @@
                        &params : NULL;
     calcUri(path);
     char *newUri = xstrdup(uri.c_str());
-    HttpRequest *const request = HttpRequest::CreateFromUrlAndMethod(newUri, method);
+    HttpRequest *const request = HttpRequest::CreateFromUrl(newUri, method);
     if (!request) {
         debugs(33, 5, "Invalid FTP URL: " << uri);
         uri.clear();
@@ -1034,6 +1036,12 @@
 {
     Must(reply);
 
+    if (waitingForOrigin) {
+        Must(delayedReply == NULL);
+        delayedReply = reply;
+        return;
+    }
+
     const HttpHeader &header = reply->header;
     // adaptation and forwarding errors lack Http::HdrType::FTP_STATUS
     if (!header.has(Http::HdrType::FTP_STATUS)) {
@@ -1488,8 +1496,8 @@
     if (!checkDataConnPre())
         return false;
 
-    master->waitForOriginData = true;
     master->userDataDone = 0;
+    originDataDownloadAbortedOnError = false;
 
     changeState(fssHandleDataRequest, "handleDataRequest");
 
@@ -1502,9 +1510,6 @@
     if (!checkDataConnPre())
         return false;
 
-    master->waitForOriginData = true;
-    master->userDataDone = 0;
-
     if (Config.accessList.forceRequestBodyContinuation) {
         ClientHttpRequest *http = pipeline.front()->http;
         HttpRequest *request = http->request;
@@ -1724,14 +1729,46 @@
 }
 
 void
-Ftp::Server::originDataCompletionCheckpoint()
+Ftp::Server::startWaitingForOrigin()
 {
-    if (!master->userDataDone) {
-        debugs(33, 5, "Transfering from/to client not finished yet");
-        return;
+    debugs(33, 5, "waiting for Ftp::Client data transfer to end");
+    waitingForOrigin = true;
+}
+
+void
+Ftp::Server::stopWaitingForOrigin(int originStatus)
+{
+    Must(waitingForOrigin);
+    waitingForOrigin = false;
+
+    // if we have already decided how to respond, respond now
+    if (delayedReply) {
+        HttpReply::Pointer reply = delayedReply;
+        delayedReply = nullptr;
+        writeForwardedReply(reply.getRaw());
+        return; // do not completeDataDownload() after an earlier response
     }
 
-    completeDataExchange();
+    if (master->serverState != fssHandleDataRequest)
+        return;
+
+    // completeDataDownload() could be waitingForOrigin in fssHandleDataRequest
+    // Depending on which side has finished downloading first, either trust
+    // master->userDataDone status or set originDataDownloadAbortedOnError:
+    if (master->userDataDone) {
+        // We finished downloading before Ftp::Client. Most likely, the
+        // adaptation shortened the origin response or we hit an error.
+        // Our status (stored in master->userDataDone) is more informative.
+        // Use master->userDataDone; avoid originDataDownloadAbortedOnError.
+        completeDataDownload();
+    } else {
+        debugs(33, 5, "too early to write the response");
+        // Ftp::Client naturally finished downloading before us. Set
+        // originDataDownloadAbortedOnError to overwrite future
+        // master->userDataDone and relay Ftp::Client error, if there was
+        // any, to the user.
+        originDataDownloadAbortedOnError = (originStatus >= 400);
+    }
 }
 
 void Ftp::Server::userDataCompletionCheckpoint(int finalStatusCode)
@@ -1742,23 +1779,24 @@
     if (bodyParser)
         finishDechunkingRequest(false);
 
-    // The origin control connection is gone, nothing to wait for
-    if (!Comm::IsConnOpen(pinning.serverConnection))
-        master->waitForOriginData = false;
-
-    if (master->waitForOriginData) {
-        // The completeDataExchange() is not called here unconditionally
+    if (waitingForOrigin) {
+        // The completeDataDownload() is not called here unconditionally
         // because we want to signal the FTP user that we are not fully
         // done processing its data stream, even though all data bytes
         // have been sent or received already.
-        debugs(33, 5, "Transfering from/to FTP server is not complete");
+        debugs(33, 5, "Transfering from FTP server is not complete");
         return;
     }
 
-    completeDataExchange();
+    // Adjust our reply if the server aborted with an error before we are done.
+    if (master->userDataDone == 226 && originDataDownloadAbortedOnError) {
+        debugs(33, 5, "Transfering from FTP server terminated with an error, adjust status code");
+        master->userDataDone = 451;
+    }
+    completeDataDownload();
 }
 
-void Ftp::Server::completeDataExchange()
+void Ftp::Server::completeDataDownload()
 {
     writeCustomReply(master->userDataDone, master->userDataDone == 226 ? "Transfer complete" : "Server error; transfer aborted");
     closeDataConnection();
diff -u -r -N squid-4.0.7/src/servers/FtpServer.h squid-4.0.8/src/servers/FtpServer.h
--- squid-4.0.7/src/servers/FtpServer.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/servers/FtpServer.h	2016-04-02 10:04:07.000000000 +1300
@@ -41,7 +41,7 @@
 public:
     typedef RefCount<MasterState> Pointer;
 
-    MasterState(): serverState(fssBegin), clientReadGreeting(false), userDataDone(0), waitForOriginData(false) {}
+    MasterState(): serverState(fssBegin), clientReadGreeting(false), userDataDone(0) {}
 
     Ip::Address clientDataAddr; ///< address of our FTP client data connection
     SBuf workingDir; ///< estimated current working directory for URI formation
@@ -49,27 +49,28 @@
     bool clientReadGreeting; ///< whether our FTP client read their FTP server greeting
     /// Squid will send or has sent this final status code to the FTP client
     int userDataDone;
-    /// whether the transfer on the Squid-origin data connection is not over yet
-    bool waitForOriginData;
 };
 
 /// Manages a control connection from an FTP client.
 class Server: public ConnStateData
 {
-    CBDATA_CLASS(Server);
-    // XXX CBDATA_CLASS expands to nonvirtual toCbdata, AsyncJob::toCbdata
-    //     is pure virtual. breaks build on clang if override is used
+    CBDATA_CHILD(Server);
 
 public:
     explicit Server(const MasterXaction::Pointer &xact);
-    virtual ~Server();
+    virtual ~Server() override;
+
     /* AsyncJob API */
-    virtual void callException(const std::exception &e);
+    virtual void callException(const std::exception &e) override;
+
+    /// Called by Ftp::Client class when it is start receiving or
+    /// sending data.
+    void startWaitingForOrigin();
 
     /// Called by Ftp::Client class when it is done receiving or
     /// sending data. Waits for both agents to be done before
     /// responding to the FTP client and closing the data connection.
-    void originDataCompletionCheckpoint();
+    void stopWaitingForOrigin(int status);
 
     // This is a pointer in hope to minimize future changes when MasterState
     // becomes a part of MasterXaction. Guaranteed not to be nil.
@@ -90,21 +91,21 @@
     };
 
     /* ConnStateData API */
-    virtual Http::Stream *parseOneRequest();
-    virtual void processParsedRequest(Http::Stream *context);
-    virtual void notePeerConnection(Comm::ConnectionPointer conn);
-    virtual void clientPinnedConnectionClosed(const CommCloseCbParams &io);
-    virtual void handleReply(HttpReply *header, StoreIOBuffer receivedData);
-    virtual int pipelinePrefetchMax() const;
-    virtual void writeControlMsgAndCall(HttpReply *rep, AsyncCall::Pointer &call);
-    virtual time_t idleTimeout() const;
+    virtual Http::Stream *parseOneRequest() override;
+    virtual void processParsedRequest(Http::Stream *context) override;
+    virtual void notePeerConnection(Comm::ConnectionPointer conn) override;
+    virtual void clientPinnedConnectionClosed(const CommCloseCbParams &io) override;
+    virtual void handleReply(HttpReply *header, StoreIOBuffer receivedData) override;
+    virtual int pipelinePrefetchMax() const override;
+    virtual void writeControlMsgAndCall(HttpReply *rep, AsyncCall::Pointer &call) override;
+    virtual time_t idleTimeout() const override;
 
     /* BodyPipe API */
-    virtual void noteMoreBodySpaceAvailable(BodyPipe::Pointer);
-    virtual void noteBodyConsumerAborted(BodyPipe::Pointer ptr);
+    virtual void noteMoreBodySpaceAvailable(BodyPipe::Pointer) override;
+    virtual void noteBodyConsumerAborted(BodyPipe::Pointer ptr) override;
 
     /* AsyncJob API */
-    virtual void start();
+    virtual void start() override;
 
     /* Comm callbacks */
     static void AcceptCtrlConnection(const CommAcceptCbParams &params);
@@ -125,7 +126,7 @@
 
     /// Writes the data-transfer status reply to the FTP client and
     /// closes the data connection.
-    void completeDataExchange();
+    void completeDataDownload();
 
     void calcUri(const SBuf *file);
     void changeState(const Ftp::ServerState newState, const char *reason);
@@ -189,6 +190,14 @@
     AsyncCall::Pointer listener; ///< set when we are passively listening
     AsyncCall::Pointer connector; ///< set when we are actively connecting
     AsyncCall::Pointer reader; ///< set when we are reading FTP data
+
+    /// whether we wait for the origin data transfer to end
+    bool waitingForOrigin;
+    /// whether the origin data transfer aborted
+    bool originDataDownloadAbortedOnError;
+
+    /// a response which writing was postponed until stopWaitingForOrigin()
+    HttpReply::Pointer delayedReply;
 };
 
 } // namespace Ftp
diff -u -r -N squid-4.0.7/src/servers/Http1Server.cc squid-4.0.8/src/servers/Http1Server.cc
--- squid-4.0.7/src/servers/Http1Server.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/servers/Http1Server.cc	2016-04-02 10:04:07.000000000 +1300
@@ -131,7 +131,7 @@
         return false;
     }
 
-    if ((request = HttpRequest::CreateFromUrlAndMethod(http->uri, parser_->method())) == NULL) {
+    if ((request = HttpRequest::CreateFromUrl(http->uri, parser_->method())) == NULL) {
         debugs(33, 5, "Invalid URL: " << http->uri);
         // setLogUri should called before repContext->setReplyToError
         setLogUri(http, http->uri, true);
@@ -276,11 +276,13 @@
 void
 Http::One::Server::writeControlMsgAndCall(HttpReply *rep, AsyncCall::Pointer &call)
 {
+    const ClientHttpRequest *http = pipeline.front()->http;
+
     // apply selected clientReplyContext::buildReplyHeader() mods
     // it is not clear what headers are required for control messages
     rep->header.removeHopByHopEntries();
     rep->header.putStr(Http::HdrType::CONNECTION, "keep-alive");
-    httpHdrMangleList(&rep->header, pipeline.front()->http->request, ROR_REPLY);
+    httpHdrMangleList(&rep->header, http->request, http->al, ROR_REPLY);
 
     MemBuf *mb = rep->pack();
 
diff -u -r -N squid-4.0.7/src/servers/Makefile.in squid-4.0.8/src/servers/Makefile.in
--- squid-4.0.7/src/servers/Makefile.in	2016-02-24 06:49:44.000000000 +1300
+++ squid-4.0.8/src/servers/Makefile.in	2016-04-02 10:08:02.000000000 +1300
@@ -685,6 +685,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/servers/Server.h squid-4.0.8/src/servers/Server.h
--- squid-4.0.7/src/servers/Server.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/servers/Server.h	2016-04-02 10:04:07.000000000 +1300
@@ -18,7 +18,7 @@
 #include "comm/Write.h"
 #include "CommCalls.h"
 #include "Pipeline.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 /**
  * Common base for all Server classes used
diff -u -r -N squid-4.0.7/src/snmp/Makefile.in squid-4.0.8/src/snmp/Makefile.in
--- squid-4.0.7/src/snmp/Makefile.in	2016-02-24 06:49:44.000000000 +1300
+++ squid-4.0.8/src/snmp/Makefile.in	2016-04-02 10:08:04.000000000 +1300
@@ -686,6 +686,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/squid.8.in squid-4.0.8/src/squid.8.in
--- squid-4.0.7/src/squid.8.in	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/squid.8.in	2016-04-02 10:04:07.000000000 +1300
@@ -118,6 +118,12 @@
 No daemon mode.
 .
 .if !'po4a'hide' .TP
+.if !'po4a'hide' .B \--foreground
+Parent process does not exit until its children have finished. It has no effect with
+.B \-N
+which does not fork/exit at startup.
+.
+.if !'po4a'hide' .TP
 .if !'po4a'hide' .B "\-O options"
 Set Windows Service Command line options in Registry.
 .
diff -u -r -N squid-4.0.7/src/SquidConfig.h squid-4.0.8/src/SquidConfig.h
--- squid-4.0.7/src/SquidConfig.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/SquidConfig.h	2016-04-02 10:04:07.000000000 +1300
@@ -72,6 +72,7 @@
     } Swap;
 
     YesNoNone memShared; ///< whether the memory cache is shared among workers
+    YesNoNone shmLocking; ///< shared_memory_locking
     size_t memMaxSize;
 
     struct {
@@ -340,6 +341,8 @@
 #endif
     } onoff;
 
+    int64_t collapsed_forwarding_shared_entries_limit;
+
     int pipeline_max_prefetch;
 
     int forward_max_tries;
@@ -394,6 +397,7 @@
         acl_access *ftp_epsv;
 
         acl_access *forceRequestBodyContinuation;
+        acl_access *serverPconnForNonretriable;
     } accessList;
     AclDenyInfoList *denyInfoList;
 
@@ -462,6 +466,8 @@
     HeaderManglers *reply_header_access;
     ///request_header_add access list
     HeaderWithAclList *request_header_add;
+    ///reply_header_add access list
+    HeaderWithAclList *reply_header_add;
     ///note
     Notes notes;
     char *coredump_dir;
@@ -544,7 +550,6 @@
 public:
     struct {
         int enable_purge;
-        int mangle_request_headers;
     } onoff;
     uid_t effectiveUserID;
     gid_t effectiveGroupID;
diff -u -r -N squid-4.0.7/src/ssl/bio.h squid-4.0.8/src/ssl/bio.h
--- squid-4.0.7/src/ssl/bio.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/ssl/bio.h	2016-04-02 10:04:07.000000000 +1300
@@ -10,7 +10,7 @@
 #define SQUID_SSL_BIO_H
 
 #include "fd.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 #include <iosfwd>
 #include <list>
diff -u -r -N squid-4.0.7/src/ssl/Makefile.in squid-4.0.8/src/ssl/Makefile.in
--- squid-4.0.7/src/ssl/Makefile.in	2016-02-24 06:49:45.000000000 +1300
+++ squid-4.0.8/src/ssl/Makefile.in	2016-04-02 10:08:05.000000000 +1300
@@ -691,6 +691,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/ssl/support.cc squid-4.0.8/src/ssl/support.cc
--- squid-4.0.7/src/ssl/support.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/ssl/support.cc	2016-04-02 10:04:07.000000000 +1300
@@ -743,26 +743,20 @@
 ssl_get_attribute(X509_NAME * name, const char *attribute_name)
 {
     static char buffer[1024];
-    int nid;
-
     buffer[0] = '\0';
 
     if (strcmp(attribute_name, "DN") == 0) {
         X509_NAME_oneline(name, buffer, sizeof(buffer));
-        goto done;
+    } else {
+        int nid = OBJ_txt2nid(const_cast<char *>(attribute_name));
+        if (nid == 0) {
+            debugs(83, DBG_IMPORTANT, "WARNING: Unknown SSL attribute name '" << attribute_name << "'");
+            return nullptr;
+        }
+        X509_NAME_get_text_by_NID(name, nid, buffer, sizeof(buffer));
     }
 
-    nid = OBJ_txt2nid((char *) attribute_name);
-
-    if (nid == 0) {
-        debugs(83, DBG_IMPORTANT, "WARNING: Unknown SSL attribute name '" << attribute_name << "'");
-        return NULL;
-    }
-
-    X509_NAME_get_text_by_NID(name, nid, buffer, sizeof(buffer));
-
-done:
-    return *buffer ? buffer : NULL;
+    return *buffer ? buffer : nullptr;
 }
 
 /// \ingroup ServerProtocolSSLInternal
diff -u -r -N squid-4.0.7/src/ssl/support.h squid-4.0.8/src/ssl/support.h
--- squid-4.0.7/src/ssl/support.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/ssl/support.h	2016-04-02 10:04:07.000000000 +1300
@@ -14,7 +14,7 @@
 #if USE_OPENSSL
 
 #include "base/CbDataList.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "security/forward.h"
 #include "ssl/gadgets.h"
 
diff -u -r -N squid-4.0.7/src/store/Controlled.h squid-4.0.8/src/store/Controlled.h
--- squid-4.0.7/src/store/Controlled.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/store/Controlled.h	2016-04-02 10:04:07.000000000 +1300
@@ -25,6 +25,9 @@
     /// return false iff the idle entry should be destroyed
     virtual bool dereference(StoreEntry &e) = 0;
 
+    /// make stored metadata and HTTP headers the same as in the given entry
+    virtual void updateHeaders(StoreEntry *) {}
+
     /// If this storage cannot cache collapsed entries, return false.
     /// If the entry is not found, return false. Otherwise, return true after
     /// tying the entry to this cache and setting inSync to updateCollapsed().
diff -u -r -N squid-4.0.7/src/store/Controller.cc squid-4.0.8/src/store/Controller.cc
--- squid-4.0.7/src/store/Controller.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/store/Controller.cc	2016-04-02 10:04:07.000000000 +1300
@@ -76,21 +76,11 @@
     swapDir->create();
 
 #if !_SQUID_WINDOWS_
-
     pid_t pid;
-
     do {
-        int status;
-#if _SQUID_NEXT_
-
-        pid = wait3(&status, WNOHANG, NULL);
-#else
-
-        pid = waitpid(-1, &status, 0);
-#endif
-
+        PidStatus status;
+        pid = WaitForAnyPid(status, WNOHANG);
     } while (pid > 0 || (pid < 0 && errno == EINTR));
-
 #endif
 }
 
@@ -478,6 +468,25 @@
 }
 
 void
+Store::Controller::updateOnNotModified(StoreEntry *old, const StoreEntry &newer)
+{
+    /* update the old entry object */
+    Must(old);
+    HttpReply *oldReply = const_cast<HttpReply*>(old->getReply());
+    Must(oldReply);
+    oldReply->updateOnNotModified(newer.getReply());
+    old->timestampsSet();
+
+    /* update stored image of the old entry */
+
+    if (memStore && old->mem_status == IN_MEMORY && !EBIT_TEST(old->flags, ENTRY_SPECIAL))
+        memStore->updateHeaders(old);
+
+    if (old->swap_dirn > -1)
+        swapDir->updateHeaders(old);
+}
+
+void
 Store::Controller::allowCollapsing(StoreEntry *e, const RequestFlags &reqFlags,
                                    const HttpRequestMethod &reqMethod)
 {
diff -u -r -N squid-4.0.7/src/store/Controller.h squid-4.0.8/src/store/Controller.h
--- squid-4.0.7/src/store/Controller.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/store/Controller.h	2016-04-02 10:04:07.000000000 +1300
@@ -48,6 +48,9 @@
     /// called to get rid of no longer needed entry data in RAM, if any
     void memoryOut(StoreEntry &, const bool preserveSwappable);
 
+    /// update old entry metadata and HTTP headers using a newer entry
+    void updateOnNotModified(StoreEntry *old, const StoreEntry &newer);
+
     /// makes the entry available for collapsing future requests
     void allowCollapsing(StoreEntry *, const RequestFlags &, const HttpRequestMethod &);
 
diff -u -r -N squid-4.0.7/src/store/Disks.cc squid-4.0.8/src/store/Disks.cc
--- squid-4.0.7/src/store/Disks.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/store/Disks.cc	2016-04-02 10:04:07.000000000 +1300
@@ -382,6 +382,13 @@
 }
 
 void
+Store::Disks::updateHeaders(StoreEntry *e)
+{
+    Must(e);
+    return e->disk().updateHeaders(e);
+}
+
+void
 Store::Disks::maintain()
 {
     int i;
diff -u -r -N squid-4.0.7/src/store/Disks.h squid-4.0.8/src/store/Disks.h
--- squid-4.0.7/src/store/Disks.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/store/Disks.h	2016-04-02 10:04:07.000000000 +1300
@@ -32,6 +32,7 @@
     virtual void sync() override;
     virtual void reference(StoreEntry &) override;
     virtual bool dereference(StoreEntry &e) override;
+    virtual void updateHeaders(StoreEntry *) override;
     virtual void maintain() override;
     virtual bool anchorCollapsed(StoreEntry &e, bool &inSync) override;
     virtual bool updateCollapsed(StoreEntry &e) override;
diff -u -r -N squid-4.0.7/src/store/id_rewriters/file/Makefile.in squid-4.0.8/src/store/id_rewriters/file/Makefile.in
--- squid-4.0.7/src/store/id_rewriters/file/Makefile.in	2016-02-24 06:49:46.000000000 +1300
+++ squid-4.0.8/src/store/id_rewriters/file/Makefile.in	2016-04-02 10:08:07.000000000 +1300
@@ -624,6 +624,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = storeid_file_rewrite $(am__append_2)
diff -u -r -N squid-4.0.7/src/store/id_rewriters/file/storeid_file_rewrite.8 squid-4.0.8/src/store/id_rewriters/file/storeid_file_rewrite.8
--- squid-4.0.7/src/store/id_rewriters/file/storeid_file_rewrite.8	2016-02-24 07:39:33.000000000 +1300
+++ squid-4.0.8/src/store/id_rewriters/file/storeid_file_rewrite.8	2016-04-02 11:48:32.000000000 +1300
@@ -133,7 +133,7 @@
 .\" ========================================================================
 .\"
 .IX Title "STOREID_FILE_REWRITE 8"
-.TH STOREID_FILE_REWRITE 8 "2016-02-23" "perl v5.22.1" "User Contributed Perl Documentation"
+.TH STOREID_FILE_REWRITE 8 "2016-04-01" "perl v5.22.1" "User Contributed Perl Documentation"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
diff -u -r -N squid-4.0.7/src/store/Makefile.in squid-4.0.8/src/store/Makefile.in
--- squid-4.0.7/src/store/Makefile.in	2016-02-24 06:49:45.000000000 +1300
+++ squid-4.0.8/src/store/Makefile.in	2016-04-02 10:08:06.000000000 +1300
@@ -726,6 +726,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = testHeaders
diff -u -r -N squid-4.0.7/src/store.cc squid-4.0.8/src/store.cc
--- squid-4.0.7/src/store.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/store.cc	2016-04-02 10:04:07.000000000 +1300
@@ -37,7 +37,6 @@
 #include "store/Disks.h"
 #include "store_digest.h"
 #include "store_key_md5.h"
-#include "store_key_md5.h"
 #include "store_log.h"
 #include "store_rebuild.h"
 #include "StoreClient.h"
@@ -658,31 +657,27 @@
     if (mem_obj->request) {
         HttpRequest *request = mem_obj->request;
 
-        if (!mem_obj->vary_headers) {
+        if (mem_obj->vary_headers.isEmpty()) {
             /* First handle the case where the object no longer varies */
-            safe_free(request->vary_headers);
+            request->vary_headers.clear();
         } else {
-            if (request->vary_headers && strcmp(request->vary_headers, mem_obj->vary_headers) != 0) {
+            if (!request->vary_headers.isEmpty() && request->vary_headers.cmp(mem_obj->vary_headers) != 0) {
                 /* Oops.. the variance has changed. Kill the base object
                  * to record the new variance key
                  */
-                safe_free(request->vary_headers);       /* free old "bad" variance key */
+                request->vary_headers.clear();       /* free old "bad" variance key */
                 if (StoreEntry *pe = storeGetPublic(mem_obj->storeId(), mem_obj->method))
                     pe->release();
             }
 
             /* Make sure the request knows the variance status */
-            if (!request->vary_headers) {
-                const char *vary = httpMakeVaryMark(request, mem_obj->getReply());
-
-                if (vary)
-                    request->vary_headers = xstrdup(vary);
-            }
+            if (request->vary_headers.isEmpty())
+                request->vary_headers = httpMakeVaryMark(request, mem_obj->getReply());
         }
 
         // TODO: storeGetPublic() calls below may create unlocked entries.
         // We should add/use storeHas() API or lock/unlock those entries.
-        if (mem_obj->vary_headers && !storeGetPublic(mem_obj->storeId(), mem_obj->method)) {
+        if (!mem_obj->vary_headers.isEmpty() && !storeGetPublic(mem_obj->storeId(), mem_obj->method)) {
             /* Create "vary" base object */
             String vary;
             StoreEntry *pe = storeCreateEntry(mem_obj->storeId(), mem_obj->logUri(), request->flags, request->method);
diff -u -r -N squid-4.0.7/src/StoreIOState.cc squid-4.0.8/src/StoreIOState.cc
--- squid-4.0.7/src/StoreIOState.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/StoreIOState.cc	2016-04-02 10:04:07.000000000 +1300
@@ -11,6 +11,7 @@
 #include "squid.h"
 #include "Debug.h"
 #include "defines.h"
+#include "Store.h"
 #include "StoreIOState.h"
 
 void *
@@ -52,3 +53,8 @@
         cbdataReferenceDone(callback_data);
 }
 
+bool StoreIOState::touchingStoreEntry() const
+{
+    return e && e->swap_filen == swap_filen;
+}
+
diff -u -r -N squid-4.0.7/src/StoreIOState.h squid-4.0.8/src/StoreIOState.h
--- squid-4.0.7/src/StoreIOState.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/StoreIOState.h	2016-04-02 10:04:07.000000000 +1300
@@ -73,12 +73,19 @@
     } CloseHow;
     virtual void close(int how) = 0; ///< finish or abort swapping per CloseHow
 
+    // Tests whether we are working with the primary/public StoreEntry chain.
+    // Reads start reading the primary chain, but it may become secondary.
+    // There are two store write kinds:
+    // * regular writes that change (usually append) the entry visible to all and
+    // * header updates that create a fresh chain (while keeping the stale one usable).
+    bool touchingStoreEntry() const;
+
     sdirno swap_dirn;
     sfileno swap_filen;
     StoreEntry *e;      /* Need this so the FS layers can play god */
     mode_t mode;
     off_t offset_; ///< number of bytes written or read for this entry so far
-    STFNCB *file_callback;  /* called on delayed sfileno assignments */
+    STFNCB *file_callback;  // XXX: Unused. TODO: Remove.
     STIOCB *callback;
     void *callback_data;
 
diff -u -r -N squid-4.0.7/src/store_key_md5.cc squid-4.0.8/src/store_key_md5.cc
--- squid-4.0.7/src/store_key_md5.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/store_key_md5.cc	2016-04-02 10:04:07.000000000 +1300
@@ -124,8 +124,8 @@
     SquidMD5Update(&M, &m, sizeof(m));
     SquidMD5Update(&M, (unsigned char *) url.rawContent(), url.length());
 
-    if (request->vary_headers) {
-        SquidMD5Update(&M, (unsigned char *) request->vary_headers, strlen(request->vary_headers));
+    if (!request->vary_headers.isEmpty()) {
+        SquidMD5Update(&M, request->vary_headers.rawContent(), request->vary_headers.length());
         debugs(20, 3, "updating public key by vary headers: " << request->vary_headers << " for: " << url);
     }
 
diff -u -r -N squid-4.0.7/src/StoreMetaVary.cc squid-4.0.8/src/StoreMetaVary.cc
--- squid-4.0.7/src/StoreMetaVary.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/StoreMetaVary.cc	2016-04-02 10:04:07.000000000 +1300
@@ -18,14 +18,14 @@
 {
     assert (getType() == STORE_META_VARY_HEADERS);
 
-    if (!e->mem_obj->vary_headers) {
+    if (e->mem_obj->vary_headers.isEmpty()) {
         /* XXX separate this mutator from the query */
         /* Assume the object is OK.. remember the vary request headers */
-        e->mem_obj->vary_headers = xstrdup((char *)value);
+        e->mem_obj->vary_headers.assign(static_cast<const char *>(value), length);
         return true;
     }
 
-    if (strcmp(e->mem_obj->vary_headers, (char *)value) != 0)
+    if (e->mem_obj->vary_headers.cmp(static_cast<const char *>(value), length) != 0)
         return false;
 
     return true;
diff -u -r -N squid-4.0.7/src/store_swapmeta.cc squid-4.0.8/src/store_swapmeta.cc
--- squid-4.0.7/src/store_swapmeta.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/store_swapmeta.cc	2016-04-02 10:04:07.000000000 +1300
@@ -39,10 +39,8 @@
 {
     tlv *TLV = NULL;        /* we'll return this */
     tlv **T = &TLV;
-    const char *vary;
     assert(e->mem_obj != NULL);
     const int64_t objsize = e->mem_obj->expectedReplySize();
-    assert(e->swap_status == SWAPOUT_WRITING);
 
     // e->mem_obj->request may be nil in this context
     SBuf url;
@@ -88,10 +86,12 @@
     }
 
     T = StoreMeta::Add(T, t);
-    vary = e->mem_obj->vary_headers;
+    SBuf vary(e->mem_obj->vary_headers);
 
-    if (vary) {
-        t =StoreMeta::Factory(STORE_META_VARY_HEADERS, strlen(vary) + 1, vary);
+    if (!vary.isEmpty()) {
+        // TODO: do we still need +1 here? StoreMetaVary::checkConsistency
+        //       no longer relies on nul-termination, but other things might.
+        t = StoreMeta::Factory(STORE_META_VARY_HEADERS, vary.length() + 1, vary.c_str());
 
         if (!t) {
             storeSwapTLVFree(TLV);
diff -u -r -N squid-4.0.7/src/tests/SBufFindTest.cc squid-4.0.8/src/tests/SBufFindTest.cc
--- squid-4.0.7/src/tests/SBufFindTest.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/SBufFindTest.cc	2016-04-02 10:04:07.000000000 +1300
@@ -8,7 +8,7 @@
 
 #include "squid.h"
 #include "base/CharacterSet.h"
-#include "SBufFindTest.h"
+#include "tests/SBufFindTest.h"
 
 #include <cppunit/extensions/HelperMacros.h>
 #include <cppunit/Message.h>
diff -u -r -N squid-4.0.7/src/tests/SBufFindTest.h squid-4.0.8/src/tests/SBufFindTest.h
--- squid-4.0.7/src/tests/SBufFindTest.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/SBufFindTest.h	2016-04-02 10:04:07.000000000 +1300
@@ -9,7 +9,7 @@
 #ifndef SQUID_SRC_TEST_SBUFFINDTEST_H
 #define SQUID_SRC_TEST_SBUFFINDTEST_H
 
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 #include <set>
 #include <string>
diff -u -r -N squid-4.0.7/src/tests/stub_comm.cc squid-4.0.8/src/tests/stub_comm.cc
--- squid-4.0.7/src/tests/stub_comm.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/stub_comm.cc	2016-04-02 10:04:07.000000000 +1300
@@ -57,7 +57,7 @@
 int ignoreErrno(int ierrno) STUB_RETVAL(-1)
 void commCloseAllSockets(void) STUB
 void checkTimeouts(void) STUB
-void comm_add_close_handler(int fd, CLCB *, void *) STUB
+AsyncCall::Pointer comm_add_close_handler(int fd, CLCB *, void *) STUB
 void comm_add_close_handler(int fd, AsyncCall::Pointer &) STUB
 void comm_remove_close_handler(int fd, CLCB *, void *) STUB
 void comm_remove_close_handler(int fd, AsyncCall::Pointer &)STUB
diff -u -r -N squid-4.0.7/src/tests/stub_http.cc squid-4.0.8/src/tests/stub_http.cc
--- squid-4.0.7/src/tests/stub_http.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/stub_http.cc	2016-04-02 10:04:07.000000000 +1300
@@ -7,12 +7,12 @@
  */
 
 #include "squid.h"
-
 #include "HttpReply.h"
 #include "HttpRequest.h"
+#include "sbuf/SBuf.h"
 
 #define STUB_API "http.cc"
 #include "tests/STUB.h"
 
-const char * httpMakeVaryMark(HttpRequest * request, HttpReply const * reply) STUB_RETVAL(NULL)
+SBuf httpMakeVaryMark(HttpRequest *, HttpReply const *) STUB_RETVAL(SBuf())
 
diff -u -r -N squid-4.0.7/src/tests/stub_HttpReply.cc squid-4.0.8/src/tests/stub_HttpReply.cc
--- squid-4.0.7/src/tests/stub_HttpReply.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/stub_HttpReply.cc	2016-04-02 10:04:07.000000000 +1300
@@ -28,5 +28,6 @@
     void HttpReply::hdrCacheInit() STUB
     HttpReply * HttpReply::clone() const STUB_RETVAL(NULL)
     bool HttpReply::inheritProperties(const HttpMsg *aMsg) STUB_RETVAL(false)
+    void HttpReply::updateOnNotModified(HttpReply const*) STUB
     int64_t HttpReply::bodySize(const HttpRequestMethod&) const STUB_RETVAL(0)
 
diff -u -r -N squid-4.0.7/src/tests/stub_HttpRequest.cc squid-4.0.8/src/tests/stub_HttpRequest.cc
--- squid-4.0.7/src/tests/stub_HttpRequest.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/stub_HttpRequest.cc	2016-04-02 10:04:07.000000000 +1300
@@ -45,10 +45,9 @@
 bool HttpRequest::bodyNibbled() const STUB_RETVAL(false)
 int HttpRequest::prefixLen() const STUB_RETVAL(0)
 void HttpRequest::swapOut(StoreEntry *) STUB
-void HttpRequest::pack(Packable *) STUB
+void HttpRequest::pack(Packable *) const STUB
 void HttpRequest::httpRequestPack(void *, Packable *) STUB
-HttpRequest * HttpRequest::CreateFromUrlAndMethod(char *, const HttpRequestMethod &) STUB_RETVAL(NULL)
-HttpRequest * HttpRequest::CreateFromUrl(char *) STUB_RETVAL(NULL)
+HttpRequest * HttpRequest::CreateFromUrl(char *, const HttpRequestMethod &) STUB_RETVAL(NULL)
 ConnStateData *HttpRequest::pinnedConnection() STUB_RETVAL(NULL)
 const SBuf HttpRequest::storeId() STUB_RETVAL(SBuf("."))
 void HttpRequest::ignoreRange(const char *) STUB
diff -u -r -N squid-4.0.7/src/tests/stub_libmem.cc squid-4.0.8/src/tests/stub_libmem.cc
--- squid-4.0.7/src/tests/stub_libmem.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/stub_libmem.cc	2016-04-02 10:04:07.000000000 +1300
@@ -80,7 +80,6 @@
     poolCount(0),
     defaultIsChunked(false)
 {}
-void MemPools::init() STUB_NOP
 void MemPools::flushMeters() STUB
 MemImplementingAllocator * MemPools::create(const char *label, size_t obj_size) STUB_RETVAL(NULL);
 void MemPools::setIdleLimit(ssize_t new_idle_limit) STUB
@@ -106,6 +105,5 @@
 MemImplementingAllocator * memPoolIterateNext(MemPoolIterator * iter) STUB_RETVAL(NULL)
 void memPoolIterateDone(MemPoolIterator ** iter) STUB
 int memPoolGetGlobalStats(MemPoolGlobalStats * stats) STUB_RETVAL(0)
-int memPoolInUseCount(MemAllocator *) STUB_RETVAL(0)
 int memPoolsTotalAllocated(void) STUB_RETVAL(0)
 
diff -u -r -N squid-4.0.7/src/tests/stub_MemObject.cc squid-4.0.8/src/tests/stub_MemObject.cc
--- squid-4.0.7/src/tests/stub_MemObject.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/stub_MemObject.cc	2016-04-02 10:04:07.000000000 +1300
@@ -38,7 +38,6 @@
     id(0),
     object_sz(-1),
     swap_hdr_sz(0),
-    vary_headers(NULL),
     _reply(NULL)
 {
     memset(&clients, 0, sizeof(clients));
diff -u -r -N squid-4.0.7/src/tests/stub_MemStore.cc squid-4.0.8/src/tests/stub_MemStore.cc
--- squid-4.0.7/src/tests/stub_MemStore.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/stub_MemStore.cc	2016-04-02 10:04:07.000000000 +1300
@@ -22,6 +22,7 @@
 void MemStore::unlink(StoreEntry &e) STUB
 void MemStore::disconnect(StoreEntry &e) STUB
 void MemStore::reference(StoreEntry &) STUB
+void MemStore::updateHeaders(StoreEntry *) STUB
 void MemStore::maintain() STUB
 void MemStore::noteFreeMapSlice(const Ipc::StoreMapSliceId) STUB
 void MemStore::init() STUB
diff -u -r -N squid-4.0.7/src/tests/stub_SBuf.cc squid-4.0.8/src/tests/stub_SBuf.cc
--- squid-4.0.7/src/tests/stub_SBuf.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/stub_SBuf.cc	2016-04-02 10:04:07.000000000 +1300
@@ -11,7 +11,7 @@
 #define STUB_API "SBuf.cc"
 #include "tests/STUB.h"
 
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 InstanceIdDefinitions(SBuf, "SBuf");
 
@@ -27,7 +27,6 @@
 SBuf::SBuf(const SBuf &S) {}
 SBuf::SBuf(const char *S, size_type n) {}
 SBuf::SBuf(const char *S) {}
-SBuf::SBuf(const String &S) {}
 SBuf::SBuf(const std::string &s) {}
 SBuf::~SBuf() {}
 SBuf& SBuf::assign(const SBuf &S) STUB_RETVAL(*this)
@@ -66,5 +65,4 @@
 int SBuf::scanf(const char *format, ...) STUB_RETVAL(-1)
 void SBuf::toLower() STUB
 void SBuf::toUpper() STUB
-String SBuf::toString() const STUB_RETVAL(String(""))
 
diff -u -r -N squid-4.0.7/src/tests/stub_SBufDetailedStats.cc squid-4.0.8/src/tests/stub_SBufDetailedStats.cc
--- squid-4.0.7/src/tests/stub_SBufDetailedStats.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/stub_SBufDetailedStats.cc	2016-04-02 10:04:07.000000000 +1300
@@ -7,15 +7,15 @@
  */
 
 #include "squid.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
-#define STUB_API "SBufDetailedStats.cc"
+#define STUB_API "sbuf/DetailedStats.cc"
 #include "tests/STUB.h"
 
 class StatHist;
 
-void recordSBufSizeAtDestruct(SBuf::size_type) {}
-const StatHist * collectSBufDestructTimeStats() STUB_RETVAL(NULL)
-void recordMemBlobSizeAtDestruct(SBuf::size_type) {}
-const StatHist * collectMemBlobDestructTimeStats() STUB_RETVAL(NULL)
+void recordSBufSizeAtDestruct(SBuf::size_type) STUB_NOP
+const StatHist * collectSBufDestructTimeStats() STUB_RETVAL(nullptr)
+void recordMemBlobSizeAtDestruct(SBuf::size_type) STUB_NOP
+const StatHist * collectMemBlobDestructTimeStats() STUB_RETVAL(nullptr)
 
diff -u -r -N squid-4.0.7/src/tests/testHttp1Parser.cc squid-4.0.8/src/tests/testHttp1Parser.cc
--- squid-4.0.7/src/tests/testHttp1Parser.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/testHttp1Parser.cc	2016-04-02 10:04:07.000000000 +1300
@@ -19,7 +19,6 @@
 #include "MemBuf.h"
 #include "SquidConfig.h"
 #include "testHttp1Parser.h"
-#include "testHttp1Parser.h"
 #include "unitTestMain.h"
 
 CPPUNIT_TEST_SUITE_REGISTRATION( testHttp1Parser );
diff -u -r -N squid-4.0.7/src/tests/testHttpRequest.cc squid-4.0.8/src/tests/testHttpRequest.cc
--- squid-4.0.7/src/tests/testHttpRequest.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/testHttpRequest.cc	2016-04-02 10:04:07.000000000 +1300
@@ -38,14 +38,25 @@
  * Test creating an HttpRequest object from a Url and method
  */
 void
-testHttpRequest::testCreateFromUrlAndMethod()
+testHttpRequest::testCreateFromUrl()
 {
-    /* vanilla url */
+    /* vanilla url, implict method */
     unsigned short expected_port;
     char * url = xstrdup("http://foo:90/bar");
-    HttpRequest *aRequest = HttpRequest::CreateFromUrlAndMethod(url, Http::METHOD_GET);
+    HttpRequest *aRequest = HttpRequest::CreateFromUrl(url);
+    expected_port = 90;
+    CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->url.port());
+    CPPUNIT_ASSERT(aRequest->method == Http::METHOD_GET);
+    CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest->url.host()));
+    CPPUNIT_ASSERT_EQUAL(SBuf("/bar"), aRequest->url.path());
+    CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, static_cast<AnyP::ProtocolType>(aRequest->url.getScheme()));
+    CPPUNIT_ASSERT_EQUAL(String("http://foo:90/bar"), String(url));
+    xfree(url);
+
+    /* vanilla url */
+    url = xstrdup("http://foo:90/bar");
+    aRequest = HttpRequest::CreateFromUrl(url, Http::METHOD_GET);
     expected_port = 90;
-    HttpRequest *nullRequest = NULL;
     CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->url.port());
     CPPUNIT_ASSERT(aRequest->method == Http::METHOD_GET);
     CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest->url.host()));
@@ -56,7 +67,7 @@
 
     /* vanilla url, different method */
     url = xstrdup("http://foo/bar");
-    aRequest = HttpRequest::CreateFromUrlAndMethod(url, Http::METHOD_PUT);
+    aRequest = HttpRequest::CreateFromUrl(url, Http::METHOD_PUT);
     expected_port = 80;
     CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->url.port());
     CPPUNIT_ASSERT(aRequest->method == Http::METHOD_PUT);
@@ -67,14 +78,15 @@
     xfree(url);
 
     /* a connect url with non-CONNECT data */
+    HttpRequest *nullRequest = nullptr;
     url = xstrdup(":foo/bar");
-    aRequest = HttpRequest::CreateFromUrlAndMethod(url, Http::METHOD_CONNECT);
+    aRequest = HttpRequest::CreateFromUrl(url, Http::METHOD_CONNECT);
     xfree(url);
     CPPUNIT_ASSERT_EQUAL(nullRequest, aRequest);
 
     /* a CONNECT url with CONNECT data */
     url = xstrdup("foo:45");
-    aRequest = HttpRequest::CreateFromUrlAndMethod(url, Http::METHOD_CONNECT);
+    aRequest = HttpRequest::CreateFromUrl(url, Http::METHOD_CONNECT);
     expected_port = 45;
     CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->url.port());
     CPPUNIT_ASSERT(aRequest->method == Http::METHOD_CONNECT);
@@ -83,26 +95,8 @@
     CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_NONE, static_cast<AnyP::ProtocolType>(aRequest->url.getScheme()));
     CPPUNIT_ASSERT_EQUAL(String("foo:45"), String(url));
     xfree(url);
-}
 
-/*
- * Test creating an HttpRequest object from a Url alone.
- */
-void
-testHttpRequest::testCreateFromUrl()
-{
-    /* vanilla url */
-    unsigned short expected_port;
-    char * url = xstrdup("http://foo:90/bar");
-    HttpRequest *aRequest = HttpRequest::CreateFromUrl(url);
-    expected_port = 90;
-    CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->url.port());
-    CPPUNIT_ASSERT(aRequest->method == Http::METHOD_GET);
-    CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest->url.host()));
-    CPPUNIT_ASSERT_EQUAL(SBuf("/bar"), aRequest->url.path());
-    CPPUNIT_ASSERT_EQUAL(AnyP::PROTO_HTTP, static_cast<AnyP::ProtocolType>(aRequest->url.getScheme()));
-    CPPUNIT_ASSERT_EQUAL(String("http://foo:90/bar"), String(url));
-    xfree(url);
+    // XXX: check METHOD_NONE input handling
 }
 
 /*
@@ -117,7 +111,7 @@
 
     /* valid IPv6 address without port */
     url = xstrdup("http://[2000:800::45]/foo");
-    aRequest = HttpRequest::CreateFromUrlAndMethod(url, Http::METHOD_GET);
+    aRequest = HttpRequest::CreateFromUrl(url, Http::METHOD_GET);
     expected_port = 80;
     CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->url.port());
     CPPUNIT_ASSERT(aRequest->method == Http::METHOD_GET);
@@ -129,7 +123,7 @@
 
     /* valid IPv6 address with port */
     url = xstrdup("http://[2000:800::45]:90/foo");
-    aRequest = HttpRequest::CreateFromUrlAndMethod(url, Http::METHOD_GET);
+    aRequest = HttpRequest::CreateFromUrl(url, Http::METHOD_GET);
     expected_port = 90;
     CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->url.port());
     CPPUNIT_ASSERT(aRequest->method == Http::METHOD_GET);
@@ -141,7 +135,7 @@
 
     /* IPv6 address as invalid (bug trigger) */
     url = xstrdup("http://2000:800::45/foo");
-    aRequest = HttpRequest::CreateFromUrlAndMethod(url, Http::METHOD_GET);
+    aRequest = HttpRequest::CreateFromUrl(url, Http::METHOD_GET);
     expected_port = 80;
     CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->url.port());
     CPPUNIT_ASSERT(aRequest->method == Http::METHOD_GET);
diff -u -r -N squid-4.0.7/src/tests/testHttpRequest.h squid-4.0.8/src/tests/testHttpRequest.h
--- squid-4.0.7/src/tests/testHttpRequest.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/testHttpRequest.h	2016-04-02 10:04:07.000000000 +1300
@@ -18,7 +18,6 @@
 class testHttpRequest : public CPPUNIT_NS::TestFixture
 {
     CPPUNIT_TEST_SUITE( testHttpRequest );
-    CPPUNIT_TEST( testCreateFromUrlAndMethod );
     CPPUNIT_TEST( testCreateFromUrl );
     CPPUNIT_TEST( testIPv6HostColonBug );
     CPPUNIT_TEST( testSanityCheckStartLine );
@@ -28,7 +27,6 @@
     void setUp();
 
 protected:
-    void testCreateFromUrlAndMethod();
     void testCreateFromUrl();
     void testIPv6HostColonBug();
     void testSanityCheckStartLine();
diff -u -r -N squid-4.0.7/src/tests/testRock.cc squid-4.0.8/src/tests/testRock.cc
--- squid-4.0.7/src/tests/testRock.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/testRock.cc	2016-04-02 10:04:07.000000000 +1300
@@ -58,6 +58,7 @@
         throw std::runtime_error("Failed to clean test work directory");
 
     Config.memShared.defaultTo(false);
+    Config.shmLocking.defaultTo(false);
 
     // use current directory for shared segments (on path-based OSes)
     Ipc::Mem::Segment::BasePath = getcwd(cwd,MAXPATHLEN);
diff -u -r -N squid-4.0.7/src/tests/testSBuf.cc squid-4.0.8/src/tests/testSBuf.cc
--- squid-4.0.7/src/tests/testSBuf.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/testSBuf.cc	2016-04-02 10:04:07.000000000 +1300
@@ -8,12 +8,11 @@
 
 #include "squid.h"
 #include "base/CharacterSet.h"
-#include "SBuf.h"
-#include "SBufAlgos.h"
-#include "SBufFindTest.h"
-#include "SBufStream.h"
-#include "SquidString.h"
-#include "testSBuf.h"
+#include "sbuf/Algorithms.h"
+#include "sbuf/SBuf.h"
+#include "sbuf/Stream.h"
+#include "tests/SBufFindTest.h"
+#include "tests/testSBuf.h"
 #include "unitTestMain.h"
 
 #include <iostream>
@@ -116,13 +115,6 @@
         CPPUNIT_ASSERT_EQUAL(s4,s3);
     }
 
-    // TEST: go via SquidString adapters.
-    {
-        String str(fox);
-        SBuf s1(str);
-        CPPUNIT_ASSERT_EQUAL(literal,s1);
-    }
-
     // TEST: go via std::string adapter.
     {
         std::string str(fox);
diff -u -r -N squid-4.0.7/src/tests/testSBuf.h squid-4.0.8/src/tests/testSBuf.h
--- squid-4.0.7/src/tests/testSBuf.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/testSBuf.h	2016-04-02 10:04:07.000000000 +1300
@@ -11,7 +11,7 @@
 
 #include <cppunit/extensions/HelperMacros.h>
 
-#include "OutOfBoundsException.h"
+#include "sbuf/OutOfBoundsException.h"
 
 /*
  * test the SBuf functionalities
diff -u -r -N squid-4.0.7/src/tests/testSBufList.cc squid-4.0.8/src/tests/testSBufList.cc
--- squid-4.0.7/src/tests/testSBufList.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/testSBufList.cc	2016-04-02 10:04:07.000000000 +1300
@@ -7,9 +7,9 @@
  */
 
 #include "squid.h"
-#include "SBufAlgos.h"
-#include "SBufList.h"
-#include "testSBufList.h"
+#include "sbuf/Algorithms.h"
+#include "sbuf/List.h"
+#include "tests/testSBufList.h"
 #include "unitTestMain.h"
 
 CPPUNIT_TEST_SUITE_REGISTRATION( testSBufList );
diff -u -r -N squid-4.0.7/src/tests/testSBufList.h squid-4.0.8/src/tests/testSBufList.h
--- squid-4.0.7/src/tests/testSBufList.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tests/testSBufList.h	2016-04-02 10:04:07.000000000 +1300
@@ -11,7 +11,7 @@
 
 #include <cppunit/extensions/HelperMacros.h>
 
-#include "OutOfBoundsException.h"
+#include "sbuf/OutOfBoundsException.h"
 
 class testSBufList : public CPPUNIT_NS::TestFixture
 {
diff -u -r -N squid-4.0.7/src/tools.cc squid-4.0.8/src/tools.cc
--- squid-4.0.7/src/tools.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tools.cc	2016-04-02 10:04:07.000000000 +1300
@@ -1204,7 +1204,7 @@
 #if _SQUID_NEXT_
     if (pid < 0)
         return wait3(&status, flags, NULL);
-    return wait4(cpid, &status, flags, NULL);
+    return wait4(pid, &status, flags, NULL);
 #elif _SQUID_WINDOWS_
     return 0; // function not used on Windows
 #else
diff -u -r -N squid-4.0.7/src/tools.h squid-4.0.8/src/tools.h
--- squid-4.0.7/src/tools.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tools.h	2016-04-02 10:04:07.000000000 +1300
@@ -11,7 +11,7 @@
 #ifndef SQUID_TOOLS_H_
 #define SQUID_TOOLS_H_
 
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "typedefs.h"
 
 class MemBuf;
diff -u -r -N squid-4.0.7/src/Transients.cc squid-4.0.8/src/Transients.cc
--- squid-4.0.7/src/Transients.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/Transients.cc	2016-04-02 10:04:07.000000000 +1300
@@ -370,7 +370,7 @@
     if (!UsingSmp() || !Config.onoff.collapsed_forwarding)
         return 0; // no SMP collapsed forwarding possible or needed
 
-    return 16*1024; // TODO: make configurable?
+    return Config.collapsed_forwarding_shared_entries_limit;
 }
 
 /// initializes shared memory segment used by Transients
diff -u -r -N squid-4.0.7/src/tunnel.cc squid-4.0.8/src/tunnel.cc
--- squid-4.0.7/src/tunnel.cc	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/tunnel.cc	2016-04-02 10:04:07.000000000 +1300
@@ -32,7 +32,7 @@
 #include "LogTags.h"
 #include "MemBuf.h"
 #include "PeerSelectState.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 #include "SquidConfig.h"
 #include "SquidTime.h"
 #include "ssl/BlindPeerConnector.h"
diff -u -r -N squid-4.0.7/src/URL.h squid-4.0.8/src/URL.h
--- squid-4.0.7/src/URL.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/URL.h	2016-04-02 10:04:07.000000000 +1300
@@ -12,7 +12,7 @@
 #include "anyp/UriScheme.h"
 #include "ip/Address.h"
 #include "rfc2181.h"
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 #include <iosfwd>
 
diff -u -r -N squid-4.0.7/src/wordlist.h squid-4.0.8/src/wordlist.h
--- squid-4.0.7/src/wordlist.h	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/src/wordlist.h	2016-04-02 10:04:07.000000000 +1300
@@ -11,7 +11,7 @@
 
 #include "globals.h"
 #include "profiler/Profiler.h"
-#include "SBufList.h"
+#include "sbuf/List.h"
 
 /** A list of C-strings
  *
@@ -48,7 +48,7 @@
 
 /** Concatenate a wordlist
  *
- * \deprecated use SBufListContainerJoin(SBuf()) from SBufAlgos.h instead
+ * \deprecated use SBufListContainerJoin(SBuf()) from sbuf/Algorithms.h instead
  */
 void wordlistCat(const wordlist *, MemBuf *);
 
@@ -60,7 +60,7 @@
 
 /** Concatenate the words in a wordlist
  *
- * \deprecated use SBufListContainerJoin(SBuf()) from SBufAlgos.h instead
+ * \deprecated use SBufListContainerJoin(SBuf()) from sbuf/Algorithms.h instead
  */
 void wordlistJoin(wordlist **, wordlist **);
 
diff -u -r -N squid-4.0.7/test-suite/Makefile.in squid-4.0.8/test-suite/Makefile.in
--- squid-4.0.7/test-suite/Makefile.in	2016-02-24 06:49:46.000000000 +1300
+++ squid-4.0.8/test-suite/Makefile.in	2016-04-02 10:08:09.000000000 +1300
@@ -768,6 +768,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = $(STUBS) stub_libmem.cc squid-conf-tests
diff -u -r -N squid-4.0.7/test-suite/stub_libmem.cc squid-4.0.8/test-suite/stub_libmem.cc
--- squid-4.0.7/test-suite/stub_libmem.cc	2016-02-24 07:40:44.000000000 +1300
+++ squid-4.0.8/test-suite/stub_libmem.cc	2016-04-02 11:49:42.000000000 +1300
@@ -80,7 +80,6 @@
     poolCount(0),
     defaultIsChunked(false)
 {}
-void MemPools::init() STUB_NOP
 void MemPools::flushMeters() STUB
 MemImplementingAllocator * MemPools::create(const char *label, size_t obj_size) STUB_RETVAL(NULL);
 void MemPools::setIdleLimit(ssize_t new_idle_limit) STUB
@@ -106,6 +105,5 @@
 MemImplementingAllocator * memPoolIterateNext(MemPoolIterator * iter) STUB_RETVAL(NULL)
 void memPoolIterateDone(MemPoolIterator ** iter) STUB
 int memPoolGetGlobalStats(MemPoolGlobalStats * stats) STUB_RETVAL(0)
-int memPoolInUseCount(MemAllocator *) STUB_RETVAL(0)
 int memPoolsTotalAllocated(void) STUB_RETVAL(0)
 
diff -u -r -N squid-4.0.7/test-suite/stub_SBuf.cc squid-4.0.8/test-suite/stub_SBuf.cc
--- squid-4.0.7/test-suite/stub_SBuf.cc	2016-02-24 07:40:45.000000000 +1300
+++ squid-4.0.8/test-suite/stub_SBuf.cc	2016-04-02 11:49:42.000000000 +1300
@@ -11,7 +11,7 @@
 #define STUB_API "SBuf.cc"
 #include "tests/STUB.h"
 
-#include "SBuf.h"
+#include "sbuf/SBuf.h"
 
 InstanceIdDefinitions(SBuf, "SBuf");
 
@@ -27,7 +27,6 @@
 SBuf::SBuf(const SBuf &S) {}
 SBuf::SBuf(const char *S, size_type n) {}
 SBuf::SBuf(const char *S) {}
-SBuf::SBuf(const String &S) {}
 SBuf::SBuf(const std::string &s) {}
 SBuf::~SBuf() {}
 SBuf& SBuf::assign(const SBuf &S) STUB_RETVAL(*this)
@@ -66,5 +65,4 @@
 int SBuf::scanf(const char *format, ...) STUB_RETVAL(-1)
 void SBuf::toLower() STUB
 void SBuf::toUpper() STUB
-String SBuf::toString() const STUB_RETVAL(String(""))
 
diff -u -r -N squid-4.0.7/tools/helper-mux/helper-mux.8 squid-4.0.8/tools/helper-mux/helper-mux.8
--- squid-4.0.7/tools/helper-mux/helper-mux.8	2016-02-24 07:40:49.000000000 +1300
+++ squid-4.0.8/tools/helper-mux/helper-mux.8	2016-04-02 11:49:46.000000000 +1300
@@ -133,7 +133,7 @@
 .\" ========================================================================
 .\"
 .IX Title "HELPER-MUX 8"
-.TH HELPER-MUX 8 "2016-02-23" "perl v5.22.1" "User Contributed Perl Documentation"
+.TH HELPER-MUX 8 "2016-04-01" "perl v5.22.1" "User Contributed Perl Documentation"
 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
 .\" way too many mistakes in technical documents.
 .if n .ad l
diff -u -r -N squid-4.0.7/tools/helper-mux/Makefile.in squid-4.0.8/tools/helper-mux/Makefile.in
--- squid-4.0.7/tools/helper-mux/Makefile.in	2016-02-24 06:49:47.000000000 +1300
+++ squid-4.0.8/tools/helper-mux/Makefile.in	2016-04-02 10:08:11.000000000 +1300
@@ -624,6 +624,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = helper-mux $(am__append_2)
diff -u -r -N squid-4.0.7/tools/Makefile.in squid-4.0.8/tools/Makefile.in
--- squid-4.0.7/tools/Makefile.in	2016-02-24 06:49:47.000000000 +1300
+++ squid-4.0.8/tools/Makefile.in	2016-04-02 10:08:10.000000000 +1300
@@ -748,6 +748,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = test_tools.cc stub_debug.cc time.cc stub_libmem.cc STUB.h \
@@ -777,6 +796,8 @@
 SUBSTITUTE = sed "\
 	s%@DEFAULT_ERROR_DIR@%$(DEFAULT_ERROR_DIR)%g;\
 	s%@DEFAULT_MIME_TABLE@%$(DEFAULT_MIME_TABLE)%g;\
+	s%@DEFAULT_SSL_CRTD@%$(DEFAULT_SSL_CRTD)%g;\
+	s%@DEFAULT_SSL_DB_DIR@%$(DEFAULT_SSL_DB_DIR)%g;\
 	s%@""PACKAGE_STRING""@%$(PACKAGE_STRING)%g;\
 	s%@SYSCONFDIR@%$(sysconfdir)%g;\
 	"
diff -u -r -N squid-4.0.7/tools/purge/Makefile.in squid-4.0.8/tools/purge/Makefile.in
--- squid-4.0.7/tools/purge/Makefile.in	2016-02-24 06:49:48.000000000 +1300
+++ squid-4.0.8/tools/purge/Makefile.in	2016-04-02 10:08:12.000000000 +1300
@@ -694,6 +694,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = 
diff -u -r -N squid-4.0.7/tools/squidclient/Makefile.in squid-4.0.8/tools/squidclient/Makefile.in
--- squid-4.0.7/tools/squidclient/Makefile.in	2016-02-24 06:49:48.000000000 +1300
+++ squid-4.0.8/tools/squidclient/Makefile.in	2016-04-02 10:08:14.000000000 +1300
@@ -743,6 +743,25 @@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+DEFAULT_HTTP_PORT = 3128
+DEFAULT_ICP_PORT = 3130
+DEFAULT_PREFIX = $(prefix)
+DEFAULT_CONFIG_DIR = $(sysconfdir)
+DEFAULT_CONFIG_FILE = $(DEFAULT_CONFIG_DIR)/squid.conf
+DEFAULT_MIME_TABLE = $(DEFAULT_CONFIG_DIR)/mime.conf
+DEFAULT_SSL_CRTD = $(libexecdir)/`echo security_file_certgen | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOG_PREFIX = $(DEFAULT_LOG_DIR)
+DEFAULT_CACHE_LOG = $(DEFAULT_LOG_PREFIX)/cache.log
+DEFAULT_ACCESS_LOG = $(DEFAULT_LOG_PREFIX)/access.log
+DEFAULT_STORE_LOG = $(DEFAULT_LOG_PREFIX)/store.log
+DEFAULT_NETDB_FILE = $(DEFAULT_SWAP_DIR)/netdb.state
+DEFAULT_SSL_DB_DIR = $(DEFAULT_SWAP_DIR)/ssl_db
+DEFAULT_PINGER = $(libexecdir)/`echo pinger | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_UNLINKD = $(libexecdir)/`echo unlinkd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_LOGFILED = $(libexecdir)/`echo log_file_daemon | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_DISKD = $(libexecdir)/`echo diskd | sed '$(transform);s/$$/$(EXEEXT)/'`
+DEFAULT_ICON_DIR = $(datadir)/icons
+DEFAULT_ERROR_DIR = $(datadir)/errors
 AM_CFLAGS = $(SQUID_CFLAGS)
 AM_CXXFLAGS = $(SQUID_CXXFLAGS)
 CLEANFILES = test_tools.cc stub_debug.cc time.cc stub_libmem.cc STUB.h
@@ -771,6 +790,8 @@
 SUBSTITUTE = sed "\
 	s%@DEFAULT_ERROR_DIR@%$(DEFAULT_ERROR_DIR)%g;\
 	s%@DEFAULT_MIME_TABLE@%$(DEFAULT_MIME_TABLE)%g;\
+	s%@DEFAULT_SSL_CRTD@%$(DEFAULT_SSL_CRTD)%g;\
+	s%@DEFAULT_SSL_DB_DIR@%$(DEFAULT_SSL_DB_DIR)%g;\
 	s%@""PACKAGE_STRING""@%$(PACKAGE_STRING)%g;\
 	s%@SYSCONFDIR@%$(sysconfdir)%g;\
 	"
diff -u -r -N squid-4.0.7/tools/squidclient/stub_libmem.cc squid-4.0.8/tools/squidclient/stub_libmem.cc
--- squid-4.0.7/tools/squidclient/stub_libmem.cc	2016-02-24 07:40:51.000000000 +1300
+++ squid-4.0.8/tools/squidclient/stub_libmem.cc	2016-04-02 11:49:48.000000000 +1300
@@ -80,7 +80,6 @@
     poolCount(0),
     defaultIsChunked(false)
 {}
-void MemPools::init() STUB_NOP
 void MemPools::flushMeters() STUB
 MemImplementingAllocator * MemPools::create(const char *label, size_t obj_size) STUB_RETVAL(NULL);
 void MemPools::setIdleLimit(ssize_t new_idle_limit) STUB
@@ -106,6 +105,5 @@
 MemImplementingAllocator * memPoolIterateNext(MemPoolIterator * iter) STUB_RETVAL(NULL)
 void memPoolIterateDone(MemPoolIterator ** iter) STUB
 int memPoolGetGlobalStats(MemPoolGlobalStats * stats) STUB_RETVAL(0)
-int memPoolInUseCount(MemAllocator *) STUB_RETVAL(0)
 int memPoolsTotalAllocated(void) STUB_RETVAL(0)
 
diff -u -r -N squid-4.0.7/tools/stub_libmem.cc squid-4.0.8/tools/stub_libmem.cc
--- squid-4.0.7/tools/stub_libmem.cc	2016-02-24 07:40:47.000000000 +1300
+++ squid-4.0.8/tools/stub_libmem.cc	2016-04-02 11:49:44.000000000 +1300
@@ -80,7 +80,6 @@
     poolCount(0),
     defaultIsChunked(false)
 {}
-void MemPools::init() STUB_NOP
 void MemPools::flushMeters() STUB
 MemImplementingAllocator * MemPools::create(const char *label, size_t obj_size) STUB_RETVAL(NULL);
 void MemPools::setIdleLimit(ssize_t new_idle_limit) STUB
@@ -106,6 +105,5 @@
 MemImplementingAllocator * memPoolIterateNext(MemPoolIterator * iter) STUB_RETVAL(NULL)
 void memPoolIterateDone(MemPoolIterator ** iter) STUB
 int memPoolGetGlobalStats(MemPoolGlobalStats * stats) STUB_RETVAL(0)
-int memPoolInUseCount(MemAllocator *) STUB_RETVAL(0)
 int memPoolsTotalAllocated(void) STUB_RETVAL(0)
 
diff -u -r -N squid-4.0.7/tools/systemd/squid.service squid-4.0.8/tools/systemd/squid.service
--- squid-4.0.7/tools/systemd/squid.service	2016-02-24 06:47:50.000000000 +1300
+++ squid-4.0.8/tools/systemd/squid.service	2016-04-02 10:04:07.000000000 +1300
@@ -8,13 +8,14 @@
 [Unit]
 Description=Squid Web Proxy Server
 Documentation=man:squid(8)
-After=network.target
+After=network.target nss-lookup.target
 
 [Service]
-Type=simple
-ExecStart=/usr/sbin/squid -sYC -N
+Type=forking
+PIDFile=/var/run/squid.pid
+ExecStart=/usr/sbin/squid -sYC
 ExecReload=/bin/kill -HUP $MAINPID
-KillMode=process
+KillMode=mixed
 
 [Install]
 WantedBy=multi-user.target
