webRequest.d.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import type { IWebRequest } from "./interfaces/iWebRequest";
  2. import type { Nullable } from "../types";
  3. /**
  4. * Extended version of XMLHttpRequest with support for customizations (headers, ...)
  5. */
  6. export declare class WebRequest implements IWebRequest {
  7. private readonly _xhr;
  8. /**
  9. * Custom HTTP Request Headers to be sent with XMLHttpRequests
  10. * i.e. when loading files, where the server/service expects an Authorization header
  11. */
  12. static CustomRequestHeaders: {
  13. [key: string]: string;
  14. };
  15. /**
  16. * Add callback functions in this array to update all the requests before they get sent to the network
  17. */
  18. static CustomRequestModifiers: ((request: XMLHttpRequest, url: string) => void)[];
  19. /**
  20. * If set to true, requests to Babylon.js CDN requests will not be modified
  21. */
  22. static SkipRequestModificationForBabylonCDN: boolean;
  23. /**
  24. * This function can be called to check if there are request modifiers for network requests
  25. * @returns true if there are any custom requests available
  26. */
  27. static get IsCustomRequestAvailable(): boolean;
  28. private _requestURL;
  29. private _injectCustomRequestHeaders;
  30. private _shouldSkipRequestModifications;
  31. /**
  32. * Gets or sets a function to be called when loading progress changes
  33. */
  34. get onprogress(): ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
  35. set onprogress(value: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null);
  36. /**
  37. * Returns client's state
  38. */
  39. get readyState(): number;
  40. /**
  41. * Returns client's status
  42. */
  43. get status(): number;
  44. /**
  45. * Returns client's status as a text
  46. */
  47. get statusText(): string;
  48. /**
  49. * Returns client's response
  50. */
  51. get response(): any;
  52. /**
  53. * Returns client's response url
  54. */
  55. get responseURL(): string;
  56. /**
  57. * Returns client's response as text
  58. */
  59. get responseText(): string;
  60. /**
  61. * Gets or sets the expected response type
  62. */
  63. get responseType(): XMLHttpRequestResponseType;
  64. set responseType(value: XMLHttpRequestResponseType);
  65. /**
  66. * Gets or sets the timeout value in milliseconds
  67. */
  68. get timeout(): number;
  69. set timeout(value: number);
  70. /** @internal */
  71. addEventListener<K extends keyof XMLHttpRequestEventMap>(type: K, listener: (this: XMLHttpRequest, ev: XMLHttpRequestEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
  72. /** @internal */
  73. removeEventListener<K extends keyof XMLHttpRequestEventMap>(type: K, listener: (this: XMLHttpRequest, ev: XMLHttpRequestEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
  74. /**
  75. * Cancels any network activity
  76. */
  77. abort(): void;
  78. /**
  79. * Initiates the request. The optional argument provides the request body. The argument is ignored if request method is GET or HEAD
  80. * @param body defines an optional request body
  81. */
  82. send(body?: Document | XMLHttpRequestBodyInit | null): void;
  83. /**
  84. * Sets the request method, request URL
  85. * @param method defines the method to use (GET, POST, etc..)
  86. * @param url defines the url to connect with
  87. */
  88. open(method: string, url: string): void;
  89. /**
  90. * Sets the value of a request header.
  91. * @param name The name of the header whose value is to be set
  92. * @param value The value to set as the body of the header
  93. */
  94. setRequestHeader(name: string, value: string): void;
  95. /**
  96. * Get the string containing the text of a particular header's value.
  97. * @param name The name of the header
  98. * @returns The string containing the text of the given header name
  99. */
  100. getResponseHeader(name: string): Nullable<string>;
  101. }