版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1 год назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import XMLHttpRequestEventTarget from './XMLHttpRequestEventTarget';
  2. import XMLHttpRequestReadyStateEnum from './XMLHttpRequestReadyStateEnum';
  3. import IDocument from '../nodes/document/IDocument';
  4. import XMLHttpRequestUpload from './XMLHttpRequestUpload';
  5. import XMLHttpResponseTypeEnum from './XMLHttpResponseTypeEnum';
  6. /**
  7. * XMLHttpRequest.
  8. *
  9. * Based on:
  10. * https://github.com/mjwwit/node-XMLHttpRequest/blob/master/lib/XMLHttpRequest.js
  11. */
  12. export default class XMLHttpRequest extends XMLHttpRequestEventTarget {
  13. static _ownerDocument: IDocument;
  14. static UNSENT: XMLHttpRequestReadyStateEnum;
  15. static OPENED: XMLHttpRequestReadyStateEnum;
  16. static HEADERS_RECEIVED: XMLHttpRequestReadyStateEnum;
  17. static LOADING: XMLHttpRequestReadyStateEnum;
  18. static DONE: XMLHttpRequestReadyStateEnum;
  19. upload: XMLHttpRequestUpload;
  20. private readonly _ownerDocument;
  21. private _state;
  22. private _settings;
  23. /**
  24. * Constructor.
  25. */
  26. constructor();
  27. /**
  28. * Returns the status.
  29. *
  30. * @returns Status.
  31. */
  32. get status(): number;
  33. /**
  34. * Returns the status text.
  35. *
  36. * @returns Status text.
  37. */
  38. get statusText(): string;
  39. /**
  40. * Returns the response URL.
  41. *
  42. * @returns Response URL.
  43. */
  44. get responseURL(): string;
  45. /**
  46. * Returns the ready state.
  47. *
  48. * @returns Ready state.
  49. */
  50. get readyState(): XMLHttpRequestReadyStateEnum;
  51. /**
  52. * Get the response text.
  53. *
  54. * @throws {DOMException} If the response type is not text or empty.
  55. * @returns The response text.
  56. */
  57. get responseText(): string;
  58. /**
  59. * Get the responseXML.
  60. *
  61. * @throws {DOMException} If the response type is not text or empty.
  62. * @returns Response XML.
  63. */
  64. get responseXML(): IDocument;
  65. /**
  66. * Set response type.
  67. *
  68. * @param type Response type.
  69. * @throws {DOMException} If the state is not unsent or opened.
  70. * @throws {DOMException} If the request is synchronous.
  71. */
  72. set responseType(type: XMLHttpResponseTypeEnum | '');
  73. /**
  74. * Get response Type.
  75. *
  76. * @returns Response type.
  77. */
  78. get responseType(): XMLHttpResponseTypeEnum | '';
  79. /**
  80. * Opens the connection.
  81. *
  82. * @param method Connection method (eg GET, POST).
  83. * @param url URL for the connection.
  84. * @param [async=true] Asynchronous connection.
  85. * @param [user] Username for basic authentication (optional).
  86. * @param [password] Password for basic authentication (optional).
  87. */
  88. open(method: string, url: string, async?: boolean, user?: string, password?: string): void;
  89. /**
  90. * Sets a header for the request.
  91. *
  92. * @param header Header name
  93. * @param value Header value
  94. * @returns Header added.
  95. */
  96. setRequestHeader(header: string, value: string): boolean;
  97. /**
  98. * Gets a header from the server response.
  99. *
  100. * @param header header Name of header to get.
  101. * @returns string Text of the header or null if it doesn't exist.
  102. */
  103. getResponseHeader(header: string): string;
  104. /**
  105. * Gets all the response headers.
  106. *
  107. * @returns A string with all response headers separated by CR+LF.
  108. */
  109. getAllResponseHeaders(): string;
  110. /**
  111. * Sends the request to the server.
  112. *
  113. * @param data Optional data to send as request body.
  114. */
  115. send(data?: string): void;
  116. /**
  117. * Aborts a request.
  118. */
  119. abort(): void;
  120. /**
  121. * Changes readyState and calls onreadystatechange.
  122. *
  123. * @param state
  124. */
  125. private _setState;
  126. /**
  127. * Default request headers.
  128. *
  129. * @returns Default request headers.
  130. */
  131. private _getDefaultRequestHeaders;
  132. /**
  133. * Sends a synchronous request.
  134. *
  135. * @param options
  136. * @param ssl
  137. * @param data
  138. */
  139. private _sendSyncRequest;
  140. /**
  141. * Sends an async request.
  142. *
  143. * @param options
  144. * @param ssl
  145. * @param data
  146. */
  147. private _sendAsyncRequest;
  148. /**
  149. * Handles an async response.
  150. *
  151. * @param options Options.
  152. * @param ssl SSL.
  153. * @param data Data.
  154. * @param response Response.
  155. * @returns Promise.
  156. */
  157. private _onAsyncResponse;
  158. /**
  159. * Sends a local file system async request.
  160. *
  161. * @param url URL.
  162. * @returns Promise.
  163. */
  164. private _sendLocalAsyncRequest;
  165. /**
  166. * Sends a local file system synchronous request.
  167. *
  168. * @param url URL.
  169. */
  170. private _sendLocalSyncRequest;
  171. /**
  172. * Parses local request data.
  173. *
  174. * @param data Data.
  175. */
  176. private _parseLocalRequestData;
  177. /**
  178. * Returns response based to the "responseType" property.
  179. *
  180. * @param data Data.
  181. * @returns Parsed response.
  182. */
  183. private _parseResponseData;
  184. /**
  185. * Set Cookies from response headers.
  186. *
  187. * @param headers String array.
  188. */
  189. private _setCookies;
  190. /**
  191. * Called when an error is encountered to deal with it.
  192. *
  193. * @param error Error.
  194. */
  195. private _onError;
  196. /**
  197. * Decodes response text.
  198. *
  199. * @param data Data.
  200. * @returns Decoded text.
  201. **/
  202. private _decodeResponseText;
  203. }