@@ -595,10 +595,38 @@ - (void)captureResponseDetails:(NSData *)data
595595 request : (NSURLRequest *)request
596596 task : (NSURLSessionTask *)task
597597{
598- // TODO: Implementation
599- // 2. Parse response body data
600- // 3. Store in appropriate location for session replay
601- // 4. Handle size limits and truncation if needed
598+ NSString *url = request.URL ? request.URL .absoluteString : @" <no URL>" ;
599+ SentryOptions *options = SentrySDK.startOption ;
600+ if (![self isNetworkDetailCaptureEnabledFor: url options: options]) {
601+ return ;
602+ }
603+
604+ SentryReplayNetworkDetails *details = objc_getAssociatedObject (task, &SentryNetworkDetailsKey);
605+ if (!details) {
606+ SENTRY_LOG_DEBUG (@" [NetworkCapture] No SentryReplayNetworkDetails found for %@ - "
607+ @" skipping response capture" ,
608+ url);
609+ return ;
610+ }
611+
612+ NSInteger statusCode = 0 ;
613+ NSDictionary *allHeaders = nil ;
614+ NSString *contentType = nil ;
615+ if ([response isKindOfClass: [NSHTTPURLResponse class ]]) {
616+ NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
617+ statusCode = httpResponse.statusCode ;
618+ allHeaders = httpResponse.allHeaderFields ;
619+ contentType = httpResponse.allHeaderFields [@" Content-Type" ];
620+ }
621+
622+ NSData *bodyData = (options.sessionReplay .networkCaptureBodies && data.length > 0 ) ? data : nil ;
623+
624+ [details setResponseWithStatusCode: statusCode
625+ size: @(data ? data.length : 0 )
626+ bodyData: bodyData
627+ contentType: contentType
628+ allHeaders: allHeaders
629+ configuredHeaders: options.sessionReplay.networkResponseHeaders];
602630}
603631
604632- (void )captureRequestDetails : (NSURLSessionTask *)sessionTask
0 commit comments