Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Increment the:
[#4245](https://github.com/open-telemetry/opentelemetry-cpp/pull/4245)
* [CONFIGURATION] Add the probability sampler to file configuration
[#4334](https://github.com/open-telemetry/opentelemetry-cpp/pull/4334)
* [BUG] Stop reading past a `nostd::string_view` that is not NUL terminated
[#4346](https://github.com/open-telemetry/opentelemetry-cpp/pull/4346)

* [OTLP/HTTP] Honor `Retry-After` response header when retrying exports,
supporting both delay-seconds and HTTP-date formats per RFC 7231 §7.1.3.
Expand Down
2 changes: 1 addition & 1 deletion examples/http/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void sendRequest(const std::string &url)
span->SetAttribute(semconv::http::kHttpResponseStatusCode, status_code);
result.GetResponse().ForEachHeader(
[&span](nostd::string_view header_name, nostd::string_view header_value) {
span->SetAttribute("http.header." + std::string(header_name.data()), header_value);
span->SetAttribute("http.header." + std::string(header_name), header_value);
return true;
});

Expand Down
2 changes: 1 addition & 1 deletion exporters/elasticsearch/src/es_log_record_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ResponseHandler : public http_client::EventHandler
ss << "Status:" << response.GetStatusCode() << ", Header:";
response.ForEachHeader([&ss](opentelemetry::nostd::string_view header_name,
opentelemetry::nostd::string_view header_value) {
ss << "\t" << header_name.data() << ": " << header_value.data() << ",";
ss << "\t" << header_name << ": " << header_value << ",";
return true;
});
ss << "Body:" << body;
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/src/otlp_http_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ResponseHandler : public http_client::EventHandler
ss << "Status:" << response.GetStatusCode() << ", Header:";
response.ForEachHeader([&ss](opentelemetry::nostd::string_view header_name,
opentelemetry::nostd::string_view header_value) {
ss << "\t" << header_name.data() << ": " << header_value.data() << ",";
ss << "\t" << header_name << ": " << header_value << ",";
return true;
});
ss << "Body:" << body;
Expand Down
4 changes: 2 additions & 2 deletions ext/include/opentelemetry/ext/http/client/http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <chrono>
#include <cstdint>
#include <cstring>
#include <map>
#include <memory>
#include <string>
Expand Down Expand Up @@ -148,7 +147,8 @@ struct HttpSslOptions
ssl_cipher_suite(input_ssl_cipher_suite)
{
/* Use SSL if url starts with "https:" */
if (strncmp(url.data(), "https:", 6) == 0)
const nostd::string_view https_scheme{"https:"};
if (url.substr(0, https_scheme.size()) == https_scheme)
{
use_ssl = true;
}
Expand Down
24 changes: 24 additions & 0 deletions ext/test/http/url_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
#include <tuple>
#include <variant>

#include "opentelemetry/ext/http/client/http_client.h"
#include "opentelemetry/ext/http/common/url_parser.h"
#include "opentelemetry/nostd/string_view.h"

namespace http_common = opentelemetry::ext::http::common;
namespace http_client = opentelemetry::ext::http::client;
namespace nostd = opentelemetry::nostd;

namespace
{
Expand Down Expand Up @@ -142,4 +146,24 @@ TEST_P(UrlDecoderTests, BasicTests)
EXPECT_EQ(actual, expected);
}

http_client::HttpSslOptions SslOptionsFor(nostd::string_view url)
{
return http_client::HttpSslOptions{url, false, "", "", "", "", "", "", "", "", "", ""};
}

// HttpSslOptions decides use_ssl from the scheme the caller passed, and the url is a string_view,
// so it can be a window onto a longer buffer. Reading one byte past it changes the answer: a view
// holding "https" over a buffer that continues with a colon reads as a secure scheme.
TEST(HttpSslOptionsTests, UsesOnlyTheGivenUrlToDecideTheScheme)
{
const char buffer[] = "https://example.com";

EXPECT_TRUE(SslOptionsFor(nostd::string_view{buffer}).use_ssl);
EXPECT_FALSE(SslOptionsFor(nostd::string_view{"http://example.com"}).use_ssl);

// The same buffer, but the caller offers only the five characters before the colon.
EXPECT_FALSE(SslOptionsFor(nostd::string_view{buffer, 5}).use_ssl)
<< "read past the end of the url view";
}

} // namespace
Loading