Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Schore <mike.schore@gmail.com>
  • Loading branch information
goaway committed Sep 22, 2020
1 parent 7f89085 commit cb17c90
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 164 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// NOLINT(namespace-envoy)
#include "library/common/extensions/filters/http/platform_bridge/c_types.h"

#include "envoy/http/filter.h"

#include "library/common/extensions/filters/http/platform_bridge/c_types.h"

const envoy_filter_headers_status_t kEnvoyFilterHeadersStatusContinue =
static_cast<envoy_filter_headers_status_t>(Envoy::Http::FilterHeadersStatus::Continue);
const envoy_filter_headers_status_t kEnvoyFilterHeadersStatusStopIteration =
Expand Down
36 changes: 21 additions & 15 deletions library/common/extensions/filters/http/platform_bridge/filter.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "library/common/extensions/filters/http/platform_bridge/filter.h"
#include "library/common/extensions/filters/http/platform_bridge/c_type_definitions.h"

#include "envoy/server/filter_config.h"

Expand All @@ -9,6 +8,7 @@
#include "library/common/api/external.h"
#include "library/common/buffer/bridge_fragment.h"
#include "library/common/buffer/utility.h"
#include "library/common/extensions/filters/http/platform_bridge/c_type_definitions.h"
#include "library/common/http/header_utility.h"

namespace Envoy {
Expand Down Expand Up @@ -60,9 +60,8 @@ void PlatformBridgeFilter::onDestroy() {
void PlatformBridgeFilter::replaceHeaders(Http::HeaderMap& headers, envoy_headers c_headers) {
headers.clear();
for (envoy_header_size_t i = 0; i < c_headers.length; i++) {
headers.addCopy(
Http::LowerCaseString(Http::Utility::convertToString(c_headers.headers[i].key)),
Http::Utility::convertToString(c_headers.headers[i].value));
headers.addCopy(Http::LowerCaseString(Http::Utility::convertToString(c_headers.headers[i].key)),
Http::Utility::convertToString(c_headers.headers[i].value));
}
// The C envoy_headers struct can be released now because the headers have been copied.
release_envoy_headers(c_headers);
Expand Down Expand Up @@ -91,7 +90,7 @@ Http::FilterHeadersStatus PlatformBridgeFilter::onHeaders(Http::HeaderMap& heade
default:
PANIC("invalid filter state: unsupported status for platform filters");
}

NOT_REACHED_GCOVR_EXCL_LINE;
}

Expand Down Expand Up @@ -150,7 +149,8 @@ Http::FilterDataStatus PlatformBridgeFilter::onData(Buffer::Instance& data, bool

case kEnvoyFilterDataStatusResumeIteration:
if (iteration_state_ != IterationState::Stopped) {
PANIC("invalid filter state: ResumeIteration may only be used when filter iteration is stopped");
PANIC("invalid filter state: ResumeIteration may only be used when filter iteration is "
"stopped");
}
if (result.extra_headers) {
PlatformBridgeFilter::replaceHeaders(**pending_headers, *result.extra_headers);
Expand All @@ -169,8 +169,7 @@ Http::FilterDataStatus PlatformBridgeFilter::onData(Buffer::Instance& data, bool
}

Http::FilterTrailersStatus
PlatformBridgeFilter::onTrailers(Http::HeaderMap& trailers,
Buffer::Instance* internal_buffer,
PlatformBridgeFilter::onTrailers(Http::HeaderMap& trailers, Buffer::Instance* internal_buffer,
Http::HeaderMap** pending_headers,
envoy_filter_on_trailers_f on_trailers) {
// Allow nullptr to act as no-op.
Expand All @@ -184,7 +183,8 @@ PlatformBridgeFilter::onTrailers(Http::HeaderMap& trailers,
switch (result.status) {
case kEnvoyFilterTrailersStatusContinue:
if (iteration_state_ == IterationState::Stopped) {
PANIC("invalid filter state: ResumeIteration may only be used when filter iteration is stopped");
PANIC("invalid filter state: ResumeIteration may only be used when filter iteration is "
"stopped");
}
PlatformBridgeFilter::replaceHeaders(trailers, result.trailers);
return Http::FilterTrailersStatus::Continue;
Expand All @@ -195,7 +195,8 @@ PlatformBridgeFilter::onTrailers(Http::HeaderMap& trailers,

case kEnvoyFilterTrailersStatusResumeIteration:
if (iteration_state_ != IterationState::Stopped) {
PANIC("invalid filter state: ResumeIteration may only be used when filter iteration is stopped");
PANIC("invalid filter state: ResumeIteration may only be used when filter iteration is "
"stopped");
}
if (result.extra_headers) {
PlatformBridgeFilter::replaceHeaders(**pending_headers, *result.extra_headers);
Expand All @@ -204,7 +205,8 @@ PlatformBridgeFilter::onTrailers(Http::HeaderMap& trailers,
}
if (result.extra_data) {
internal_buffer->drain(internal_buffer->length());
internal_buffer->addBufferFragment(*Buffer::BridgeFragment::createBridgeFragment(*result.extra_data));
internal_buffer->addBufferFragment(
*Buffer::BridgeFragment::createBridgeFragment(*result.extra_data));
free(result.extra_data);
}
PlatformBridgeFilter::replaceHeaders(trailers, result.trailers);
Expand Down Expand Up @@ -246,7 +248,8 @@ Http::FilterDataStatus PlatformBridgeFilter::decodeData(Buffer::Instance& data,
});
}

return onData(data, end_stream, internal_buffer, &pending_request_headers_, platform_filter_.on_request_data);
return onData(data, end_stream, internal_buffer, &pending_request_headers_,
platform_filter_.on_request_data);
}

Http::FilterDataStatus PlatformBridgeFilter::encodeData(Buffer::Instance& data, bool end_stream) {
Expand All @@ -258,7 +261,8 @@ Http::FilterDataStatus PlatformBridgeFilter::encodeData(Buffer::Instance& data,
});
}

return onData(data, end_stream, internal_buffer, &pending_response_headers_, platform_filter_.on_response_data);
return onData(data, end_stream, internal_buffer, &pending_response_headers_,
platform_filter_.on_response_data);
}

Http::FilterTrailersStatus PlatformBridgeFilter::decodeTrailers(Http::RequestTrailerMap& trailers) {
Expand All @@ -270,7 +274,8 @@ Http::FilterTrailersStatus PlatformBridgeFilter::decodeTrailers(Http::RequestTra
});
}

auto status = onTrailers(trailers, internal_buffer, &pending_request_headers_, platform_filter_.on_request_trailers);
auto status = onTrailers(trailers, internal_buffer, &pending_request_headers_,
platform_filter_.on_request_trailers);
if (status == Http::FilterTrailersStatus::StopIteration) {
pending_request_trailers_ = &trailers;
}
Expand All @@ -287,7 +292,8 @@ PlatformBridgeFilter::encodeTrailers(Http::ResponseTrailerMap& trailers) {
});
}

auto status = onTrailers(trailers, internal_buffer, &pending_response_headers_, platform_filter_.on_response_trailers);
auto status = onTrailers(trailers, internal_buffer, &pending_response_headers_,
platform_filter_.on_response_trailers);
if (status == Http::FilterTrailersStatus::StopIteration) {
pending_response_trailers_ = &trailers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ class PlatformBridgeFilter final : public Http::PassThroughFilter,
Http::FilterHeadersStatus onHeaders(Http::HeaderMap& headers, bool end_stream,
envoy_filter_on_headers_f on_headers);
Http::FilterDataStatus onData(Buffer::Instance& data, bool end_stream,
Buffer::Instance* internal_buffer,
Http::HeaderMap** pending_headers,
envoy_filter_on_data_f on_data);
Buffer::Instance* internal_buffer,
Http::HeaderMap** pending_headers, envoy_filter_on_data_f on_data);
Http::FilterTrailersStatus onTrailers(Http::HeaderMap& trailers,
Buffer::Instance* internal_buffer,
Http::HeaderMap** pending_headers,
Expand Down
Loading

0 comments on commit cb17c90

Please sign in to comment.