mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-26 01:41:04 +08:00
19 lines
650 B
Go
19 lines
650 B
Go
package intercept
|
|
|
|
import "net/http"
|
|
|
|
// ApplyAssessmentUserAgent adds the task's configured identifier to a target
|
|
// request. An explicitly supplied User-Agent, including an empty one, takes
|
|
// precedence. It reports whether it inserted the identifier.
|
|
func ApplyAssessmentUserAgent(req *http.Request) bool {
|
|
scope, ok := TargetScopeFromContext(req.Context())
|
|
if !ok || scope.TaskID == "" || scope.ConversationID != 0 || !scope.AssessmentIdentity.AllowsOrigin(req.URL) {
|
|
return false
|
|
}
|
|
if _, explicit := req.Header["User-Agent"]; explicit {
|
|
return false
|
|
}
|
|
req.Header.Set("User-Agent", scope.AssessmentIdentity.UserAgent())
|
|
return true
|
|
}
|