Update XHRExampleFetch and dump the response headers

Summary:
Thanks for submitting a pull request! Please provide enough information so that others can review your pull request:

> **Unless you are a React Native release maintainer and cherry-picking an *existing* commit into a current release, ensure your pull request is targeting the `master` React Native branch.**

Dump the response headers so that we can check `Set-Cookie` header is working properly whether or not.

**Test plan (required)**

Manual Test.

![image](https://cloud.githubusercontent.com/assets/104052/18259326/6b86c90a-7415-11e6-8979-92bd24ac703c.png)

**Code formatting**

Look around. Match the style of the rest of the codebase. See also the simple [style guide](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#style-guide).

For more info, see the ["Pull Requests" section of our "Contributing" guidelines](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#pull-requests).
Closes https://github.com/facebook/react-native/pull/9687

Differential Revision: D3821145

Pulled By: javache

fbshipit-source-id: 24baa051165d3b451ba0e71efbe70db44b0bf45e
This commit is contained in:
leeight 2016-09-06 04:16:54 -07:00 committed by Facebook Github Bot 3
parent f799fa13b8
commit 0d176b3337
1 changed files with 26 additions and 0 deletions

View File

@ -36,6 +36,7 @@ var {
class XHRExampleFetch extends React.Component {
state: any;
responseURL: ?string;
responseHeaders: ?Object;
constructor(props: any) {
super(props);
@ -43,17 +44,34 @@ class XHRExampleFetch extends React.Component {
responseText: null,
};
this.responseURL = null;
this.responseHeaders = null;
}
submit(uri: String) {
fetch(uri).then((response) => {
this.responseURL = response.url;
this.responseHeaders = response.headers;
return response.text();
}).then((body) => {
this.setState({responseText: body});
});
}
_renderHeaders() {
if (!this.responseHeaders) {
return null;
}
var responseHeaders = [];
var keys = Object.keys(this.responseHeaders.map);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var value = this.responseHeaders.get(key);
responseHeaders.push(<Text>{key}: {value}</Text>);
}
return responseHeaders;
}
render() {
var responseURL = this.responseURL ? (
@ -63,6 +81,13 @@ class XHRExampleFetch extends React.Component {
</View>
) : null;
var responseHeaders = this.responseHeaders ? (
<View style={{marginTop: 10}}>
<Text style={styles.label}>Server response headers:</Text>
{this._renderHeaders()}
</View>
) : null;
var response = this.state.responseText ? (
<View style={{marginTop: 10}}>
<Text style={styles.label}>Server response:</Text>
@ -87,6 +112,7 @@ class XHRExampleFetch extends React.Component {
style={styles.textInput}
/>
{responseURL}
{responseHeaders}
{response}
</View>
);