diff --git a/Examples/UIExplorer/js/XHRExampleFetch.js b/Examples/UIExplorer/js/XHRExampleFetch.js index 06a90dac3..292e3bc76 100644 --- a/Examples/UIExplorer/js/XHRExampleFetch.js +++ b/Examples/UIExplorer/js/XHRExampleFetch.js @@ -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({key}: {value}); + } + return responseHeaders; + } + render() { var responseURL = this.responseURL ? ( @@ -63,6 +81,13 @@ class XHRExampleFetch extends React.Component { ) : null; + var responseHeaders = this.responseHeaders ? ( + + Server response headers: + {this._renderHeaders()} + + ) : null; + var response = this.state.responseText ? ( Server response: @@ -87,6 +112,7 @@ class XHRExampleFetch extends React.Component { style={styles.textInput} /> {responseURL} + {responseHeaders} {response} );