net-info-body.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. "use strict";
  5. const React = require("devtools/client/shared/vendor/react");
  6. const { createFactories } = require("devtools/client/shared/components/reps/rep-utils");
  7. const { Tabs, TabPanel } = createFactories(require("devtools/client/shared/components/tabs/tabs"));
  8. // Network
  9. const HeadersTab = React.createFactory(require("./headers-tab"));
  10. const ResponseTab = React.createFactory(require("./response-tab"));
  11. const ParamsTab = React.createFactory(require("./params-tab"));
  12. const CookiesTab = React.createFactory(require("./cookies-tab"));
  13. const PostTab = React.createFactory(require("./post-tab"));
  14. const StackTraceTab = React.createFactory(require("./stacktrace-tab"));
  15. const NetUtils = require("../utils/net");
  16. // Shortcuts
  17. const PropTypes = React.PropTypes;
  18. /**
  19. * This template renders the basic Network log info body. It's not
  20. * visible by default, the user needs to expand the network log
  21. * to see it.
  22. *
  23. * This is the set of tabs displaying details about network events:
  24. * 1) Headers - request and response headers
  25. * 2) Params - URL parameters
  26. * 3) Response - response body
  27. * 4) Cookies - request and response cookies
  28. * 5) Post - posted data
  29. */
  30. var NetInfoBody = React.createClass({
  31. propTypes: {
  32. tabActive: PropTypes.number.isRequired,
  33. actions: PropTypes.object.isRequired,
  34. data: PropTypes.shape({
  35. request: PropTypes.object.isRequired,
  36. response: PropTypes.object.isRequired
  37. })
  38. },
  39. displayName: "NetInfoBody",
  40. getDefaultProps() {
  41. return {
  42. tabActive: 0
  43. };
  44. },
  45. getInitialState() {
  46. return {
  47. data: {
  48. request: {},
  49. response: {}
  50. },
  51. tabActive: this.props.tabActive,
  52. };
  53. },
  54. onTabChanged(index) {
  55. this.setState({tabActive: index});
  56. },
  57. hasCookies() {
  58. let {request, response} = this.state.data;
  59. return this.state.hasCookies ||
  60. NetUtils.getHeaderValue(request.headers, "Cookie") ||
  61. NetUtils.getHeaderValue(response.headers, "Set-Cookie");
  62. },
  63. hasStackTrace() {
  64. let {cause} = this.state.data;
  65. return cause && cause.stacktrace && cause.stacktrace.length > 0;
  66. },
  67. getTabPanels() {
  68. let actions = this.props.actions;
  69. let data = this.state.data;
  70. let {request} = data;
  71. // Flags for optional tabs. Some tabs are visible only if there
  72. // are data to display.
  73. let hasParams = request.queryString && request.queryString.length;
  74. let hasPostData = request.bodySize > 0;
  75. let panels = [];
  76. // Headers tab
  77. panels.push(
  78. TabPanel({
  79. className: "headers",
  80. key: "headers",
  81. title: Locale.$STR("netRequest.headers")},
  82. HeadersTab({data: data, actions: actions})
  83. )
  84. );
  85. // URL parameters tab
  86. if (hasParams) {
  87. panels.push(
  88. TabPanel({
  89. className: "params",
  90. key: "params",
  91. title: Locale.$STR("netRequest.params")},
  92. ParamsTab({data: data, actions: actions})
  93. )
  94. );
  95. }
  96. // Posted data tab
  97. if (hasPostData) {
  98. panels.push(
  99. TabPanel({
  100. className: "post",
  101. key: "post",
  102. title: Locale.$STR("netRequest.post")},
  103. PostTab({data: data, actions: actions})
  104. )
  105. );
  106. }
  107. // Response tab
  108. panels.push(
  109. TabPanel({className: "response", key: "response",
  110. title: Locale.$STR("netRequest.response")},
  111. ResponseTab({data: data, actions: actions})
  112. )
  113. );
  114. // Cookies tab
  115. if (this.hasCookies()) {
  116. panels.push(
  117. TabPanel({
  118. className: "cookies",
  119. key: "cookies",
  120. title: Locale.$STR("netRequest.cookies")},
  121. CookiesTab({
  122. data: data,
  123. actions: actions
  124. })
  125. )
  126. );
  127. }
  128. // Stacktrace tab
  129. if (this.hasStackTrace()) {
  130. panels.push(
  131. TabPanel({
  132. className: "stacktrace-tab",
  133. key: "stacktrace",
  134. title: Locale.$STR("netRequest.callstack")},
  135. StackTraceTab({
  136. data: data,
  137. actions: actions
  138. })
  139. )
  140. );
  141. }
  142. return panels;
  143. },
  144. render() {
  145. let tabActive = this.state.tabActive;
  146. let tabPanels = this.getTabPanels();
  147. return (
  148. Tabs({
  149. tabActive: tabActive,
  150. onAfterChange: this.onTabChanged},
  151. tabPanels
  152. )
  153. );
  154. }
  155. });
  156. // Exports from this module
  157. module.exports = NetInfoBody;