@@ -185,7 +185,7 @@ struct flb_upstream *flb_upstream_create(struct flb_config *config,
185185 flb_net_setup_init (& u -> net );
186186
187187 /* Set upstream to the http_proxy if it is specified. */
188- if (config -> http_proxy ) {
188+ if (flb_should_proxy_for_host ( host , config -> http_proxy , config -> no_proxy ) == FLB_TRUE ) {
189189 flb_debug ("[upstream] config->http_proxy: %s" , config -> http_proxy );
190190 ret = flb_utils_proxy_url_split (config -> http_proxy , & proxy_protocol ,
191191 & proxy_username , & proxy_password ,
@@ -237,6 +237,39 @@ struct flb_upstream *flb_upstream_create(struct flb_config *config,
237237 return u ;
238238}
239239
240+ /*
241+ * Checks whehter a destinate URL should be proxied.
242+ */
243+ int flb_should_proxy_for_host (const char * host , const char * proxy , const char * no_proxy )
244+ {
245+ /* No HTTP_PROXY, should not set up proxy for the upstream `host`. */
246+ if (proxy == NULL ) {
247+ return FLB_FALSE ;
248+ }
249+
250+ /* No NO_PROXY with HTTP_PROXY set, should set up proxy for the upstream `host`. */
251+ if (no_proxy == NULL ) {
252+ return FLB_TRUE ;
253+ }
254+
255+ /* NO_PROXY=`*`, it matches all hosts. */
256+ if (strcmp (no_proxy , "*" ) == 0 ) {
257+ return FLB_FALSE ;
258+ }
259+
260+ /* check the URL list in the NO_PROXY */
261+ char * no_proxy_url = strtok (no_proxy , "," );
262+ while (no_proxy_url != NULL ) {
263+ if (strcmp (host , no_proxy_url ) == 0 ) {
264+ return FLB_FALSE ;
265+ }
266+ no_proxy_url = strtok (NULL , "," );
267+ }
268+
269+ return FLB_TRUE ;
270+ }
271+
272+
240273
241274/* Create an upstream context using a valid URL (protocol, host and port) */
242275struct flb_upstream * flb_upstream_create_url (struct flb_config * config ,
0 commit comments