diff --git a/app/publisher/gallery.html b/app/publisher/gallery.html index 6ca071f9f..b8c1a4e51 100644 --- a/app/publisher/gallery.html +++ b/app/publisher/gallery.html @@ -12,7 +12,6 @@ var publishedRoot = {{$header.PublishedRoot}}; var pathPrefix = {{$header.PathPrefix}}; var host = {{$header.Host}}; - var scheme = {{$header.Scheme}}; var camliViewIsOwner = {{$header.ViewerIsOwner}}; {{range $jsFile := $header.JSDeps}} diff --git a/app/publisher/js/main.go b/app/publisher/js/main.go index ff11f7f87..9c7a9b310 100644 --- a/app/publisher/js/main.go +++ b/app/publisher/js/main.go @@ -22,6 +22,7 @@ package main import ( "fmt" + "strings" "camlistore.org/pkg/blob" @@ -48,11 +49,15 @@ func host() (string, error) { } func scheme() (string, error) { - s := js.Global.Get("scheme") - if undefOrEmptyString(s) { - return "", fmt.Errorf("No Scheme in header") + // We can't rely on the publisher's server-side to set the scheme as a var, + // because it could be behind a proxy, serving for a scheme different + // from the one we're seeing from the outside. + // Ask the browser instead what scheme/protocol the current page was accessed with. + proto := js.Global.Get("location").Get("protocol") + if undefOrEmptyString(proto) { + return "", fmt.Errorf("window.location.protocol missing or invalid") } - return s.String(), nil + return strings.TrimRight(proto.String(), ":"), nil } func subjectBasePath() (string, error) { diff --git a/app/publisher/main.go b/app/publisher/main.go index 65e75cc8c..e688d5e97 100644 --- a/app/publisher/main.go +++ b/app/publisher/main.go @@ -976,17 +976,12 @@ func (pr *publishRequest) fileSchemaRefFromBlob(des *search.DescribedBlob) (file // subjectHeader returns the PageHeader corresponding to the described subject. func (pr *publishRequest) subjectHeader(described map[string]*search.DescribedBlob) *publish.PageHeader { subdes := described[pr.subject.String()] - scheme := "http" - if pr.req.TLS != nil { - scheme = "https" - } header := &publish.PageHeader{ Title: html.EscapeString(getTitle(subdes.BlobRef, described)), CSSFiles: pr.cssFiles(), JSDeps: pr.jsDeps(), Subject: pr.subject, Host: pr.req.Host, - Scheme: scheme, SubjectBasePath: pr.subjectBasePath, PathPrefix: pr.base, PublishedRoot: pr.publishedRoot, diff --git a/pkg/publish/types.go b/pkg/publish/types.go index dad89b408..4629af030 100644 --- a/pkg/publish/types.go +++ b/pkg/publish/types.go @@ -52,7 +52,6 @@ type PageHeader struct { // "/pics/", or "/" if the request was not proxied through Camlistore. PathPrefix string Host string - Scheme string } // PageFile contains the file related data available to the subject template,