Use case-insensitive comparison for headers fix #2100 (#2101)

* Use case-inseneitive comparison for headers

HTTP headers should be case-insensitive. Use case-insensitive string
comparisons when working with HTTP header responses to ensure
compatibility.

* Revert "Use case-inseneitive comparison for headers"

This reverts commit a02f591723506b62b7208449be6eef7122120398

* Ignore case when searching HTTP header responses

Looking up the Content-Length in the header returned by S3 storage
endpoints should ignore case. To guarantee portability implement a
function for case-insensitive string search, because it is non-standard.

* Add an _ after H5 for the strcasestr implementation

It is a private function and should sport that underscore.

* Remove author comment from the doc comment

* Use search function defined by system if available

Check whether the system provides a function implementing case
insensitive string searches. Only use the custom implementation if the
system does not provide the functionality.

* Add tests for case-insensitive search

Basic tests:
  - Search for empty string
  - Search with exact match
  - Search with case-insensitive match
  - search with no match

* Enforce clang-format style

Some variable definitions in the th5_system tests did not conform to
clang-format's expectations. Updated the offending lines.

* Correct comment describing test case

* Added some spaces to please clang-format

* Ignore discarding const

Ask the compiler to ignore discarding the const when retunring a match from H5_strcasestr

Co-authored-by: Frank Berghaus <frank.berghaus@mpcdf.mpg.de>
This commit is contained in:
Frank Berghaus
2022-09-21 18:50:17 +02:00
committed by GitHub
parent d491c33a72
commit 100b22e6c2
8 changed files with 80 additions and 2 deletions

View File

@@ -437,6 +437,31 @@ test_h5_basename(void)
HDfree(path);
}
static void
test_h5_strcasestr(void)
{
const char *const haystack = "My test string";
char *str = NULL;
MESSAGE(5, ("Testing H5_strcasestr\n"));
/* check that H5_strcasestr returns target in empty search */
str = H5_strcasestr(haystack, "");
CHECK_PTR_EQ(str, haystack, "H5_strcasestr search for empty");
/* Check that H5_strcasestr find a string of same case */
str = H5_strcasestr(haystack, "string");
CHECK_PTR_EQ(str, &(haystack[8]), "H5_strcasestr search same case");
/* Check that H5_strcasestr find a string of different case */
str = H5_strcasestr(haystack, "sTrInG");
CHECK_PTR_EQ(str, &(haystack[8]), "H5_strcasestr search different case");
/* Check that H5_strcasestr returns NULL if no match is found */
str = H5_strcasestr(haystack, "nomatch");
CHECK_PTR_NULL(str, "H5_strcasestr search with no match");
}
static void
test_h5_strndup(void)
{
@@ -495,6 +520,7 @@ test_h5_system(void)
test_h5_dirname();
test_h5_basename();
test_h5_strcasestr();
test_h5_strndup();
}