AliSoftware / OHHTTPStubs

Stub your network requests easily! Test your apps with fake network data and custom response time, response code and headers!
MIT License
5.03k stars 602 forks source link

FEATURE REQUEST: Ability to control response stream #362

Open Tyler-Keith-Thompson opened 1 year ago

Tyler-Keith-Thompson commented 1 year ago

New Issue Checklist

Environment

Issue Description

I am attempting to use this to test a Server-Sent Events implementation. That particular protocol likes to send data in chunks of varying sizes as it streams, example:

id: 1
data: This

data:  is

data:  a

data:  sentence

data: .

OHHTTPStubs at the moment doesn't seem to expose a way to send partial responses back as part of the stream. Specifically, what I need is the URLSessionDataDelegate to have its urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) method called with each sent event.

An ideal solution in my mind would be to allow me to pass an array of Data to the response and have it work out the rest, but honestly I'd be up for anything that worked.