diff --git a/src/envoy/upstreams/http/metadata/BUILD b/src/envoy/upstreams/http/metadata/BUILD new file mode 100644 index 00000000000..85cb11e0ed9 --- /dev/null +++ b/src/envoy/upstreams/http/metadata/BUILD @@ -0,0 +1,50 @@ +# Copyright 2021 Istio Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +# + +load( + "@envoy//bazel:envoy_build_system.bzl", + "envoy_cc_library", + "envoy_cc_test", + "envoy_package", +) + +envoy_package() + +envoy_cc_library( + name = "upstream_request_lib", + srcs = ["upstream_request.cc"], + hdrs = ["upstream_request.h"], + repository = "@envoy", + deps = [ + "@envoy//include/envoy/http:codec_interface", + "@envoy//include/envoy/router:router_interface", + "@envoy//source/extensions/upstreams/http/http:upstream_request_lib", + ], +) + +envoy_cc_test( + name = "upstream_request_test", + srcs = ["upstream_request_test.cc"], + repository = "@envoy", + deps = [ + ":upstream_request_lib", + "@envoy//test/common/http:common_lib", + "@envoy//test/mocks/http:stream_encoder_mock", + "@envoy//test/mocks/router:router_mocks", + "@envoy//test/test_common:utility_lib", + ], +) diff --git a/src/envoy/upstreams/http/metadata/upstream_request.cc b/src/envoy/upstreams/http/metadata/upstream_request.cc new file mode 100644 index 00000000000..c4ea50422fa --- /dev/null +++ b/src/envoy/upstreams/http/metadata/upstream_request.cc @@ -0,0 +1,16 @@ +/* Copyright 2021 Istio Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "src/envoy/upstreams/http/metadata/upstream_request.h" diff --git a/src/envoy/upstreams/http/metadata/upstream_request.h b/src/envoy/upstreams/http/metadata/upstream_request.h new file mode 100644 index 00000000000..60203710666 --- /dev/null +++ b/src/envoy/upstreams/http/metadata/upstream_request.h @@ -0,0 +1,38 @@ +/* Copyright 2021 Istio Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "envoy/http/codec.h" +#include "envoy/router/router.h" +#include "extensions/upstreams/http/http/upstream_request.h" + +namespace Envoy { +namespace Upstreams { +namespace Http { +namespace Metadata { + +class MetadataUpstream + : public Extensions::Upstreams::Http::Http::HttpUpstream { + public: + MetadataUpstream(Router::UpstreamToDownstream& upstream_request, + Envoy::Http::RequestEncoder* encoder) + : HttpUpstream(upstream_request, encoder) {} +}; + +} // namespace Metadata +} // namespace Http +} // namespace Upstreams +} // namespace Envoy diff --git a/src/envoy/upstreams/http/metadata/upstream_request_test.cc b/src/envoy/upstreams/http/metadata/upstream_request_test.cc new file mode 100644 index 00000000000..969af063df9 --- /dev/null +++ b/src/envoy/upstreams/http/metadata/upstream_request_test.cc @@ -0,0 +1,49 @@ +/* Copyright 2021 Istio Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "src/envoy/upstreams/http/metadata/upstream_request.h" + +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" +#include "test/common/http/common.h" +#include "test/mocks/http/stream_encoder.h" +#include "test/mocks/router/mocks.h" +#include "test/test_common/utility.h" + +namespace Envoy { +namespace Upstreams { +namespace Http { +namespace Metadata { + +class MetadataUpstreamTest : public ::testing::Test { + protected: + Router::MockUpstreamToDownstream upstream_to_downstream_; + ::testing::NiceMock encoder_; +}; + +TEST_F(MetadataUpstreamTest, Basic) { + Envoy::Http::TestRequestHeaderMapImpl headers; + HttpTestUtility::addDefaultHeaders(headers); + auto upstream = + std::make_unique(upstream_to_downstream_, &encoder_); + EXPECT_TRUE(upstream->encodeHeaders(headers, false).ok()); +} + +} // namespace Metadata +} // namespace Http +} // namespace Upstreams +} // namespace Envoy