plugins: ctx.state.webdavDetected
Massimo Melina committed
May 1, 2026 at 00:19 UTC
10277a5564d2cdbabcfa659ce20450f987f7aae5
2 files changed
+10
dev-plugins.md
+1
@@ -905,6 +905,7 @@ Where there is too little information, you'll have to consult the source code. A
905
archive?: string
906
fileSource?: string // set when serving a file
907
fileStats?: Stat // file attributes
908
+ webdavDetected?: boolean // there's no clear way to detect a webdav client, but this is the result of the heuristic in HFS
909
910
## Other files
911
src/webdav.ts
+9
@@ -103,9 +103,12 @@ export const webdav: Koa.Middleware = async (ctx, next) => {
103
const ua = ctx.get('user-agent')
104
if (path.includes('/._') && ua?.startsWith('WebDAVFS')) {// too much spam from Finder for these files that can contain metas
105
ctx.state.dontLog = true
106
+ ctx.state.webdavDetected = true
107
return ctx.status = HTTP_FORBIDDEN
108
}
109
const isWebdavAuthRequest = WEBDAV_METHODS.has(ctx.method) || WEBDAV_HINT_HEADERS.some(h => ctx.get(h))
110
+ if (isWebdavAuthRequest)
111
+ ctx.state.webdavDetected = true
112
if (isWebdavAuthRequest && ua && getCurrentUsername(ctx))
113
webdavDetectedAgents.try(webdavAgentKey(ctx, ua), () => true)
114
@@ -395,3 +398,9 @@ function dotClean(path: string) {
398
}
399
}, 10_000))
400
}
401
+
402
+declare module "koa" {
403
+ interface DefaultState {
404
+ webdavDetected?: boolean
405
+ }
406
+}
\ No newline at end of file