Make a change so that HTTPS is not forced on the local network (or specifically when…
- User
Make a change so that HTTPS is not forced on the local network (or specifically when accessed through [Redacted IPAddress])
Assistant
Based on the repository files, I can help modify the HFS server to not force HTTPS on local network or specific IP addresses. Here's how we can implement this:
The relevant code is in
middlewares.tswhere the HTTPS forcing logic is implemented, and the configuration is defined inconfig.ts.The solution would be to modify the
force_httpsconfiguration to support more granular control. Here's what needs to be changed:- First, modify the config definition in
config.tsto support the new format:
typescript// Change from: const forceHttps = defineConfig('force_https', true) // To: const forceHttps = defineConfig<boolean | {except?: string[]}>('force_https', { enabled: true, except: ['[Redacted IPAddress]/16', '[Redacted IPAddress]/8', '[Redacted IPAddress]/12'] // Default local network ranges })- Then modify the HTTPS redirect logic in
middlewares.ts:
typescript// In middlewares.ts, modify the someSecurity middleware: if (!ctx.secure && forceHttps.get() && getHttpsWorkingPort() && !isLocalHost(ctx)) { // Add check for force_https configuration const config = forceHttps.get() const clientIp = ctx.request.ip // If config is boolean, use old behavior if (typeof config === 'boolean') { if (config) { const { URL } = ctx URL.protocol = 'https' URL.port = getHttpsWorkingPort() ctx.status = 307 return ctx.redirect(URL.href) } } // If config is object with exceptions, check IP else if (config.except) { const shouldForce = !config.except.some(network => { // Check if IP matches any of the excepted networks if (network.includes('/')) { // Network mask format like [Redacted IPAddress]/16 const [base, bits] = network.split('/') // Use existing isLocalHost helper or implement network mask checking return isInNetwork(clientIp, base, parseInt(bits)) } // Exact IP match return network === clientIp }) if (shouldForce) { const { URL } = ctx URL.protocol = 'https' URL.port = getHttpsWorkingPort() ctx.status = 307 return ctx.redirect(URL.href) } } }- First, modify the config definition in
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.