         let stub = URLProtocol.property(forKey: stubPropertyKey, in: request) as! RequestStub
         stub.delayLatch.await()
 
-        let client = self.client!
-
-        if let error = stub.responseError
-            {
-            client.urlProtocol(self, didFailWithError: error)
-            return
-            }
-        else
-            {
-            Thread.sleep(forTimeInterval: 1.0 / pow(.random(in: 1...1000), 2))
-
-            let response = HTTPURLResponse(
-                url: request.url!,
-                statusCode: stub.responseCode,
-                httpVersion: "1.1",
-                headerFields: stub.responseHeaders)!
-            client.urlProtocol(self, didReceive: response, cacheStoragePolicy: .notAllowed)
-            if let data = stub.responseBody
-                { client.urlProtocol(self, didLoad: data) }
-            }
-
-        client.urlProtocolDidFinishLoading(self)
+        Thread.sleep(forTimeInterval: 1.0 / pow(.random(in: 1...1000), 2))
+
+        stub.responseData.send(to: self.client!, for: self, url: request.url!)
         }
 
     override func stopLoading()


    func andReturn(_ statusCode: Int) -> LSStubResponseDSL
        {
        stub.responseCode = statusCode
        return LSStubResponseDSL(stub: stub)
        }

    func andFailWithError(_ error: Error)
        {
        stub.responseError = error
        }
    }


            matcher: RequestMatcher(
                method: method.rawValue.uppercased(),
                url: resource().url.absoluteString),
            responseData: HTTPResponse(statusCode: status)))
        }

    static func add(_ stub: RequestStub)
