app/publisher: use scheme from window.location

Also remove the scheme variable from the template that
tells what protocol the backend uses to talk to camlistore.

Fixes #920

Change-Id: Ia25e99d0f1b77077158f761f11a5c6bacfa2dc3b
This commit is contained in:
Attila Tajti 2017-04-24 11:33:08 +02:00
parent 8a545a1ed2
commit c1eeefe837
4 changed files with 9 additions and 11 deletions

View File

@ -12,7 +12,6 @@
var publishedRoot = {{$header.PublishedRoot}};
var pathPrefix = {{$header.PathPrefix}};
var host = {{$header.Host}};
var scheme = {{$header.Scheme}};
var camliViewIsOwner = {{$header.ViewerIsOwner}};
</script>
{{range $jsFile := $header.JSDeps}}

View File

@ -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) {

View File

@ -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,

View File

@ -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,