Headers.mjs (2684B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /* eslint no-shadow: ["error", { "allow": ["Headers"] }] */ 6 7 import { 8 createFactory, 9 Component, 10 } from "resource://devtools/client/shared/vendor/react.mjs"; 11 import PropTypes from "resource://devtools/client/shared/vendor/react-prop-types.mjs"; 12 import * as dom from "resource://devtools/client/shared/vendor/react-dom-factories.mjs"; 13 14 const { div, span, table, tbody, tr, td } = dom; 15 16 /** 17 * This template is responsible for rendering basic layout 18 * of the 'Headers' panel. It displays HTTP headers groups such as 19 * received or response headers. 20 */ 21 class Headers extends Component { 22 static get propTypes() { 23 return { 24 data: PropTypes.object, 25 }; 26 } 27 28 constructor(props) { 29 super(props); 30 this.state = {}; 31 } 32 33 render() { 34 const data = this.props.data; 35 36 return div( 37 { className: "netInfoHeadersTable" }, 38 div( 39 { className: "netHeadersGroup" }, 40 div( 41 { className: "netInfoHeadersGroup" }, 42 JSONView.Locale["jsonViewer.responseHeaders"] 43 ), 44 table( 45 { cellPadding: 0, cellSpacing: 0 }, 46 HeaderListFactory({ headers: data.response }) 47 ) 48 ), 49 div( 50 { className: "netHeadersGroup" }, 51 div( 52 { className: "netInfoHeadersGroup" }, 53 JSONView.Locale["jsonViewer.requestHeaders"] 54 ), 55 table( 56 { cellPadding: 0, cellSpacing: 0 }, 57 HeaderListFactory({ headers: data.request }) 58 ) 59 ) 60 ); 61 } 62 } 63 64 /** 65 * This template renders headers list, 66 * name + value pairs. 67 */ 68 class HeaderList extends Component { 69 static get propTypes() { 70 return { 71 headers: PropTypes.arrayOf( 72 PropTypes.shape({ 73 name: PropTypes.string, 74 value: PropTypes.string, 75 }) 76 ), 77 }; 78 } 79 80 constructor(props) { 81 super(props); 82 83 this.state = { 84 headers: [], 85 }; 86 } 87 88 render() { 89 const headers = this.props.headers; 90 91 headers.sort(function (a, b) { 92 return a.name > b.name ? 1 : -1; 93 }); 94 95 const rows = []; 96 headers.forEach(header => { 97 rows.push( 98 tr( 99 { key: header.name }, 100 td( 101 { className: "netInfoParamName" }, 102 span({ title: header.name }, header.name) 103 ), 104 td({ className: "netInfoParamValue" }, header.value) 105 ) 106 ); 107 }); 108 109 return tbody({}, rows); 110 } 111 } 112 113 const HeaderListFactory = createFactory(HeaderList); 114 115 export default { Headers };