Fix answer_type::get_header().
continuous-integration/drone/push Build is passing Details

The previous implementation returned a reference to an out-of-scope string.
This commit is contained in:
tastytea 2020-01-09 15:54:52 +01:00
parent 913130b57d
commit 7ba967a36c
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 4 additions and 2 deletions

View File

@ -103,7 +103,9 @@ struct answer_type
/*!
* @brief Returns the value of a header field.
*
* Case insensitive, only ASCII.
* Is only valid for as long as the answer_type is in scope.
*
* @param field Case insensitive, only ASCII.
*
* @since 0.1.0
*/

View File

@ -54,7 +54,7 @@ string_view answer_type::get_header(const string_view field) const
auto pos{static_cast<size_t>(it - headers.begin())};
pos = headers.find(':', pos) + 2;
const auto endpos{headers.find('\n', pos)};
return headers.substr(pos, endpos - pos);
return string_view(&headers[pos], endpos - pos);
}
return {};