Skip to content

Commit

Permalink
Add Last-Modified header field
Browse files Browse the repository at this point in the history
  • Loading branch information
akuny committed Jun 10, 2024
1 parent b50db5c commit 636a006
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions entities/core-result.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ export class CoreResult {
})
usaClassesUsed?: string;

@Column({ nullable: true })
@Exclude()
lastModifiedHeaderValue?: string;

static getColumnNames(): string[] {
// return class-transformer version of column names
return Object.keys(classToPlain(new CoreResult()));
Expand Down
1 change: 1 addition & 0 deletions entities/scan-data.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type SeoScan = {
ogUrlContent: string;
htmlLangContent: string;
hrefLangContent: string;
lastModifiedHeaderValue: string;
};

export type ThirdPartyScan = {
Expand Down
2 changes: 1 addition & 1 deletion libs/core-scanner/src/pages/primary.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('primary scanner', () => {
};
const scanner = await createPrimaryScanner(mockLogger, input);
const result = await scanner(page);
expect(result).toEqual({
expect(result).toMatchObject({
urlScan: {
targetUrlRedirects: true,
finalUrl: 'https://18f.gsa.gov/',
Expand Down
1 change: 1 addition & 0 deletions libs/core-scanner/src/scans/seo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('seo scan', () => {
'https://www.arc.gov/wp-content/uploads/2020/08/48982308566_5ce274f0ab_o-washington-scaled.jpg',
ogTypeContent: 'website',
ogUrlContent: 'https://www.arc.gov/',
lastModifiedHeaderValue: null,
});
}, 'arc_gov_dump.mht');
});
Expand Down
16 changes: 16 additions & 0 deletions libs/core-scanner/src/scans/seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const buildSeoResult = async (
const ogUrlContent = await findOpenGraphTag(page, 'og:url');
const htmlLangContent = await findHtmlLangContent(page);
const hrefLangContent = await findHreflangContent(page);
const lastModifiedHeaderValue = await findLastModifiedHeaderValue(response);

return {
ogTitleFinalUrl,
Expand All @@ -49,6 +50,7 @@ export const buildSeoResult = async (
ogUrlContent,
htmlLangContent,
hrefLangContent,
lastModifiedHeaderValue,
};
};

Expand Down Expand Up @@ -204,3 +206,17 @@ const findHreflangContent = async (page: Page): Promise<string> => {

return content;
};

const findLastModifiedHeaderValue = async (
response: HTTPResponse,
): Promise<string> => {
const headers = await response.headers();

for (const key in headers) {
if (key.toLowerCase() === 'last-modified') {
return headers[key];
}
}

return null;
};
1 change: 1 addition & 0 deletions libs/database/src/core-results/core-result.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ describe('CoreResultService', () => {
ogUrlContent: null,
htmlLangContent: null,
hrefLangContent: null,
lastModifiedHeaderValue: null,
},
thirdPartyScan: {
thirdPartyServiceDomains: null,
Expand Down
3 changes: 3 additions & 0 deletions libs/database/src/core-results/core-result.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export class CoreResultService {
coreResult.ogUrlContent = result.seoScan.ogUrlContent;
coreResult.htmlLangContent = result.seoScan.htmlLangContent;
coreResult.hrefLangContent = result.seoScan.hrefLangContent;
coreResult.lastModifiedHeaderValue =
result.seoScan.lastModifiedHeaderValue;

// Third-party scan
coreResult.thirdPartyServiceCount =
Expand Down Expand Up @@ -195,6 +197,7 @@ export class CoreResultService {
coreResult.ogUrlContent = null;
coreResult.htmlLangContent = null;
coreResult.hrefLangContent = null;
coreResult.lastModifiedHeaderValue = null;
}
}

Expand Down

0 comments on commit 636a006

Please sign in to comment.