Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[webview_flutter_wkwebview] Fix bug of overriding default values of NSURLRequest #5969

Merged
merged 3 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ - (void)testFWFNSURLRequestFromRequestData {
XCTAssertEqualObjects(request.allHTTPHeaderFields, @{@"a" : @"header"});
}

- (void)testFWFNSURLRequestFromRequestDataDoesNotOverrideDefaultValuesWithNull {
NSURLRequest *request =
FWFNSURLRequestFromRequestData([FWFNSUrlRequestData makeWithUrl:@"https://flutter.dev"
httpMethod:nil
httpBody:nil
allHttpHeaderFields:@{}]);

XCTAssertEqualObjects(request.HTTPMethod, @"GET");
}

- (void)testFWFNSHTTPCookieFromCookieData {
NSHTTPCookie *cookie = FWFNSHTTPCookieFromCookieData([FWFNSHttpCookieData
makeWithPropertyKeys:@[ [FWFNSHttpCookiePropertyKeyEnumData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@
return nil;
}

[request setHTTPMethod:data.httpMethod];
[request setHTTPBody:data.httpBody.data];
[request setAllHTTPHeaderFields:data.allHttpHeaderFields];
if (data.httpMethod) {
[request setHTTPMethod:data.httpMethod];
}
if (data.httpBody) {
[request setHTTPBody:data.httpBody.data];
}
if (data.allHttpHeaderFields) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check can be removed, since the property is nonnullable.

[request setAllHTTPHeaderFields:data.allHttpHeaderFields];
}

return request;
}
Expand Down