q231950 / the-stubborn-network

A Swifty and clean stubbing machine.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make Request Data Accessible

q231950 opened this issue · comments

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?