mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
The webinspector debugger now does not requre http-request
This commit is contained in:
2
http/http-request.d.ts
vendored
2
http/http-request.d.ts
vendored
@@ -2,7 +2,5 @@
|
||||
|
||||
declare module "http/http-request" {
|
||||
import http = require("http");
|
||||
|
||||
export var domainDebugger: any;
|
||||
export var request: (options: http.HttpRequestOptions) => Promise<http.HttpResponse>;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* iOS specific http request implementation.
|
||||
*/
|
||||
|
||||
declare var __inspectorTimestamp;
|
||||
import http = require("http");
|
||||
|
||||
import * as types from "utils/types";
|
||||
@@ -10,8 +9,7 @@ import * as imageSourceModule from "image-source";
|
||||
import * as utilsModule from "utils/utils";
|
||||
import * as fsModule from "file-system";
|
||||
|
||||
import resource_data = require("./resource-data");
|
||||
import debuggerDomains = require("./../debugger/debugger");
|
||||
import domainDebugger = require("./../debugger/debugger");
|
||||
|
||||
var GET = "GET";
|
||||
var USER_AGENT_HEADER = "User-Agent";
|
||||
@@ -20,8 +18,6 @@ var sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration();
|
||||
var queue = NSOperationQueue.mainQueue();
|
||||
var session = NSURLSession.sessionWithConfigurationDelegateDelegateQueue(sessionConfig, null, queue);
|
||||
|
||||
export var domainDebugger: any;
|
||||
|
||||
var utils: typeof utilsModule;
|
||||
function ensureUtils() {
|
||||
if (!utils) {
|
||||
@@ -40,14 +36,7 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
|
||||
return new Promise<http.HttpResponse>((resolve, reject) => {
|
||||
|
||||
try {
|
||||
// var sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration();
|
||||
// var queue = NSOperationQueue.mainQueue();
|
||||
// var session = NSURLSession.sessionWithConfigurationDelegateDelegateQueue(
|
||||
// sessionConfig, null, queue);
|
||||
|
||||
var requestId = Math.random().toString();
|
||||
var resourceData = new resource_data.ResourceData(requestId);
|
||||
domainDebugger.resource_datas[requestId] = resourceData;
|
||||
var debugRequest = domainDebugger.network && domainDebugger.network.create();
|
||||
|
||||
var urlRequest = NSMutableURLRequest.requestWithURL(
|
||||
NSURL.URLWithString(options.url));
|
||||
@@ -87,28 +76,22 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
|
||||
(<any>http).addHeader(headers, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
domainDebugger.resource_datas[requestId].mimeType = response.MIMEType;
|
||||
domainDebugger.resource_datas[requestId].data = data;
|
||||
var debugResponse = {
|
||||
// Response URL. This URL can be different from CachedResource.url in case of redirect.
|
||||
url: options.url,
|
||||
// HTTP response status code.
|
||||
status: response.statusCode,
|
||||
// HTTP response status text.
|
||||
statusText: NSHTTPURLResponse.localizedStringForStatusCode(response.statusCode),
|
||||
// HTTP response headers.
|
||||
headers: headers,
|
||||
// HTTP response headers text.
|
||||
mimeType: response.MIMEType,
|
||||
fromDiskCache: false
|
||||
|
||||
if (debugRequest) {
|
||||
debugRequest.mimeType = response.MIMEType;
|
||||
debugRequest.data = data;
|
||||
var debugResponse = {
|
||||
url: options.url,
|
||||
status: response.statusCode,
|
||||
statusText: NSHTTPURLResponse.localizedStringForStatusCode(response.statusCode),
|
||||
headers: headers,
|
||||
mimeType: response.MIMEType,
|
||||
fromDiskCache: false
|
||||
}
|
||||
debugRequest.responseReceived(debugResponse);
|
||||
debugRequest.loadingFinished();
|
||||
}
|
||||
|
||||
// Loader Identifier is hardcoded in the runtime and should be the same string
|
||||
// __inspectorTimestamp is provided by the runtime and returns a frontend friendly timestamp
|
||||
domainDebugger.events.responseReceived(requestId, "NativeScriptMainFrameIdentifier", "Loader Identifier", __inspectorTimestamp(), exports.domainDebugger.resource_datas[requestId].resourceType, debugResponse);
|
||||
domainDebugger.events.loadingFinished(requestId, __inspectorTimestamp());
|
||||
|
||||
resolve({
|
||||
content: {
|
||||
raw: data,
|
||||
@@ -162,14 +145,13 @@ export function request(options: http.HttpRequestOptions): Promise<http.HttpResp
|
||||
}
|
||||
});
|
||||
|
||||
if(options.url) {
|
||||
if(options.url && debugRequest) {
|
||||
var request = {
|
||||
url: options.url,
|
||||
method: "GET",
|
||||
headers: options.headers
|
||||
url: options.url,
|
||||
method: "GET",
|
||||
headers: options.headers
|
||||
};
|
||||
|
||||
domainDebugger.events.requestWillBeSent(requestId, "NativeScriptMainFrameIdentifier", "Loader Identifier", options.url, request, __inspectorTimestamp(), { type: 'Script' });
|
||||
debugRequest.requestWillBeSent(request);
|
||||
}
|
||||
|
||||
dataTask.resume();
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
var documentTypeByMimeType = [];
|
||||
documentTypeByMimeType["text/xml"] = "Document";
|
||||
documentTypeByMimeType["text/plain"] = "Document";
|
||||
documentTypeByMimeType["text/html"] = "Document";
|
||||
documentTypeByMimeType["application/xml"] = "Document";
|
||||
documentTypeByMimeType["application/xhtml+xml"] = "Document";
|
||||
documentTypeByMimeType["text/css"] = "Stylesheet";
|
||||
documentTypeByMimeType["text/javascript"] = "Script";
|
||||
documentTypeByMimeType["text/ecmascript"] = "Script";
|
||||
documentTypeByMimeType["application/javascript"] = "Script";
|
||||
documentTypeByMimeType["application/ecmascript"] = "Script";
|
||||
documentTypeByMimeType["application/x-javascript"] = "Script";
|
||||
documentTypeByMimeType["application/json"] = "Script";
|
||||
documentTypeByMimeType["application/x-json"] = "Script";
|
||||
documentTypeByMimeType["text/x-javascript"] = "Script";
|
||||
documentTypeByMimeType["text/x-json"] = "Script";
|
||||
documentTypeByMimeType["text/typescript"] = "Script";
|
||||
|
||||
export class ResourceData {
|
||||
|
||||
private _requestID: string;
|
||||
private _resourceType: string;
|
||||
private _data: any;
|
||||
private _mimeType: string;
|
||||
|
||||
constructor(requestID: string) {
|
||||
this._requestID = requestID;
|
||||
}
|
||||
|
||||
get mimeType(): string {
|
||||
return this._mimeType;
|
||||
}
|
||||
|
||||
set mimeType(value: string) {
|
||||
if (this._mimeType !== value) {
|
||||
this._mimeType = value;
|
||||
|
||||
var resourceType = "Other";
|
||||
|
||||
if (this._mimeType in documentTypeByMimeType) {
|
||||
resourceType = documentTypeByMimeType[this._mimeType];
|
||||
}
|
||||
|
||||
if(this._mimeType.indexOf("image/") !== -1) {
|
||||
resourceType = "Image";
|
||||
}
|
||||
|
||||
if (this._mimeType.indexOf("font/") !== -1) {
|
||||
resourceType = "Font";
|
||||
}
|
||||
|
||||
this._resourceType = resourceType;
|
||||
}
|
||||
}
|
||||
|
||||
get requestID(): string {
|
||||
return this._requestID;
|
||||
}
|
||||
|
||||
get hasTextContent(): boolean {
|
||||
return [ "Document", "Stylesheet", "Script", "XHR" ].indexOf(this._resourceType) !== -1;
|
||||
}
|
||||
|
||||
get data(): any {
|
||||
return this._data;
|
||||
}
|
||||
|
||||
set data(value: any) {
|
||||
if (this._data !== value) {
|
||||
this._data = value;
|
||||
}
|
||||
}
|
||||
|
||||
get resourceType() {
|
||||
return this._resourceType;
|
||||
}
|
||||
|
||||
set resourceType(value: string) {
|
||||
if (this._resourceType !== value) {
|
||||
this._resourceType = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user