Brotli: prefer new C++ API header (compressor.h).

No functional changes.

Change-Id: Ie88775d3451483ac65d0d5d9d61b896b48fe6a0e
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
Reviewed-on: https://nginx-review.googlesource.com/1171
Reviewed-by: Martin Maly <mmaly@google.com>
diff --git a/BUILD b/BUILD
index e89e15b..8ce09fa 100644
--- a/BUILD
+++ b/BUILD
@@ -46,6 +46,7 @@
     ],
     copts = nginx_cxxopts,
     defines = [
+        "NGX_HAVE_BROTLI_ENC_COMPRESSOR_H",
         "NGX_HTTP_BROTLI_FILTER",
     ],
     visibility = [
diff --git a/config b/config
index 9f4d15f..0f829c7 100644
--- a/config
+++ b/config
@@ -54,17 +54,20 @@
 fi
 
 #
-# filter module (depends on Brotli library)
+# filter module (depends on Brotli C++ library)
 #
 
+# new C++ API header (compressor.h)
+
+ngx_feature_name=NGX_HAVE_BROTLI_ENC_COMPRESSOR_H
 ngx_feature_run=no
 ngx_feature_cpp=yes
-ngx_feature_incs="#include <brotli/enc/encode.h>"
+ngx_feature_incs="#include <brotli/enc/compressor.h>"
 ngx_feature_test="brotli::BrotliParams  params;
                   params.quality = 11"
 
 # auto-discovery
-ngx_feature="Brotli library"
+ngx_feature="Brotli C++ library (compressor.h)"
 ngx_feature_cpp=yes
 ngx_feature_path=
 ngx_feature_libs="-lbrotlienc -lstdc++"
@@ -72,7 +75,7 @@
 
 if [ $ngx_found = no ]; then
     # FreeBSD, OpenBSD
-    ngx_feature="Brotli library in /usr/local/"
+    ngx_feature="Brotli C++ library (compressor.h) in /usr/local/"
     ngx_feature_cpp=yes
     ngx_feature_path="/usr/local/include"
     if [ $NGX_RPATH = YES ]; then
@@ -85,7 +88,7 @@
 
 if [ $ngx_found = no ]; then
     # NetBSD
-    ngx_feature="Brotli library in /usr/pkg/"
+    ngx_feature="Brotli C++ library (compressor.h) in /usr/pkg/"
     ngx_feature_cpp=yes
     ngx_feature_path="/usr/pkg/include"
     if [ $NGX_RPATH = YES ]; then
@@ -98,7 +101,60 @@
 
 if [ $ngx_found = no ]; then
     # MacPorts
-    ngx_feature="Brotli library in /opt/local/"
+    ngx_feature="Brotli C++ library (compressor.h) in /opt/local/"
+    ngx_feature_cpp=yes
+    ngx_feature_path="/opt/local/include"
+    if [ $NGX_RPATH = YES ]; then
+        ngx_feature_libs="-R/opt/local/lib -L/opt/local/lib -lbrotlienc -lstdc++"
+    else
+        ngx_feature_libs="-L/opt/local/lib -lbrotlienc -lstdc++"
+    fi
+    . $ngx_addon_dir/auto/feature
+fi
+
+# original C++ API header (encode.h)
+
+ngx_feature_name=
+ngx_feature_incs="#include <brotli/enc/encode.h>"
+
+if [ $ngx_found = no ]; then
+    # auto-discovery
+    ngx_feature="Brotli C++ library (encode.h)"
+    ngx_feature_cpp=yes
+    ngx_feature_path=
+    ngx_feature_libs="-lbrotlienc -lstdc++"
+    . $ngx_addon_dir/auto/feature
+fi
+
+if [ $ngx_found = no ]; then
+    # FreeBSD, OpenBSD
+    ngx_feature="Brotli C++ library (encode.h) in /usr/local/"
+    ngx_feature_cpp=yes
+    ngx_feature_path="/usr/local/include"
+    if [ $NGX_RPATH = YES ]; then
+        ngx_feature_libs="-R/usr/local/lib -L/usr/local/lib -lbrotlienc -lstdc++"
+    else
+        ngx_feature_libs="-L/usr/local/lib -lbrotlienc -lstdc++"
+    fi
+    . $ngx_addon_dir/auto/feature
+fi
+
+if [ $ngx_found = no ]; then
+    # NetBSD
+    ngx_feature="Brotli C++ library (encode.h) in /usr/pkg/"
+    ngx_feature_cpp=yes
+    ngx_feature_path="/usr/pkg/include"
+    if [ $NGX_RPATH = YES ]; then
+        ngx_feature_libs="-R/usr/pkg/lib -L/usr/pkg/lib -lbrotlienc -lstdc++"
+    else
+        ngx_feature_libs="-L/usr/pkg/lib -lbrotlienc -lstdc++"
+    fi
+    . $ngx_addon_dir/auto/feature
+fi
+
+if [ $ngx_found = no ]; then
+    # MacPorts
+    ngx_feature="Brotli C++ library (encode.h) in /opt/local/"
     ngx_feature_cpp=yes
     ngx_feature_path="/opt/local/include"
     if [ $NGX_RPATH = YES ]; then
@@ -110,7 +166,7 @@
 fi
 
 if [ $ngx_found = no ]; then
-    echo "$0: error: ngx_brotli filter module requires Brotli library."
+    echo "$0: error: ngx_brotli filter module requires Brotli C++ library."
     exit 1
 fi
 
diff --git a/src/ngx_http_brotli_filter_module.cc b/src/ngx_http_brotli_filter_module.cc
index 02280a1..19da345 100644
--- a/src/ngx_http_brotli_filter_module.cc
+++ b/src/ngx_http_brotli_filter_module.cc
@@ -12,7 +12,11 @@
   #include <ngx_http.h>
 }
 
+#if (NGX_HAVE_BROTLI_ENC_COMPRESSOR_H)
+#include <brotli/enc/compressor.h>
+#else
 #include <brotli/enc/encode.h>
+#endif
 
 
 typedef struct {