mami-project / pto3-go

MAMI Path Transparency Observatory server (v3) and associated utilities
1 stars 2 forks source link

Cached queries have wrong links #119

Closed ghost closed 5 years ago

ghost commented 5 years ago

Links in cached queries have "/query/..." but should have baseUrl prepended

ghost commented 5 years ago

Part of the problem is url.ResolveReference(). Consider the following code snippets:

const (
    base     = "https://a.b.c.com/path/"
    relative = "raw"
)

func main() {
    baseU := url.Parse("https://a.b.c.com/path/")
    relU := url.Parse("raw")
    link := baseU.ResolveReference(relU)
}

This will cause link to have the value "https://a.b.c.com/path/raw", as expected. But consider

func main() {
    baseU := url.Parse("https://a.b.c.com/path")
    relU := url.Parse("raw")
    link := baseU.ResolveReference(relU)
}

Now, link has the value "https://a.b.c.com/raw". This may perhaps also be expected. But now consider

func main() {
    baseU := url.Parse("https://a.b.c.com/path")
    relU := url.Parse("/raw")
    link := baseU.ResolveReference(relU)
}

This doesn't make a difference! Even now, link contains "https://a.b.c.com/raw". Okay, you may say, let's put slashes everywhere, just to be on the safe side:

func main() {
    baseU := url.Parse("https://a.b.c.com/path/")
    relU := url.Parse("/raw")
    link := baseU.ResolveReference(relU)
}

Nope, link still contains "https://a.b.c.com/raw". So the only way to get the behaviour we want is:

ghost commented 5 years ago

I'm thinking of making sure that

ghost commented 5 years ago

I implemented the suggestion in the previous comment and now everything seems to work OK