Why are responses with `Content-Length = 0` not stored in URLCache?

Hi!

I noticed that responses with Content-Length = 0 are not stored in the URLCache, while responses with Content-Length > 0 are stored.

In my case the response contains a Protobuf message where all fields might have default values. This message will have size 0 when encoded and is a valid message. I would expect this message to be cached as all other instances of the message type.

Is there a reason why 0-sized response are not stored in cache? Or is it a bug?

Best Regards
Markus


Steps to reproduce:

This response will cause URLCache.storeCachedResponse(_, for) to be called:
Code Block
< HTTP/1.0 200 OK
< Content-Type: application/protobuf
< Content-Length: 1
< Cache-Control: max-age=20


This response will not cause any call to URLCache.storeCachedResponse(_, for):
Code Block
< HTTP/1.0 200 OK
< Content-Type: application/protobuf
< Content-Length: 0
< Cache-Control: max-age=20

Is there a reason why 0-sized response are not stored in cache? Or is
it a bug?

I’m not sure what’s going on here but I definitely think its bugworthy. You should file a bug, making sure to include your description of why it’s important that the system cache such responses. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Why are responses with `Content-Length = 0` not stored in URLCache?
 
 
Q