PuerkitoBio / purell

tiny Go library to normalize URLs
BSD 3-Clause "New" or "Revised" License
468 stars 59 forks source link

FlagForceHTTP -> to also force adding http if schema not present? #13

Closed dentot closed 9 years ago

dentot commented 9 years ago

Hey guys,

Still new with github, so pardon my ignorance.

I have a use case wherein input url doesn't contain schema, and was wondering if 'FlagForceHTTP' should also include adding default 'http' schema if schema doesn't exist, and not just if schema is 'https'? e.g. :

    &testCase{
        "ForceHTTP",
        "whereareyou.com",
        FlagForceHTTP,
        "http://whereareyou.com",
        false,
    },

Already made changes here in my local, and if this is a valid issue, should just be a simple fix, and will search on how to commit the change.

func forceHTTP(u *url.URL) { if strings.ToLower(u.Scheme) == "https" { u.Scheme = "http" }

// +den
// for those urls not having schema, then add http
if strings.ToLower(u.Scheme) == "" {
    u.Scheme = "http"
}
// -den

}

mna commented 9 years ago

Hi,

This looks like a duplicate of #11, the feature makes sense but there are some subtle issues as mentioned in the discussion.

Thanks, Martin