Changeset 124 in code for trunk/morty.go


Ignore:
Timestamp:
Jul 14, 2020, 9:22:08 PM (5 years ago)
Author:
asciimoo
Message:

[enh] inject header even if the page does not contain body element

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/morty.go

    r123 r124  
    184184
    185185type RequestConfig struct {
    186         Key     []byte
    187         BaseURL *url.URL
     186        Key          []byte
     187        BaseURL      *url.URL
     188        BodyInjected bool
    188189}
    189190
     
    455456                sanitizeCSS(&RequestConfig{Key: p.Key, BaseURL: parsedURI}, ctx, responseBody)
    456457        case contentType.SubType == "html" && contentType.Suffix == "":
    457                 sanitizeHTML(&RequestConfig{Key: p.Key, BaseURL: parsedURI}, ctx, responseBody)
     458                rc := &RequestConfig{Key: p.Key, BaseURL: parsedURI}
     459                sanitizeHTML(rc, ctx, responseBody)
     460                if !rc.BodyInjected {
     461                        p := HTMLBodyExtParam{rc.BaseURL.String(), false}
     462                        if len(rc.Key) > 0 {
     463                                p.HasMortyKey = true
     464                        }
     465                        err := HTML_BODY_EXTENSION.Execute(ctx, p)
     466                        if err != nil {
     467                                if DEBUG {
     468                                        fmt.Println("failed to inject body extension", err)
     469                                }
     470                        }
     471                }
    458472        default:
    459473                if contentDispositionBytes != nil {
     
    679693                                                }
    680694                                        }
     695                                        rc.BodyInjected = true
    681696                                case "style":
    682697                                        state = STATE_DEFAULT
Note: See TracChangeset for help on using the changeset viewer.