You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by as...@apache.org on 2021/11/09 00:24:33 UTC

[impala] branch master updated: IMPALA-11007: Replies to HTTP HEAD requests should contain no content.

This is an automated email from the ASF dual-hosted git repository.

asherman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git


The following commit(s) were added to refs/heads/master by this push:
     new efcf29f  IMPALA-11007: Replies to HTTP HEAD requests should contain no content.
efcf29f is described below

commit efcf29fb82b19a538ded724282b94bd3a63f05ee
Author: Andrew Sherman <as...@cloudera.com>
AuthorDate: Fri Nov 5 08:40:20 2021 -0700

    IMPALA-11007: Replies to HTTP HEAD requests should contain no content.
    
    If a HEAD request to Impala's webserver, for example
      curl -I http://localhost:25000/metrics
    does send content in the response then this results in ugly messages
    being logged on the server side when the client side closes the
    connection after it has read the headers in the http response. Fix this
    by not sending (or generating) the content in reply to the HEAD
    request.
    
    TESTING:
      Ran all end-to-end tests.
      Added HEAD calls to various existing tests.
    
    Change-Id: I5cc3bf72067dfa5bc24e29fe974e5762be507952
    Reviewed-on: http://gerrit.cloudera.org:8080/18002
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 be/src/util/webserver.cc          |  5 ++++-
 tests/webserver/test_web_pages.py | 16 ++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/be/src/util/webserver.cc b/be/src/util/webserver.cc
index c23fe00..5fbf9df 100644
--- a/be/src/util/webserver.cc
+++ b/be/src/util/webserver.cc
@@ -817,7 +817,10 @@ sq_callback_result_t Webserver::BeginRequestCallback(struct sq_connection* conne
 
   // The output of this page is accumulated into this stringstream.
   stringstream output;
-  if (!url_handler->use_templates()) {
+  if (strncmp("HEAD", request_info->request_method, 4) == 0) {
+    // For a HEAD call do not generate the response body.
+    VLOG(4) << "Not generating output for HEAD call on " << request_info->uri;
+  } else if (!url_handler->use_templates()) {
     content_type = PLAIN;
     url_handler->raw_callback()(req, &output, &response);
   } else {
diff --git a/tests/webserver/test_web_pages.py b/tests/webserver/test_web_pages.py
index bfed002..d870ec4 100644
--- a/tests/webserver/test_web_pages.py
+++ b/tests/webserver/test_web_pages.py
@@ -115,6 +115,12 @@ class TestWebPage(ImpalaTestSuite):
     assert page.status_code == requests.codes.ok
     page = requests.get("http://localhost:25020/memz")
     assert page.status_code == requests.codes.ok
+    page = requests.head("http://localhost:25000/memz")
+    assert page.status_code == requests.codes.ok
+    page = requests.head("http://localhost:25010/memz")
+    assert page.status_code == requests.codes.ok
+    page = requests.head("http://localhost:25020/memz")
+    assert page.status_code == requests.codes.ok
 
   def test_memz_shows_fragment_instance_id(self):
     """Tests that the memory breakdown on memz shows fragment instance IDs."""
@@ -161,6 +167,9 @@ class TestWebPage(ImpalaTestSuite):
     responses = []
     for port in ports_to_test:
       input_url = url.format(port)
+      response = requests.head(input_url, headers=headers)
+      assert response.status_code == requests.codes.ok, "URL: {0} Str:'{1}'\nResp:{2}"\
+        .format(input_url, string_to_search, response.text)
       response = requests.get(input_url, headers=headers)
       assert response.status_code == requests.codes.ok, "URL: {0} Str:'{1}'\nResp:{2}"\
         .format(input_url, string_to_search, response.text)
@@ -391,6 +400,9 @@ class TestWebPage(ImpalaTestSuite):
       ports_to_test = self.TEST_PORTS_WITH_SS
     for port in ports_to_test:
       input_url = url.format(port)
+      response = requests.head(input_url)
+      assert response.status_code == requests.codes.not_found, "URL: {0} Str:'{" \
+        "1}'\nResp:{2}".format(input_url, string_to_search, response.text)
       response = requests.get(input_url)
       assert response.status_code == requests.codes.not_found, "URL: {0} Str:'{" \
         "1}'\nResp:{2}".format(input_url, string_to_search, response.text)
@@ -779,6 +791,8 @@ class TestWebPage(ImpalaTestSuite):
     for port in self.TEST_PORTS_WITH_SS:
       page = requests.get(self.HEALTHZ_URL.format(port))
       assert page.status_code == requests.codes.ok
+      page = requests.head(self.HEALTHZ_URL.format(port))
+      assert page.status_code == requests.codes.ok
 
   def test_knox_compatibility(self):
     """Checks that the template files conform to the requirements for compatibility with
@@ -842,3 +856,5 @@ class TestWebPage(ImpalaTestSuite):
     """Test to check that the /operations endpoint returns 200 OK."""
     page = requests.get("http://localhost:25020/operations")
     assert page.status_code == requests.codes.ok
+    page = requests.head("http://localhost:25020/operations")
+    assert page.status_code == requests.codes.ok