Accessing `allHTTPHeaderFields` makes a side effect on `URLRequest` equatability

Originator:ncreated
Number:rdar://FB8814193 Date Originated:Oct 20, 2020
Status:Potential fix identified - In iOS 15 Resolved:
Product:Xcode Product Version:12.0 (12A7209)
Classification: Reproducible:Always
 
In Foundation framework, when using `URLRequest`, it seems that retrieving `allHTTPHeaderFields` makes a side effect visible in `Equatable` comparison. The following snippet run on iOS14 (Simulator or device) can be used to demonstrate it:
```
import Foundation

let url = URL(string: "https://api.com/foo")!

var request1 = URLRequest(url: url)
var request2 = URLRequest(url: url)

print(request1 == request2)

request1.setValue("Foo", forHTTPHeaderField: "Bar")
request2.setValue("Foo", forHTTPHeaderField: "Bar")

print(request1 == request2)

_ = request1.allHTTPHeaderFields

print(request1 == request2)
```

When starting the app, I’d expect following output:
```
true
true
true
```

Instead, I get this one:
```
true
true
false
```

Note: when running this snippet in macOS Playground, the output is as expected.

Comments

Update from Apple

Received response from Apple:

""" We believe this issue is resolved.

Please test with the latest releases: iOS 14 beta, macOS 12 beta and Xcode 13 beta. """

It seems to work as expected on Xcode 13.0 (13A233) + iOS 15.0 Simulator.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!