HTTP requests identify Faceclaw in their user-agent string

This commit is contained in:
James Babcock committed 2026-08-20 11:32:50 -07:00
1 parent c27dcacfee
commit 8cdee2a701
14 files changed
+115 -9

No files matched your search

+2 -1
View File
@@ -7,6 +7,7 @@
import { GrayImage } from "../graphics/image";
import { getStringSetting } from "./settings-store";
import { grayImageFromPacket } from "./image-files";
import { fetchWithUserAgent } from "../util/http";
declare const com: any;
declare const global: any;
@@ -268,7 +269,7 @@ async function fetchJson(url: string, label: string): Promise<any> {
}
async function fetchWithTimeout(url: string, label: string): Promise<Response> {
const request = fetch(url);
const request = fetchWithUserAgent(url);
let timeoutHandle: ReturnType<typeof setTimeout> | null = null;
const timeout = new Promise<never>((_resolve, reject) => {
timeoutHandle = setTimeout(() => reject(new Error(`${label} timed out.`)), FETCH_TIMEOUT_MS);
+2 -1
View File
@@ -1,4 +1,5 @@
import { loadNightscoutSettings, nightscoutApiTokenSetting, nightscoutSiteUrlSetting } from "../ui/dashboard-settings";
import { fetchWithUserAgent } from "../util/http";
export type NightscoutPoint = {
timestampMs: number;
@@ -292,7 +293,7 @@ export class NightscoutBridge {
}
async function fetchJson<T>(url: string): Promise<T> {
const response = await fetch(url);
const response = await fetchWithUserAgent(url);
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
+5 -2
View File
@@ -1,5 +1,7 @@
import { hasLocationPermission } from "../g2/android-permissions";
import { getCurrentLocation, type CurrentLocation } from "./location";
import { fetchWithUserAgent } from "../util/http";
import { USER_AGENT } from "../version";
export type WeatherPhase = "permission-required" | "locating" | "loading" | "ready" | "error";
@@ -87,7 +89,8 @@ type NwsMeasure = {
const NWS_API_ROOT = "https://api.weather.gov";
const NWS_HEADERS = {
Accept: "application/geo+json",
"User-Agent": "Faceclaw/1.0 (https://github.com/jimrandomh/faceclaw)",
// NWS asks callers to identify themselves with a contact address.
"User-Agent": `${USER_AGENT} (https://github.com/jimrandomh/faceclaw)`,
};
const WEATHER_REFRESH_MS = 30 * 60 * 1000;
const FETCH_TIMEOUT_MS = 20_000;
@@ -230,7 +233,7 @@ async function loadLatestObservation(stationsUrl: string): Promise<NwsObservatio
}
async function fetchNwsJson<T>(url: string): Promise<T> {
const request = fetch(url, { headers: NWS_HEADERS });
const request = fetchWithUserAgent(url, { headers: NWS_HEADERS });
let timeoutHandle: ReturnType<typeof setTimeout> | null = null;
const timeout = new Promise<never>((_resolve, reject) => {
timeoutHandle = setTimeout(() => reject(new Error("Weather request timed out.")), FETCH_TIMEOUT_MS);