Skip to content

Commit

Permalink
feat: add x_cache field
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Apr 4, 2024
1 parent 8074521 commit e34a355
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/presets/columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default {
'og_image',
'request_time',
'status',
'x_cache',
'error',
'dom_size',
'html_size',
Expand Down Expand Up @@ -49,6 +50,7 @@ export default {
'url',
'depth',
'status',
'x_cache',
'error',
'mixed_content_url',
'is_canonical',
Expand Down
20 changes: 18 additions & 2 deletions src/presets/fields.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import registry from '../registry.js';
import fieldsLighthouse from './fields-lighthouse.js';
import fieldsLighthouseEn from './fields-lighthouse-en.js';

export const fields = [
{
name: 'url',
Expand Down Expand Up @@ -69,7 +70,8 @@ export const fields = [
comment: 'Код ответа страницы',
comment_en: 'HTTP answer code',
validate: {
error: '!= 200',
warning: '== 0',
error: '> 400',
},
stat: {
type: 'enum',
Expand All @@ -78,6 +80,20 @@ export const fields = [
type: 'integer',
filterType: 'enum',
},
{
name: 'x_cache',
comment: 'X-Cache',
comment_en: 'X-Cache',
validate: {
warning: '< 1',
},
stat: {
type: 'enum',
},
groups: ['perf'],
type: 'integer',
filterType: 'enum',
},
{
name: 'request_time',
comment: 'Время отдачи страницы (без js)',
Expand Down Expand Up @@ -498,7 +514,7 @@ for (let lhf of fieldsLighthouse) {
// plugins fields
const plugins = registry.getPlugins();
for (let plugin of plugins) {
if (plugin.fields) for(let field of plugin.fields) {
if (plugin.fields) for (let field of plugin.fields) {
if (typeof field === 'string') {
fields.push({
name: field,
Expand Down
3 changes: 3 additions & 0 deletions src/presets/scraperFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default {
'depth',
'result.error',
'response.status',
'result.x_cache',
'result.request_time',
'result.redirected_from',
'result.redirects',
Expand All @@ -23,6 +24,7 @@ export default {
'depth',
'result.error',
'response.status',
'result.x_cache',
'result.request_time',
'result.redirected_from',
'result.redirects',
Expand Down Expand Up @@ -70,6 +72,7 @@ export default {
'response.url',
'depth',
'result.error',
'result.x_cache',
'response.headers.content-type',
'response.headers.',
'response.headers.x-bitrix-composite',
Expand Down
8 changes: 8 additions & 0 deletions src/scrap-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,14 @@ async function scrapSite ({baseUrl, options = {}}) {
result = await crawl();
// console.log("after crawl(), result.response.status: ", result?.response?.status);

result.result.x_cache = 0;
for (let header in result.response.headers) {
if (header.match(/x-cache/) && result.response.headers[header].match(/hit/i)) {
result.result.x_cache = 1;
break;
}
}

if (options.lighthouse) {
const opts = {
logLevel: 'info',
Expand Down

0 comments on commit e34a355

Please sign in to comment.