Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for gzip and deflate encoding #593

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.5.1.dev2",
"regenerated": "2021-09-27 09:40:37.419998",
"spec_repo_commit": "c02444e"
"regenerated": "2021-09-28 11:30:21.345145",
"spec_repo_commit": "4a04b77"
},
"v2": {
"apigentools_version": "1.5.1.dev2",
"regenerated": "2021-09-27 09:40:59.645682",
"spec_repo_commit": "c02444e"
"regenerated": "2021-09-28 11:30:43.932927",
"spec_repo_commit": "4a04b77"
}
}
}
6 changes: 6 additions & 0 deletions .generator/templates/rest.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import logging
import re
import ssl
from urllib.parse import urlencode
import zlib

import urllib3

Expand Down Expand Up @@ -141,6 +142,11 @@ class RESTClientObject(object):
request_body = None
if body is not None:
request_body = json.dumps(body)
if headers.get("Content-Encoding") == "gzip":
compress = zlib.compressobj(wbits=16 + zlib.MAX_WBITS)
request_body = compress.compress(request_body.encode("utf-8")) + compress.flush()
elif headers.get("Content-Encoding") == "deflate":
request_body = zlib.compress(request_body.encode("utf-8"))
r = self.pool_manager.request(
method, url,
body=request_body,
Expand Down
4 changes: 2 additions & 2 deletions src/datadog_api_client/v1/model/content_encoding.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/datadog_api_client/v1/openapi.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/datadog_api_client/v1/rest.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/datadog_api_client/v2/rest.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/v1/features/logs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ Feature: Logs
When the request is sent
Then the response status is 200 OK

@integration-only
Scenario: Send deflate logs returns "Response from server (always 200 empty JSON)." response
Given new "SubmitLog" request
And body with value [{"message": "{{ unique }}", "ddtags": "host:{{ unique_alnum }}"}]
And request contains "content_encoding" parameter with value "deflate"
When the request is sent
Then the response status is 200 Response from server (always 200 empty JSON).

@integration-only
Scenario: Send gzip logs returns "Response from server (always 200 empty JSON)." response
Given new "SubmitLog" request
And body with value [{"message": "{{ unique }}", "ddtags": "host:{{ unique_alnum }}"}]
And request contains "content_encoding" parameter with value "gzip"
When the request is sent
Then the response status is 200 Response from server (always 200 empty JSON).

Scenario: Send logs returns "Response from server (always 200 empty JSON)." response
Given new "SubmitLog" request
And body with value [{"message": "{{ unique }}", "ddtags": "host:{{ unique_alnum }}"}]
Expand Down