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 601 forks source link

Saved Responses for 204 No Content Returned as 200s #296

Open SlaunchaMan opened 5 years ago

SlaunchaMan commented 5 years ago

Environment

Issue Description

In my tests, I have some stubbed network responses for when the server returns a 204 No Content response. I have them saved as .response files in a test bundle, just like any other response. When they are returned by OHHTTPStubs, however, they’re returned with a 200 status code, with the contents of the file as the data. This is due to the fact that CFHTTPMessageIsHeaderComplete() returns false with the following response:

HTTP/1.1 204 No Content
Date: Sat, 19 Jan 2019 15:13:01 GMT
Connection: close

This parsing happens here: https://github.com/AliSoftware/OHHTTPStubs/blob/826a9217fcd468220d154ed0075cbc1a20d0c5c9/OHHTTPStubs/Sources/HTTPMessage/OHHTTPStubsResponse%2BHTTPMessage.m#L48

I can manually create these responses for now, but I’m wondering if we should get the status code from the response before calling CFHTTPMessageIsHeaderComplete() to check for 204 status codes, for which we’d return nil for the data.