mirror of
https://github.com/morten-olsen/react-native-debug-console.git
synced 2026-02-08 00:36:26 +01:00
Add request as soon as they are send
This commit is contained in:
@@ -42,6 +42,9 @@ const Indented = styled.View`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const getResponse = (contentType, request) => {
|
const getResponse = (contentType, request) => {
|
||||||
|
if (!contentType) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (request.responseType == 'blob' || request.responseType == 'ArrayBuffer') {
|
if (request.responseType == 'blob' || request.responseType == 'ArrayBuffer') {
|
||||||
return <Emphasis>🤖 Binary</Emphasis>
|
return <Emphasis>🤖 Binary</Emphasis>
|
||||||
}
|
}
|
||||||
@@ -111,7 +114,7 @@ const Response = ({
|
|||||||
|
|
||||||
|
|
||||||
const getPreview = (contentType, request, url) => {
|
const getPreview = (contentType, request, url) => {
|
||||||
if (request.responseType == 'blob' || request.responseType == 'ArrayBuffer') {
|
if (!contentType || request.responseType == 'blob' || request.responseType == 'ArrayBuffer' || !contentType) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const contentTypes = contentType.split(';').map(c => c.trim());
|
const contentTypes = contentType.split(';').map(c => c.trim());
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import {
|
|||||||
} from '../base/text';
|
} from '../base/text';
|
||||||
|
|
||||||
const getColor = (code) => {
|
const getColor = (code) => {
|
||||||
|
if (code === 0) {
|
||||||
|
return '#c0392b';
|
||||||
|
}
|
||||||
if (code >= 500) {
|
if (code >= 500) {
|
||||||
return '#c0392b';
|
return '#c0392b';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
const proxied = window.XMLHttpRequest.prototype.open;
|
const proxied = window.XMLHttpRequest.prototype.open;
|
||||||
|
let currentId = 0;
|
||||||
|
|
||||||
class Network {
|
class Network {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.requests = [];
|
this.requests = [];
|
||||||
this.listeners = [];
|
this.listeners = [];
|
||||||
this.currentId = 0;
|
|
||||||
// this.clear = this.clear.bind(this);
|
// this.clear = this.clear.bind(this);
|
||||||
this.get = this.get.bind(this);
|
this.get = this.get.bind(this);
|
||||||
}
|
}
|
||||||
@@ -27,11 +27,19 @@ class Network {
|
|||||||
this.listeners.forEach(l => l(this.requests));
|
this.listeners.forEach(l => l(this.requests));
|
||||||
}
|
}
|
||||||
|
|
||||||
addRequest(request) {
|
addRequest(id, request) {
|
||||||
this.requests.push({
|
const index = this.requests.findIndex(req => req.id === id);
|
||||||
id: this.currentId++,
|
if (index >= 0) {
|
||||||
...request,
|
this.requests[index] = {
|
||||||
});
|
id,
|
||||||
|
...request,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
this.requests.push({
|
||||||
|
id,
|
||||||
|
...request,
|
||||||
|
});
|
||||||
|
}
|
||||||
this.listeners.forEach(l => l(this.requests));
|
this.listeners.forEach(l => l(this.requests));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,20 +52,21 @@ class Network {
|
|||||||
method,
|
method,
|
||||||
url,
|
url,
|
||||||
] = args;
|
] = args;
|
||||||
|
const id = currentId++;
|
||||||
this.addEventListener('load', () => {
|
this.addEventListener('load', () => {
|
||||||
me.addRequest({
|
me.addRequest(id, {
|
||||||
url,
|
url,
|
||||||
method,
|
method,
|
||||||
args: sendArgs,
|
args: sendArgs,
|
||||||
headers,
|
headers,
|
||||||
requestHeaders: this.getAllResponseHeaders(),
|
requestHeaders: this.getAllResponseHeaders(),
|
||||||
contentType: this.getResponseHeader('content-type') || '',
|
contentType: (this.getResponseHeader('content-type') || ''),
|
||||||
request: this,
|
request: this,
|
||||||
status: this.status,
|
status: this.status || null,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
this.addEventListener('error', (error) => {
|
this.addEventListener('error', (error) => {
|
||||||
me.addRequest({
|
me.addRequest(id, {
|
||||||
url,
|
url,
|
||||||
method,
|
method,
|
||||||
error,
|
error,
|
||||||
@@ -65,13 +74,21 @@ class Network {
|
|||||||
headers,
|
headers,
|
||||||
requestHeaders: this.getAllResponseHeaders(),
|
requestHeaders: this.getAllResponseHeaders(),
|
||||||
request: this,
|
request: this,
|
||||||
status: this.status || 'CONN ERR',
|
status: this.status,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
const proxiedSend = this.send;
|
const proxiedSend = this.send;
|
||||||
const proxiedSetRequestHeader = this.setRequestHeader;
|
const proxiedSetRequestHeader = this.setRequestHeader;
|
||||||
this.send = function proxySend (...sendargs) {
|
this.send = function proxySend (...sendargs) {
|
||||||
sendArgs = sendargs;
|
sendArgs = sendargs;
|
||||||
|
me.addRequest(id, {
|
||||||
|
url,
|
||||||
|
method,
|
||||||
|
args: sendArgs,
|
||||||
|
headers,
|
||||||
|
request: this,
|
||||||
|
status: 'Waiting',
|
||||||
|
});
|
||||||
return proxiedSend.apply(this, [].slice.call(arguments));
|
return proxiedSend.apply(this, [].slice.call(arguments));
|
||||||
}
|
}
|
||||||
this.setRequestHeader = function (name, value) {
|
this.setRequestHeader = function (name, value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user