Skip to content

Commit

Permalink
Add Rate Limit Headers to Table
Browse files Browse the repository at this point in the history
  • Loading branch information
pro4tlzz committed Jun 27, 2023
1 parent 091a449 commit 99f6463
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion rockstar/rockstar.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@
}
.hoverDiv:hover {
background-color: #f0f0f0;
}
}
.rs_headerTable td {
padding: 8px;
}
16 changes: 14 additions & 2 deletions rockstar/rockstar.js
Original file line number Diff line number Diff line change
Expand Up @@ -979,14 +979,26 @@
}
requestJSON({url, method: method.value, data: data.value}).then((objects, status, jqXHR) => {
$(results).html("<br>");
var linkHeader = jqXHR.getResponseHeader("Link"); // TODO: maybe show X-Rate-Limit-* headers, too.
var linkHeader = jqXHR.getResponseHeader("Link");
var remaining = jqXHR.getResponseHeader("X-Rate-Limit-Remaining");
var limit = jqXHR.getResponseHeader("X-Rate-Limit-Limit");
var reset = new Date(jqXHR.getResponseHeader("X-Rate-Limit-Reset") * 1000);
var headersTable =
`
<br>Headers<br><table class="rs_headerTable">
<tr><td>Rate Limit<td> ${limit}
<tr><td>Rate Limit Remaining<td> ${remaining}
<tr><td>Rate Limit Reset<td> ${reset}
`;
if (linkHeader) {
$(results).html("<br>Headers<br><table><tr><td>Link<td>" + linkHeader.replace(/</g, "&lt;").replace(/, /g, "<br>") + "</table><br>");
$(results).html(headersTable + '<tr><td>Link<td>' + linkHeader.replace(/</g, "&lt;").replace(/, /g, "<br>") + '</table><br>');
var links = getLinks(linkHeader);
if (links.next) {
var nextUrl = new URL(links.next); // links.next is an absolute URL; we need a relative URL.
nextUrl = nextUrl.pathname + nextUrl.search;
}
} else {
$(results).html(headersTable + '</table><br>');
}
$(results).append("Status: " + jqXHR.status + " " + jqXHR.statusText + "<br>");
if (objects) {
Expand Down

0 comments on commit 99f6463

Please sign in to comment.