diff --git a/mobile/BUILD b/mobile/BUILD index 3db77f8ca3da..375b944ff3db 100644 --- a/mobile/BUILD +++ b/mobile/BUILD @@ -130,10 +130,6 @@ xcodeproj( name = "Hello World App (ObjC)", launch_action = xcode_schemes.launch_action("//examples/objective-c/hello_world:app"), ), - xcode_schemes.scheme( - name = "Baseline App", - launch_action = xcode_schemes.launch_action("//test/swift/apps/baseline:app"), - ), xcode_schemes.scheme( name = "Experimental App", launch_action = xcode_schemes.launch_action("//test/swift/apps/experimental:app"), @@ -165,7 +161,6 @@ xcodeproj( labels = [ "//examples/objective-c/hello_world:app", "//examples/swift/hello_world:app", - "//test/swift/apps/baseline:app", "//test/swift/apps/experimental:app", ], target_environments = [ diff --git a/mobile/test/swift/apps/baseline/AppDelegate.swift b/mobile/test/swift/apps/baseline/AppDelegate.swift deleted file mode 100644 index 2f161c9b3ec7..000000000000 --- a/mobile/test/swift/apps/baseline/AppDelegate.swift +++ /dev/null @@ -1,19 +0,0 @@ -import UIKit - -@UIApplicationMain -final class AppDelegate: UIResponder, UIApplicationDelegate { - var window: UIWindow? - - func application( - _ application: UIApplication, - didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool - { - let window = UIWindow(frame: UIScreen.main.bounds) - window.rootViewController = ViewController() - window.makeKeyAndVisible() - self.window = window - - NSLog("Finished launching!") - return true - } -} diff --git a/mobile/test/swift/apps/baseline/AsyncDemoFilter.swift b/mobile/test/swift/apps/baseline/AsyncDemoFilter.swift deleted file mode 100644 index c25e10ef4352..000000000000 --- a/mobile/test/swift/apps/baseline/AsyncDemoFilter.swift +++ /dev/null @@ -1,67 +0,0 @@ -import Envoy -import Foundation - -/// Example of a more complex HTTP filter that pauses processing on the response filter chain, -/// buffers until the response is complete, then asynchronously triggers filter chain resumption -/// while setting a new header. Also demonstrates safety of re-entrancy of async callbacks. -final class AsyncDemoFilter: AsyncResponseFilter { - private var callbacks: ResponseFilterCallbacks! - - func onResponseHeaders(_ headers: ResponseHeaders, endStream: Bool, streamIntel: StreamIntel) - -> FilterHeadersStatus - { - if endStream { - DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in - self?.callbacks.resumeResponse() - } - } - return .stopIteration - } - - func onResponseData(_ body: Data, endStream: Bool, streamIntel: StreamIntel) - -> FilterDataStatus - { - if endStream { - DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in - self?.callbacks.resumeResponse() - } - } - return .stopIterationAndBuffer - } - - func onResponseTrailers( - _ trailers: ResponseTrailers, - streamIntel: StreamIntel - ) -> FilterTrailersStatus { - DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in - self?.callbacks.resumeResponse() - } - return .stopIteration - } - - func setResponseFilterCallbacks(_ callbacks: ResponseFilterCallbacks) { - self.callbacks = callbacks - } - - func onResumeResponse( - headers: ResponseHeaders?, - data: Data?, - trailers: ResponseTrailers?, - endStream: Bool, - streamIntel: StreamIntel - ) -> FilterResumeStatus { - guard let headers = headers else { - // Iteration was stopped on headers, so headers must be present. - fatalError("Filter behavior violation!") - } - let builder = headers.toResponseHeadersBuilder() - .add(name: "async-filter-demo", value: "1") - return .resumeIteration(headers: builder.build(), data: data, trailers: trailers) - } - - func onError(_ error: EnvoyError, streamIntel: FinalStreamIntel) {} - - func onCancel(streamIntel: FinalStreamIntel) {} - - func onComplete(streamIntel: FinalStreamIntel) {} -} diff --git a/mobile/test/swift/apps/baseline/BUILD b/mobile/test/swift/apps/baseline/BUILD deleted file mode 100644 index 0eccd319f4e3..000000000000 --- a/mobile/test/swift/apps/baseline/BUILD +++ /dev/null @@ -1,28 +0,0 @@ -load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application") -load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") -load("@envoy//bazel:envoy_build_system.bzl", "envoy_mobile_package") -load("//bazel:config.bzl", "MINIMUM_IOS_VERSION") - -licenses(["notice"]) # Apache 2 - -envoy_mobile_package() - -swift_library( - name = "appmain", - srcs = glob(["*.swift"]), - deps = ["//library/swift:ios_lib"], -) - -ios_application( - name = "app", - bundle_id = "io.envoyproxy.envoymobile.helloworld", - families = ["iphone"], - infoplists = ["Info.plist"], - minimum_os_version = MINIMUM_IOS_VERSION, - provisioning_profile = select({ - "@envoy//bazel:ios_arm64": "//examples:ios_provisioning_profile", - "//conditions:default": None, - }), - visibility = ["//visibility:public"], - deps = ["appmain"], -) diff --git a/mobile/test/swift/apps/baseline/Base.lproj/LaunchScreen.storyboard b/mobile/test/swift/apps/baseline/Base.lproj/LaunchScreen.storyboard deleted file mode 100644 index bfa36129419f..000000000000 --- a/mobile/test/swift/apps/baseline/Base.lproj/LaunchScreen.storyboard +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/mobile/test/swift/apps/baseline/BufferDemoFilter.swift b/mobile/test/swift/apps/baseline/BufferDemoFilter.swift deleted file mode 100644 index 1def3fb67749..000000000000 --- a/mobile/test/swift/apps/baseline/BufferDemoFilter.swift +++ /dev/null @@ -1,48 +0,0 @@ -import Envoy -import Foundation - -/// Example of a more complex HTTP filter that pauses processing on the response filter chain, -/// buffers until the response is complete, then resumes filter iteration while setting a new -/// header. -final class BufferDemoFilter: ResponseFilter { - private var headers: ResponseHeaders! - private var body: Data? - - func onResponseHeaders(_ headers: ResponseHeaders, endStream: Bool, streamIntel: StreamIntel) - -> FilterHeadersStatus - { - self.headers = headers - return .stopIteration - } - - func onResponseData(_ data: Data, endStream: Bool, streamIntel: StreamIntel) - -> FilterDataStatus - { - // Since we request buffering, each invocation will include all data buffered so far. - self.body = data - - // If this is the end of the stream, resume processing of the (now fully-buffered) response. - if endStream { - let builder = self.headers.toResponseHeadersBuilder() - .add(name: "buffer-filter-demo", value: "1") - return .resumeIteration(headers: builder.build(), data: data) - } - return .stopIterationAndBuffer - } - - func onResponseTrailers( - _ trailers: ResponseTrailers, - streamIntel: StreamIntel - ) -> FilterTrailersStatus { - // Trailers imply end of stream; resume processing of the (now fully-buffered) response. - let builder = self.headers.toResponseHeadersBuilder() - .add(name: "buffer-filter-demo", value: "1") - return .resumeIteration(headers: builder.build(), data: self.body, trailers: trailers) - } - - func onError(_ error: EnvoyError, streamIntel: FinalStreamIntel) {} - - func onCancel(streamIntel: FinalStreamIntel) {} - - func onComplete(streamIntel: FinalStreamIntel) {} -} diff --git a/mobile/test/swift/apps/baseline/DemoFilter.swift b/mobile/test/swift/apps/baseline/DemoFilter.swift deleted file mode 100644 index 27e79c3e6b8b..000000000000 --- a/mobile/test/swift/apps/baseline/DemoFilter.swift +++ /dev/null @@ -1,33 +0,0 @@ -import Envoy -import Foundation - -/// Example of a simple HTTP filter that adds a response header. -struct DemoFilter: ResponseFilter { - func onResponseHeaders(_ headers: ResponseHeaders, endStream: Bool, streamIntel: StreamIntel) - -> FilterHeadersStatus - { - let builder = headers.toResponseHeadersBuilder() - builder.add(name: "filter-demo", value: "1") - return .continue(headers: builder.build()) - } - - func setResponseFilterCallbacks(_ callbacks: ResponseFilterCallbacks, streamIntel: StreamIntel) {} - - func onResponseData(_ body: Data, endStream: Bool, streamIntel: StreamIntel) - -> FilterDataStatus - { - return .continue(data: body) - } - - func onResponseTrailers(_ trailers: ResponseTrailers, streamIntel: StreamIntel) - -> FilterTrailersStatus - { - return .continue(trailers: trailers) - } - - func onError(_ error: EnvoyError, streamIntel: FinalStreamIntel) {} - - func onCancel(streamIntel: FinalStreamIntel) {} - - func onComplete(streamIntel: FinalStreamIntel) {} -} diff --git a/mobile/test/swift/apps/baseline/Info.plist b/mobile/test/swift/apps/baseline/Info.plist deleted file mode 100644 index 83af5464ce7e..000000000000 --- a/mobile/test/swift/apps/baseline/Info.plist +++ /dev/null @@ -1,47 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - APPL - CFBundleShortVersionString - 0.1 - CFBundleSignature - ???? - CFBundleVersion - 0.1 - ITSAppUsesNonExemptEncryption - - NSAppTransportSecurity - - NSExceptionDomains - - localhost - - NSExceptionAllowsInsecureHTTPLoads - - - - - LSRequiresIPhoneOS - - UIRequiredDeviceCapabilities - - armv7 - - UIStatusBarStyle - UIStatusBarStyleLightContent - UILaunchStoryboardName - LaunchScreen - - diff --git a/mobile/test/swift/apps/baseline/README.md b/mobile/test/swift/apps/baseline/README.md deleted file mode 100644 index ee625688d1f8..000000000000 --- a/mobile/test/swift/apps/baseline/README.md +++ /dev/null @@ -1 +0,0 @@ -For instructions on how to use this demo, please head over to our [docs](https://envoymobile.io/docs/envoy-mobile/latest/start/examples/hello_world.html). diff --git a/mobile/test/swift/apps/baseline/ResponseModels.swift b/mobile/test/swift/apps/baseline/ResponseModels.swift deleted file mode 100644 index c83e5553204c..000000000000 --- a/mobile/test/swift/apps/baseline/ResponseModels.swift +++ /dev/null @@ -1,10 +0,0 @@ -/// Represents a response from the server. -struct Response { - let message: String - let headerMessage: String -} - -/// Error that was encountered when executing a request. -struct RequestError: Error { - let message: String -} diff --git a/mobile/test/swift/apps/baseline/ViewController.swift b/mobile/test/swift/apps/baseline/ViewController.swift deleted file mode 100644 index 0493d986d654..000000000000 --- a/mobile/test/swift/apps/baseline/ViewController.swift +++ /dev/null @@ -1,155 +0,0 @@ -import Envoy -import UIKit - -private let kCellID = "cell-id" -private let kRequestAuthority = "api.lyft.com" -private let kRequestPath = "/ping" -private let kRequestScheme = "http" -private let kFilteredHeaders = - ["server", "filter-demo", "x-envoy-upstream-service-time"] - -final class ViewController: UITableViewController { - private var results = [Result]() - private var timer: Foundation.Timer? - private var streamClient: StreamClient? - private var pulseClient: PulseClient? - - override func viewDidLoad() { - super.viewDidLoad() - - let engine = EngineBuilder() - .setLogLevel(.debug) - .setLogger { _, msg in - print(msg, terminator: "") - } - .addPlatformFilter(DemoFilter.init) - .addNativeFilter( - name: "envoy.filters.http.buffer", - // swiftlint:disable:next line_length - typedConfig: "[type.googleapis.com/envoy.extensions.filters.http.buffer.v3.Buffer] { max_request_bytes: { value: 5242880 } }" - ) - .setOnEngineRunning { NSLog("Envoy async internal setup completed") } - .addStringAccessor(name: "demo-accessor", accessor: { return "PlatformString" }) - .setEventTracker { NSLog("Envoy event emitted: \($0)") } - .build() - self.streamClient = engine.streamClient() - self.pulseClient = engine.pulseClient() - - NSLog("started Envoy, beginning requests...") - self.startRequests() - } - - deinit { - self.timer?.invalidate() - } - - // MARK: - Requests - - private func startRequests() { - self.timer = .scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] _ in - self?.performRequest() - self?.recordStats() - } - } - - private func performRequest() { - guard let streamClient = self.streamClient else { - NSLog("failed to start request - Envoy is not running") - return - } - - NSLog("starting request to '\(kRequestPath)'") - - let headers = RequestHeadersBuilder(method: .get, scheme: kRequestScheme, - authority: kRequestAuthority, path: kRequestPath) - .build() - - streamClient - .newStreamPrototype() - .setOnResponseHeaders { [weak self] headers, _, _ in - let statusCode = headers.httpStatus.map(String.init) ?? "nil" - let message = "received headers with status \(statusCode)" - - let headerMessage = headers.caseSensitiveHeaders() - .filter { kFilteredHeaders.contains($0.key) } - .map { "\($0.key): \($0.value.joined(separator: ", "))" } - .joined(separator: "\n") - - NSLog(message) - if let filterDemoValue = headers.value(forName: "filter-demo")?.first { - NSLog("filter-demo: \(filterDemoValue)") - } - - let response = Response(message: message, - headerMessage: headerMessage) - self?.add(result: .success(response)) - } - .setOnError { [weak self] error, _ in - let message: String - if let attemptCount = error.attemptCount { - message = "failed within Envoy library after \(attemptCount) attempts: \(error.message)" - } else { - message = "failed within Envoy library: \(error.message)" - } - - NSLog(message) - self?.add(result: .failure(RequestError(message: message))) - } - .start() - .sendHeaders(headers, endStream: true) - } - - private func add(result: Result) { - self.results.insert(result, at: 0) - self.tableView.reloadData() - } - - private func recordStats() { - guard let pulseClient = self.pulseClient else { - NSLog("failed to send stats - Envoy is not running") - return - } - - let counter = pulseClient.counter(elements: ["foo", "bar", "counter"]) - counter.increment() - counter.increment(count: 5) - } - // MARK: - UITableView - - override func numberOfSections(in tableView: UITableView) -> Int { - return 1 - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return self.results.count - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) - -> UITableViewCell - { - let cell = tableView.dequeueReusableCell(withIdentifier: kCellID) ?? - UITableViewCell(style: .subtitle, reuseIdentifier: kCellID) - - let result = self.results[indexPath.row] - switch result { - case .success(let response): - cell.textLabel?.text = response.message - cell.detailTextLabel?.text = response.headerMessage - - cell.textLabel?.textColor = .black - cell.detailTextLabel?.lineBreakMode = .byWordWrapping - cell.detailTextLabel?.numberOfLines = 0 - cell.detailTextLabel?.textColor = .black - cell.contentView.backgroundColor = .white - case .failure(let error): - cell.textLabel?.text = error.message - cell.detailTextLabel?.text = nil - - cell.textLabel?.textColor = .white - cell.detailTextLabel?.textColor = .white - cell.contentView.backgroundColor = .red - } - - return cell - } -}