Compare commits

..

3 commits

4 changed files with 2 additions and 8 deletions

View file

@ -27,7 +27,7 @@ func Root(resp *types.SpaceAPIResponseV14) func(http.ResponseWriter, *http.Reque
} }
w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json; charset=utf-8")
_, _ = w.Write(response) _, _ = w.Write(response)
} }
} }

View file

@ -1,7 +1,6 @@
package handlers package handlers
import ( import (
"io"
"log" "log"
"math" "math"
"net/http" "net/http"
@ -34,7 +33,5 @@ func EnvironmentSensor(
// Set SpaceAPI response values // Set SpaceAPI response values
resp.Value = newState resp.Value = newState
resp.LastChange = time.Now().Unix() resp.LastChange = time.Now().Unix()
_, _ = io.WriteString(w, "Update Successful")
} }
} }

View file

@ -1,7 +1,6 @@
package handlers package handlers
import ( import (
"io"
"log" "log"
"net/http" "net/http"
"strconv" "strconv"
@ -33,7 +32,5 @@ func StateOpen(
// Set SpaceAPI response values // Set SpaceAPI response values
resp.Open = newState resp.Open = newState
resp.LastChange = time.Now().Unix() resp.LastChange = time.Now().Unix()
_, _ = io.WriteString(w, "Update Successful")
} }
} }

View file

@ -19,7 +19,7 @@ func updateEndpointValidator(
// Check BasicAuth credentials // Check BasicAuth credentials
username, password, ok := r.BasicAuth() username, password, ok := r.BasicAuth()
if !ok || !util.CheckCredentials(authDB, validCredentials, username, password) { if !ok || !util.CheckCredentials(authDB, validCredentials, username, password) {
w.Header().Set("WWW-Authenticate", "Basic realm=\"space-api\"") w.Header()["WWW-Authenticate"] = []string{"Basic realm=\"spaceapid\""}
http.Error(w, "", http.StatusUnauthorized) http.Error(w, "", http.StatusUnauthorized)
return []byte{}, errors.New(fmt.Sprintf("Unauthorized request from %s Username: %s Password: %s", r.RemoteAddr, username, password)) return []byte{}, errors.New(fmt.Sprintf("Unauthorized request from %s Username: %s Password: %s", r.RemoteAddr, username, password))
} }