mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-29 05:31:51 +02:00
Request fallback name in header
This commit is contained in:
25
src-web/lib/fallbackRequestName.ts
Normal file
25
src-web/lib/fallbackRequestName.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import type { HttpRequest } from './models';
|
||||
|
||||
export function fallbackRequestName(r: HttpRequest | null): string {
|
||||
if (r == null) return '';
|
||||
|
||||
if (r.name) {
|
||||
return r.name;
|
||||
}
|
||||
|
||||
if (r.url.trim() === '') {
|
||||
return 'New Request';
|
||||
}
|
||||
|
||||
const fixedUrl = r.url.match(/^https?:\/\//) ? r.url : 'http://' + r.url;
|
||||
|
||||
try {
|
||||
const url = new URL(fixedUrl);
|
||||
const pathname = url.pathname === '/' ? '' : url.pathname;
|
||||
return `${url.host}${pathname}`;
|
||||
} catch (_) {
|
||||
// Nothing
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
Reference in New Issue
Block a user