Repository: envoyproxy/envoy
File: source/extensions/bootstrap/reverse_tunnel/common/reverse_connection_utility.h (C/C++)

Code before:
#pragma once

#include <string>

#include "envoy/buffer/buffer.h"
#include "envoy/network/connection.h"

#include "source/common/buffer/buffer_impl.h"
#include "source/common/common/logger.h"
#include "source/common/http/header_map_impl.h"
#include "source/common/http/headers.h"

#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"

namespace Envoy {
namespace Extensions {
namespace Bootstrap {
namespace ReverseConnection {

class ReverseConnectionUtility : public Logger::Loggable<Logger::Id::connection> {
public:
  static constexpr absl::string_view PING_MESSAGE = "RPING";
  static constexpr absl::string_view PROXY_MESSAGE = "PROXY";
  static constexpr absl::string_view kDefaultReverseTunnelRequestPath =
      "/reverse_connections/request";

  static bool isPingMessage(absl::string_view data);

  static Buffer::InstancePtr createPingResponse();

  static bool sendPingResponse(Network::Connection& connection);

  static Api::IoCallUint64Result sendPingResponse(Network::IoHandle& io_handle);

  static bool handlePingMessage(absl::string_view data, Network::Connection& connection);

  static bool extractPingFromHttpData(absl::string_view http_data);

private:
  ReverseConnectionUtility() = delete;
};

// Header names used by reverse tunnel handshake over HTTP.
inline const Http::LowerCaseString& reverseTunnelNodeIdHeader() {
  static const Http::LowerCaseString kHeader{
      absl::StrCat(Http::Headers::get().prefix(), "-reverse-tunnel-node-id")};
  return kHeader;
}


Review comment (suggestion):
Envoy code styles are using `CONSTANT_VAR` values, and Google C++ styles recommend `k*`, I am fine either way, but would be good to unify it.

Code after:
#pragma once

#include <string>

#include "envoy/buffer/buffer.h"
#include "envoy/network/connection.h"

#include "source/common/buffer/buffer_impl.h"
#include "source/common/common/logger.h"
#include "source/common/http/header_map_impl.h"
#include "source/common/http/headers.h"

#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"

namespace Envoy {
namespace Extensions {
namespace Bootstrap {
namespace ReverseConnection {

class ReverseConnectionUtility : public Logger::Loggable<Logger::Id::connection> {
public:
  static constexpr absl::string_view PING_MESSAGE = "RPING";
  static constexpr absl::string_view PROXY_MESSAGE = "PROXY";
  static constexpr absl::string_view DEFAULT_REVERSE_TUNNEL_REQUEST_PATH =
      "/reverse_connections/request";

  static bool isPingMessage(absl::string_view data);

  static Buffer::InstancePtr createPingResponse();

  static bool sendPingResponse(Network::Connection& connection);

  static Api::IoCallUint64Result sendPingResponse(Network::IoHandle& io_handle);

  static bool handlePingMessage(absl::string_view data, Network::Connection& connection);

  static bool extractPingFromHttpData(absl::string_view http_data);

private:
  ReverseConnectionUtility() = delete;
};

// Header names used by reverse tunnel handshake over HTTP.
inline const Http::LowerCaseString& reverseTunnelNodeIdHeader() {
  static const Http::LowerCaseString kHeader{
      absl::StrCat(Http::Headers::get().prefix(), "-reverse-tunnel-node-id")};
  return kHeader;
}