Skip to content

Commit

Permalink
fix: add headers in fabric image component (#45415)
Browse files Browse the repository at this point in the history
Summary:
FIXES [45404](#45404)

 sending headers from Image  component  not working in new arch , implementation was missing
```
<Image
        source={{
          uri: "http://localhost:3000/image",
          headers: {
            "test-header": 'test',
              "hello":"tested"
          }
        }}
        style={{
          width: 300,
          height: 300,
        }}
      />
```

## Changelog:
[IOS] [ADDED]- sending missing **headers** field with **Image** component in fabric

Pull Request resolved: #45415

Test Plan:
# Tested
Attaching the below video to show how headers are getting received on server from Image component running in new arch

https://github.com/user-attachments/assets/c816265d-0bb5-4670-bde0-cfec72d7618f

Reviewed By: javache, cipolleschi

Differential Revision: D59807462

Pulled By: blakef

fbshipit-source-id: dffa4d80db58de6a81947ac876aa76ec7e62dd48
  • Loading branch information
deepanshushuklad11 authored and facebook-github-bot committed Jul 16, 2024
1 parent db16a78 commit 50f7892
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ inline void fromRawValue(
result.type = ImageSource::Type::Local;
}

if (items.find("headers") != items.end() &&
items.at("headers")
.hasType<std::unordered_map<std::string, std::string>>()) {
auto headers =
(std::unordered_map<std::string, std::string>)items.at("headers");
for (const auto& header : headers) {
result.headers.push_back(header);
}
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ inline static NSURLRequest *NSURLRequestFromImageSource(const facebook::react::I
request.cachePolicy = ...;
request.allHTTPHeaderFields = ...;
*/
for (const auto &header : imageSource.headers) {
NSString *key = [NSString stringWithUTF8String:header.first.c_str()];
NSString *value = [NSString stringWithUTF8String:header.second.c_str()];
if (key != NULL && value != NULL) {
[request setValue:value forHTTPHeaderField:key];
}
}

return [request copy];
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ImageSource {
std::string bundle{};
Float scale{3};
Size size{0};
std::vector<std::pair<std::string, std::string>> headers{};

bool operator==(const ImageSource& rhs) const {
return std::tie(this->type, this->uri) == std::tie(rhs.type, rhs.uri);
Expand Down

0 comments on commit 50f7892

Please sign in to comment.