 
     func withBody(_ data: Data?) -> Self
         {
-        stub.responseBody = data
+        var response = stub.responseData as! HTTPResponse
+        response.body = data
+        stub.responseData = response
         return self
         }
 

        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)
        }

    override func stopLoading()


    func withHeader(_ key: String, _ value: String?) -> Self
        {
        var response = stub.responseData as! HTTPResponse
        response.headers[key] = value
        stub.responseData = response
        return self
        }

