check / check (push) Waiting to run
internal/wafprotocol writes and reads the question, the answer and the report, and declares once each header, path and limit both daemons use. rproxy no longer imports internal/waf. Nothing on the wire changes. Model: opus-5-5
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package wafprotocol
|
|
|
|
import "net/http"
|
|
|
|
// Answer is what waf's answer to a question tells rproxy in its headers.
|
|
// The status, the other headers and the body of an answer of deny are what
|
|
// the visitor gets.
|
|
type Answer struct {
|
|
// Disposition is what rproxy does with the request: DispositionAllow,
|
|
// DispositionDeny or DispositionClose.
|
|
Disposition string
|
|
// ASN and Country are the client's AS number and country, each empty
|
|
// when the answer does not give it.
|
|
ASN, Country string
|
|
}
|
|
|
|
// SetAnswerHeaders sets the headers of waf's answer that tell rproxy answer,
|
|
// leaving out an ASN or Country that is empty.
|
|
func SetAnswerHeaders(header http.Header, answer Answer) {
|
|
header.Set(DispositionHeader, answer.Disposition)
|
|
|
|
if answer.ASN != "" {
|
|
header.Set(ASNHeader, answer.ASN)
|
|
}
|
|
|
|
if answer.Country != "" {
|
|
header.Set(CountryHeader, answer.Country)
|
|
}
|
|
}
|
|
|
|
// ReadAnswer returns what the headers of waf's answer tell rproxy, and
|
|
// whether they give a valid disposition.
|
|
func ReadAnswer(header http.Header) (Answer, bool) {
|
|
disposition := header.Get(DispositionHeader)
|
|
|
|
switch disposition {
|
|
case DispositionAllow, DispositionDeny, DispositionClose:
|
|
return Answer{
|
|
Disposition: disposition,
|
|
ASN: header.Get(ASNHeader),
|
|
Country: header.Get(CountryHeader),
|
|
}, true
|
|
}
|
|
|
|
return Answer{}, false
|
|
}
|