aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-10-16 16:10:14 +0200
committerAlex Auvolat <alex@adnab.me>2023-10-16 16:10:14 +0200
commit75b27becf26516a65549a00378155437e4acce4e (patch)
tree97d818b819b5d78e96e8a8a1219b5a362e150350
parent224cb5e217f4e6c69cde1bb3fd26fecd6ced5f9a (diff)
downloadbagage-75b27becf26516a65549a00378155437e4acce4e.tar.gz
bagage-75b27becf26516a65549a00378155437e4acce4e.zip
Fix CORS by allowing everything
-rw-r--r--cors.go30
-rw-r--r--main.go35
2 files changed, 51 insertions, 14 deletions
diff --git a/cors.go b/cors.go
new file mode 100644
index 0000000..a05e6d5
--- /dev/null
+++ b/cors.go
@@ -0,0 +1,30 @@
+package main
+
+import (
+ "net/http"
+)
+
+type CorsAllowAllOrigins struct {
+ AndThen http.Handler
+}
+
+func (c CorsAllowAllOrigins) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ w.Header().Add("Access-Control-Allow-Origin", "*")
+ w.Header().Add("Access-Control-Allow-Methods", "*")
+ w.Header().Add("Access-Control-Allow-Headers", "*")
+ c.AndThen.ServeHTTP(w, r)
+}
+
+type OptionsNoError struct {
+ Error ErrorHandler
+}
+
+func (c OptionsNoError) WithError(err error) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.Method == "OPTIONS" {
+ w.WriteHeader(200)
+ } else {
+ c.Error.WithError(err).ServeHTTP(w, r)
+ }
+ })
+}
diff --git a/main.go b/main.go
index 5895b12..cf7e8a1 100644
--- a/main.go
+++ b/main.go
@@ -3,17 +3,18 @@ package main
import (
"context"
"fmt"
- "git.deuxfleurs.fr/Deuxfleurs/bagage/s3"
- "git.deuxfleurs.fr/Deuxfleurs/bagage/sftp"
- "github.com/minio/minio-go/v7"
- "github.com/minio/minio-go/v7/pkg/credentials"
- "golang.org/x/crypto/ssh"
"io"
"io/ioutil"
"log"
"net"
"net/http"
"os"
+
+ "git.deuxfleurs.fr/Deuxfleurs/bagage/s3"
+ "git.deuxfleurs.fr/Deuxfleurs/bagage/sftp"
+ "github.com/minio/minio-go/v7"
+ "github.com/minio/minio-go/v7/pkg/credentials"
+ "golang.org/x/crypto/ssh"
)
func main() {
@@ -176,17 +177,23 @@ func handleSSHConn(nConn net.Conn, dconfig *Config, config *ssh.ServerConfig) {
func httpServer(config *Config, done chan error) {
// Assemble components to handle WebDAV requests
http.Handle(config.DavPath+"/",
- BasicAuthExtract{
- OnNotFound: NotAuthorized{},
- OnCreds: LdapPreAuth{
- WithConfig: config,
- OnWrongPassword: NotAuthorized{},
- OnFailure: InternalError{},
- OnCreds: S3Auth{
+ CorsAllowAllOrigins{
+ AndThen: BasicAuthExtract{
+ OnNotFound: OptionsNoError{
+ NotAuthorized{},
+ },
+ OnCreds: LdapPreAuth{
WithConfig: config,
- OnFailure: InternalError{},
- OnMinioClient: WebDav{
+ OnWrongPassword: OptionsNoError{
+ Error: NotAuthorized{},
+ },
+ OnFailure: InternalError{},
+ OnCreds: S3Auth{
WithConfig: config,
+ OnFailure: InternalError{},
+ OnMinioClient: WebDav{
+ WithConfig: config,
+ },
},
},
},