Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion packages/react-native/Libraries/Image/ImageSourceUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import type {ResolvedAssetSource} from './AssetSourceResolver';
import type {ImageProps} from './ImageProps';
import type {ImageURISource} from './ImageSource';

import resolveAssetSource from './resolveAssetSource';

Expand Down Expand Up @@ -87,7 +88,14 @@ export function getImageSourcesFromImageProps(imageProps: ImageProps):
} else if (src != null) {
sources = [{uri: src, headers: headers, width, height}];
} else if (source != null && source.uri && Object.keys(headers).length > 0) {
sources = [{...source, headers}];
const sourceHeaders = (source as ImageURISource).headers;
sources = [
{
...source,
headers:
sourceHeaders != null ? {...sourceHeaders, ...headers} : headers,
},
];
} else {
sources = source;
}
Expand Down
15 changes: 12 additions & 3 deletions packages/react-native/Libraries/Image/__tests__/Image-itest.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,28 @@ describe('<Image>', () => {
);
});

it('sets the "Access-Control-Allow-Credentials" header in "use-credentials" mode', () => {
it('adds the credentials header without replacing source headers', () => {
const root = Fantom.createRoot();

Fantom.runTask(() => {
root.render(
<Image crossOrigin="use-credentials" source={LOGO_SOURCE} />,
<Image
crossOrigin="use-credentials"
source={{
...LOGO_SOURCE,
headers: {Authorization: 'Bearer token'},
}}
/>,
);
});

expect(
root.getRenderedOutput({props: ['source-header']}).toJSX(),
).toEqual(
<rn-image source-header-Access-Control-Allow-Credentials="true" />,
<rn-image
source-header-Access-Control-Allow-Credentials="true"
source-header-Authorization="Bearer token"
/>,
);
});
});
Expand Down
Loading