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

Http compression only working when using localhost #26980

Closed
sladeos opened this issue Oct 12, 2017 · 5 comments
Closed

Http compression only working when using localhost #26980

sladeos opened this issue Oct 12, 2017 · 5 comments

Comments

@sladeos
Copy link

sladeos commented Oct 12, 2017

Elasticsearch version (bin/elasticsearch --version): 5.5.2, 5.6.0, 5.6.2

Plugins installed: []

JVM version (java -version): 1.8.0_131, 1.8.0_144

OS version (uname -a if on a Unix-like system): 4.4.0-97-generic #120-Ubuntu SMP Tue Sep 19 17:28:18 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux. Windows 10.

Description of the problem including expected versus actual behavior:
Expected behaviour is that if http.compression is not turned off and a request is made with the Accept-Encoding header that responses are compressed and that the content-encoding header is set with the correct encoding type, regardless of the host address.
Responses are only compressed when issuing requests to localhost. When using another address (local ip address, 127.0.0.1) no Content-Encoding header is sent and responses are not compressed.

Steps to reproduce:

  1. Install elastic and specify two network.hosts addresses. [localhost, local ip address]

  2. Visit localhost:9200/_nodes/settings?pretty and localipaddress:9200/_nodes/settings?pretty and view the response headers.

  3. Localhost

  • HTTP/1.1 200 OK
    content-type: application/json; charset=UTF-8
    content-encoding: gzip
    content-length: 549
  1. Local ip request
  • Content-Length:1667
    content-type:application/json; charset=UTF-8
@tlrx
Copy link
Member

tlrx commented Oct 12, 2017

Quick test I did on 5.6.2:

$ cat config/elasticsearch.yml | grep network
network.host: ["localhost","127.0.0.1","192.168.1.15"]

Now testing with curl with no Accept-Encoding header on http://localhost:9200, http://127.0.0.1:9200, http://192.168.1.15:9200 and http://laptop:9200 all return the same response headers:

curl -v -H 'Content-Type: application/json' -XGET 'http://localhost:9200/_nodes/settings?pretty&filter_path=cluster_name' 

* Connected to localhost (127.0.0.1) port 9200 (#0)
> GET /_nodes/settings?pretty&filter_path=cluster_name HTTP/1.1
> Host: localhost:9200
> User-Agent: curl/7.52.1
> Accept: */*
> Content-Type: application/json

< HTTP/1.1 200 OK
< content-type: application/json; charset=UTF-8
< content-length: 39
< 
{
  "cluster_name" : "elasticsearch"
}

The test but with Accept-Encoding: gzip header returns:

curl -v -H 'Content-Type: application/json' -H 'Accept-Encoding: gzip' -XGET 'http://localhost:9200/_nodes/settings?pretty&filter_path=cluster_name'

* Connected to localhost (127.0.0.1) port 9200 (#0)
> GET /_nodes/settings?pretty&filter_path=cluster_name HTTP/1.1
> Host: localhost:9200
> User-Agent: curl/7.52.1
> Accept: */*
> Content-Type: application/json
> Accept-Encoding: gzip

< HTTP/1.1 200 OK
< content-type: application/json; charset=UTF-8
< content-encoding: gzip
< content-length: 65
< 
���RPPJ�)-.I-��K�MUR�RPJ�I,.�L.NM,J�P���������m,'%      

I have the same result if I use http://127.0.0.1:9200, http://192.168.1.15:9200 and http://laptop:9200 and I think this is the expected behaviour.

@sladeos
Copy link
Author

sladeos commented Oct 12, 2017

It indeed compresses on hosts other than localhost when issuing the requests with curl, however when using postman or a web browser it does not. Not really sure what this could be caused by.

@tlrx
Copy link
Member

tlrx commented Oct 12, 2017

I'm going to close this issue then.

@tlrx tlrx closed this as completed Oct 12, 2017
@sladeos
Copy link
Author

sladeos commented Oct 12, 2017

Any insight as to why it only compresses responses when sending with curl and not with postman, chrome, firefox, etc. would be greatly appreciated.

@tlrx
Copy link
Member

tlrx commented Oct 12, 2017

These tools adds extra headers to the HTTP request. You can see that on Firefox or Chrome by opening the "Development Tools" and look at the network tabs. curl won't alter the HTTP request so it is the easiest way to send appropriate headers and see the HTTP response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants