darkweak / go-esi

Pure implementation of the non-standard ESI (Edge-Side-Include) specification in Go
MIT License
22 stars 6 forks source link

fix: handle includes without hosts #6

Closed dkarlovi closed 1 year ago

dkarlovi commented 1 year ago

Fixes #4.

darkweak commented 1 year ago

Got something working @dkarlovi

// writer.go
// ...

func NewWriter(buf *bytes.Buffer, rw http.ResponseWriter, rq *http.Request) *Writer {
    if rq.URL.Scheme == "" {
        if rq.TLS != nil {
            rq.URL.Scheme = "https"
        } else {
            rq.URL.Scheme = "http"
        }
    }

    if rq.URL.Host == "" {
        rq.URL.Host = rq.Host
    }

    return &Writer{
        buf:      buf,
        Rq:       rq,
        rw:       rw,
        AsyncBuf: make([]chan []byte, 0),
        Done:     make(chan bool),
    }
}

// ...
// include.go

// ...
    if e := i.loadAttributes(b[8:i.length]); e != nil {
        return nil, len(b)
    }

    u, _ := url.Parse(i.src)
    i.src = req.URL.ResolveReference(u).String()
// ...
dkarlovi commented 1 year ago

Feel free to close this if you've solved it differently. 👍

darkweak commented 1 year ago

Resolved by #7