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

Feature/removing accept encoding header when using symfony http client #37

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
- job:
name: elastic+enterprise-search-php+8.5
display-name: 'elastic / enterprise-search-php # 8.5'
description: Testing the enterprise-search-php 8.5 branch.
name: elastic+enterprise-search-php+8.7
display-name: 'elastic / enterprise-search-php # 8.7'
description: Testing the enterprise-search-php 8.7 branch.
parameters:
- string:
name: branch_specifier
default: refs/heads/8.5
default: refs/heads/8.7
description: the Git branch specifier to build (<branchName>, <tagName>,
<commitId>, etc.)
triggers:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 8.7.1 (2023-06-01)

- Removes Accept-Encoding (gzip) header when using Symfony HTTP client

## 8.7.0 (2023-04-04)

Release compatible with Enterprise Search, App Search and Workplace Search 8.7.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"require-dev": {
"phpunit/phpunit": "^9.5",
"guzzlehttp/guzzle": "^7.0",
"phpstan/phpstan": "^1.8"
"phpstan/phpstan": "^1.8",
"symfony/http-client": "^6.0"
},
"suggest": {
"guzzlehttp/guzzle": "We suggest to use Guzzle as PSR-18 HTTP library"
Expand Down
17 changes: 15 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

class Client
{
const VERSION = '8.6.0';
const VERSION = '8.7.0';

private array $config = [];

Expand Down Expand Up @@ -110,7 +110,9 @@ private function initTransport(Transport $transport, array $config): void
if (!isset($config['meta-header']) || $config['meta-header']) {
$transport->setElasticMetaHeader('ent', self::VERSION);
}
$transport->setHeader('Accept-Encoding', 'gzip');
if (!$this->isSymfonyHttpClient($transport)) {
$transport->setHeader('Accept-Encoding', 'gzip');
}
}

/**
Expand Down Expand Up @@ -185,4 +187,15 @@ private function setAuthentication(Transport $transport, array $config, string $
'You need to use an authentication method: username and password, token or apiKey'
);
}

private function isSymfonyHttpClient(Transport $transport): bool
{
if (false !== strpos(get_class($transport->getClient()), 'Symfony\Component\HttpClient')) {
return true;
}
if (false !== strpos(get_class($transport->getAsyncClient()), 'Symfony\Component\HttpClient')) {
return true;
}
return false;
}
}