backtrace-cocoa
backtrace-cocoa copied to clipboard
Improvement/attachments and requests
This PR refactors the MultipartRequest and Attachments implementation to transition from in-memory multipart body construction to disk-based streaming using a temporary file and improve filenameExtension detection.
Why?
- The previous implementation (in-memory NSMutableData) held the entire multipart body in memory, risking high memory usage and even crashes for large reports or numerous chunky attachments (which is limited by available RAM), streaming to disk allows the sdk to process larger reports and attachments reliably.
- Content-Length is now calculated from the size of the temporary file, avoiding the need to hold the entire payload in memory
- Modern MIME Type Detection that leverage UTType APIs for iOS 14+/tvOS/macOS 11+ with fallbacks for older platforms
Changes
- Replace NSMutableData operation with streaming Data to a temporary file
- Use httpBodyStream to stream file content directly into the request body
- Use FileHandle to manage file writing
- Calculate file size after writing to ensure accurate HTTP header
- defer file handling
- Migrate Attachements to modern UniformTypeIdentifiers API, keep legacy support
ref: BT-5311