[enh] inject header even if the page does not contain body element
git-svn-id: https://svn.yakumo.dev/yakumo.izuru/yukari/trunk@124 f3bd38d9-da89-464d-a02a-eb04e43141b5
This commit is contained in:
parent
2651c4549c
commit
ac030bd851
21
morty.go
21
morty.go
@ -183,8 +183,9 @@ type Proxy struct {
|
||||
}
|
||||
|
||||
type RequestConfig struct {
|
||||
Key []byte
|
||||
BaseURL *url.URL
|
||||
Key []byte
|
||||
BaseURL *url.URL
|
||||
BodyInjected bool
|
||||
}
|
||||
|
||||
type HTMLBodyExtParam struct {
|
||||
@ -454,7 +455,20 @@ func (p *Proxy) RequestHandler(ctx *fasthttp.RequestCtx) {
|
||||
case contentType.SubType == "css" && contentType.Suffix == "":
|
||||
sanitizeCSS(&RequestConfig{Key: p.Key, BaseURL: parsedURI}, ctx, responseBody)
|
||||
case contentType.SubType == "html" && contentType.Suffix == "":
|
||||
sanitizeHTML(&RequestConfig{Key: p.Key, BaseURL: parsedURI}, ctx, responseBody)
|
||||
rc := &RequestConfig{Key: p.Key, BaseURL: parsedURI}
|
||||
sanitizeHTML(rc, ctx, responseBody)
|
||||
if !rc.BodyInjected {
|
||||
p := HTMLBodyExtParam{rc.BaseURL.String(), false}
|
||||
if len(rc.Key) > 0 {
|
||||
p.HasMortyKey = true
|
||||
}
|
||||
err := HTML_BODY_EXTENSION.Execute(ctx, p)
|
||||
if err != nil {
|
||||
if DEBUG {
|
||||
fmt.Println("failed to inject body extension", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
if contentDispositionBytes != nil {
|
||||
ctx.Response.Header.AddBytesV("Content-Disposition", contentDispositionBytes)
|
||||
@ -678,6 +692,7 @@ func sanitizeHTML(rc *RequestConfig, out io.Writer, htmlDoc []byte) {
|
||||
fmt.Println("failed to inject body extension", err)
|
||||
}
|
||||
}
|
||||
rc.BodyInjected = true
|
||||
case "style":
|
||||
state = STATE_DEFAULT
|
||||
case "noscript":
|
||||
|
Loading…
x
Reference in New Issue
Block a user