Skip to content

Commit

Permalink
Do not include default headers by default
Browse files Browse the repository at this point in the history
  • Loading branch information
David Bouchare committed Apr 18, 2019
1 parent d22df1a commit a38df53
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion http_check/datadog_checks/http_check/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def from_instance(instance, default_ca_certs=None):
http_response_status_code = str(instance.get('http_response_status_code', DEFAULT_EXPECTED_CODE))
timeout = int(instance.get('timeout', 10))
config_headers = instance.get('headers', {})
default_headers = is_affirmative(instance.get("include_default_headers", True))
default_headers = is_affirmative(instance.get("include_default_headers", False))
if default_headers:
headers = agent_headers({})
else:
Expand Down
4 changes: 2 additions & 2 deletions http_check/datadog_checks/http_check/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ instances:
#
# stream: false

## @param include_default_headers - boolean - optional - default: true
## @param include_default_headers - boolean - optional - default: false
## The (optional) include_default_headers parameter instructs the check to include the default headers.
## Default headers can be found at:
## https://github.com/DataDog/integrations-core/blob/master/datadog_checks_base/datadog_checks/utils/headers.py
#
# include_default_headers: true
# include_default_headers: false

## @param tags - list of key:value element - optional
## List of tags to attach to every metric, event and service check emitted by this integration.
Expand Down
6 changes: 0 additions & 6 deletions http_check/datadog_checks/http_check/http_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@ def send_status_down(loginfo, down_msg):
if suppress_warning:
warnings.simplefilter('ignore', InsecureRequestWarning)

# GET requests do not need headers that include Content-Type, as some firewalls may block them
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
if method == 'get' and headers['Content-Type'] == 'application/x-www-form-urlencoded':
headers.pop('Content-Type')
self.log.debug("Stripping headers from Content-Type")

r = sess.request(
method.upper(),
addr,
Expand Down
7 changes: 2 additions & 5 deletions http_check/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import pytest

from datadog_checks.base import ConfigurationError
from datadog_checks.http_check.config import DEFAULT_EXPECTED_CODE, from_instance
from datadog_checks.utils.headers import headers as agent_headers
from datadog_checks.http_check.config import from_instance, DEFAULT_EXPECTED_CODE


@pytest.mark.unit
Expand Down Expand Up @@ -50,7 +49,7 @@ def test_from_instance():
# default `include_content` is False
assert params[10] is False
# default headers
assert params[11] == agent_headers({})
assert params[11] == {}
# default `collect_response_time` is True
assert params[12] is True
# default `content_match` is None
Expand Down Expand Up @@ -84,9 +83,7 @@ def test_from_instance():
)

headers = params[11]
expected_headers = agent_headers({}).get('User-Agent')
assert headers["X-Auth-Token"] == "SOME-AUTH-TOKEN", headers
assert expected_headers == headers.get('User-Agent'), headers

# proxy
params = from_instance({'url': 'https://example.com', 'name': 'UpService', 'no_proxy': True})
Expand Down

0 comments on commit a38df53

Please sign in to comment.