Skip to content

Commit

Permalink
added chunked test case
Browse files Browse the repository at this point in the history
  • Loading branch information
alicata committed Jun 12, 2024
1 parent 14ccf6b commit 7b49189
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions packages/rn-tester/js/examples/XHR/XHRExampleDownload.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class XHRExampleDownload extends React.Component<{...}, Object> {
readystateHandler: false,
progressHandler: true,
arraybuffer: false,
chunked: false,
};

xhr: ?XMLHttpRequest = null;
Expand Down Expand Up @@ -107,12 +108,19 @@ class XHRExampleDownload extends React.Component<{...}, Object> {
Alert.alert('Error', xhr.responseText);
}
};
xhr.open(
'GET',
'http://aleph.gutenberg.org/cache/epub/100/pg100-images.html.utf8',
);
// Avoid gzip so we can actually show progress
xhr.setRequestHeader('Accept-Encoding', '');
if(this.state.chunked) {
xhr.open(
'GET',
'https://filesamples.com/samples/ebook/azw3/Around%20the%20World%20in%2028%20Languages.azw3',
);
} else {
xhr.open(
'GET',
'http://aleph.gutenberg.org/cache/epub/100/pg100-images.html.utf8',
);
// Avoid gzip so we can actually show progress
xhr.setRequestHeader('Accept-Encoding', '');
}
xhr.send();

this.setState({downloading: true});
Expand All @@ -133,7 +141,7 @@ class XHRExampleDownload extends React.Component<{...}, Object> {
) : (
<TouchableHighlight style={styles.wrapper} onPress={this._download}>
<View style={styles.button}>
<Text>Download 7MB Text File</Text>
<Text>{this.state.chunked ? 'Download 10MB File' : 'Download 19KB pdf File'}</Text>
</View>
</TouchableHighlight>
);
Expand Down Expand Up @@ -188,6 +196,13 @@ class XHRExampleDownload extends React.Component<{...}, Object> {
onValueChange={arraybuffer => this.setState({arraybuffer})}
/>
</View>
<View style={styles.configRow}>
<Text>transfer-encoding: chunked</Text>
<Switch
value={this.state.chunked}
onValueChange={chunked => this.setState({chunked})}
/>
</View>
{button}
{readystate}
{progress}
Expand Down

0 comments on commit 7b49189

Please sign in to comment.