Clients sometimes need to modify information in the body data of a post request or the body of a server’s response. This requires a hook into The Stubborn Network when storing the stubs.
This could be achieved by a var bodyDataProcessor: BodyDataProcessor property on the URLSessionStub. The BodyDataProcessor would be a protocol that allows modifications to the body data of post requests and responses. Possibly, the protocol would have 3 function declarations to enable the functionality:
Firstly, the data can be modified before the stub is created, meaning you can access your own request’s body and the server’s response body before they get stored as a stub.
func dataForStoringRequestBody(data: Data?, of request: URLRequest) -> Data?
func dataForStoringResponseBody(data: Data?, of request: URLRequest) -> Data?
Secondly you can modify the response data just before a stub will be delivered in the URLSessionStub’s playback mode. This could be used for updating time stamps within the stubbed response just before delivery, for example.
func dataForDeliveringResponseBody(data: Data?, of request: URLRequest) -> Data?
Clients sometimes need to modify information in the body data of a post request or the body of a server’s response. This requires a hook into The Stubborn Network when storing the stubs.
This could be achieved by a
var bodyDataProcessor: BodyDataProcessor
property on the URLSessionStub. TheBodyDataProcessor
would be a protocol that allows modifications to the body data of post requests and responses. Possibly, the protocol would have 3 function declarations to enable the functionality:Firstly, the data can be modified before the stub is created, meaning you can access your own request’s body and the server’s response body before they get stored as a stub.
Secondly you can modify the response data just before a stub will be delivered in the URLSessionStub’s
playback
mode. This could be used for updating time stamps within the stubbed response just before delivery, for example.