oschaaf commented on a change in pull request #1969: Integration of envoy fetcher in pagespeed URL: https://github.com/apache/incubator-pagespeed-mod/pull/1969#discussion_r358741100
########## File path: pagespeed/envoy/pagespeed_remote_data_fetcher.h ########## @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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_cluster_manager.h" + + +namespace net_instaweb { + +/** + * Failure reason. + */ +enum class FailureReason { + /* A network error occurred causing remote data retrieval failure. */ + Network, + /* A failure occurred when trying to verify remote data using sha256. */ + InvalidData, +}; + +/** + * Callback used by remote data fetcher. + */ +class PagespeedRemoteDataFetcherCallback { +public: + virtual ~PagespeedRemoteDataFetcherCallback() = default; + + /** + * This function will be called when data is fetched successfully from remote. + * @param data remote data + */ + virtual void onSuccess(Envoy::Http::MessagePtr& response) PURE; + + /** + * This function is called when error happens during fetching data. + * @param reason failure reason. + */ + virtual void onFailure(FailureReason reason) PURE; +}; + +/** + * Remote data fetcher. + */ +class PagespeedRemoteDataFetcher : public Envoy::Logger::Loggable<Envoy::Logger::Id::config>, + public Envoy::Http::AsyncClient::Callbacks { +public: + PagespeedRemoteDataFetcher(Envoy::Upstream::ClusterManager& cm, const ::envoy::api::v2::core::HttpUri& uri, + PagespeedRemoteDataFetcherCallback& callback); + + ~PagespeedRemoteDataFetcher() override; + + // Http::AsyncClient::Callbacks + void onSuccess(Envoy::Http::MessagePtr&& response) override; + void onFailure(Envoy::Http::AsyncClient::FailureReason reason) override; + + /** + * Fetch data from remote. + * @param uri remote URI Review comment: These comments don't seem to match the arguments to `fetch()` below? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services