[lxc-devel] [lxd/master] #1705: Feature: Add headers CORS for use with web app

aarnaud on Github lxc-bot at linuxcontainers.org
Sun Mar 6 23:26:55 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160306/8aa8d34e/attachment.bin>
-------------- next part --------------
From 3d46c67d85c659633c38bc22ee90cf0a717036e3 Mon Sep 17 00:00:00 2001
From: Anthony ARNAUD <perso at anthony-arnaud.fr>
Date: Mon, 7 Mar 2016 00:12:20 +0100
Subject: [PATCH] #1705: Feature: Add headers CORS for use with web app

---
 lxd/daemon.go | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/lxd/daemon.go b/lxd/daemon.go
index 83a3686..caa0963 100644
--- a/lxd/daemon.go
+++ b/lxd/daemon.go
@@ -1134,6 +1134,10 @@ func (d *Daemon) ConfigKeyIsValid(key string) bool {
 		return true
 	case "core.https_allowed_origin":
 		return true
+	case "core.https_allowed_methods":
+		return true
+	case "core.https_allowed_headers":
+		return true
 	case "core.trust_password":
 		return true
 	case "storage.lvm_vg_name":
@@ -1283,6 +1287,16 @@ func (s *lxdHttpServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
 		rw.Header().Set("Access-Control-Allow-Origin", allowedOrigin)
 	}
 
+	allowedMethods, _ := s.d.ConfigValueGet("core.https_allowed_methods")
+	if allowedMethods != "" && origin != "" {
+		rw.Header().Set("Access-Control-Allow-Methods", allowedMethods)
+	}
+
+	allowedHeaders, _ := s.d.ConfigValueGet("core.https_allowed_headers")
+	if allowedHeaders != "" && origin != "" {
+		rw.Header().Set("Access-Control-Allow-Headers", allowedHeaders)
+	}
+
 	// OPTIONS request don't need any further processing
 	if req.Method == "OPTIONS" {
 		return


More information about the lxc-devel mailing list