all repos — litestore @ 7faab62a50c4a56040471b354fca6918fd96d5ed

A minimalist nosql document store.

Closes #48.
h3rald h3rald@h3rald.com
Sun, 13 Jan 2019 10:41:23 +0100
commit

7faab62a50c4a56040471b354fca6918fd96d5ed

parent

d6c39a88febc46d14c833ce9063b42cc34f860d4

2 files changed, 20 insertions(+), 16 deletions(-)

jump to
M src/litestorepkg/lib/api_v4.nimsrc/litestorepkg/lib/api_v4.nim

@@ -586,21 +586,24 @@ result.content = ""

result.headers = newHttpHeaders(TAB_HEADERS) setOrigin(LS, req, result.headers) result.headers["Allow"] = "GET,OPTIONS" - result.headers["Access-Control-Allow-Methods"] = "GET,OPTIONS" + result.headers["Access-Control-Allow-Methods"] = "GET, OPTIONS" + result.headers["Access-Control-Allow-Headers"] = "Content-Type, Authorization" of "dir": result.code = Http200 result.content = "" result.headers = newHttpHeaders(TAB_HEADERS) setOrigin(LS, req, result.headers) result.headers["Allow"] = "GET,OPTIONS" - result.headers["Access-Control-Allow-Methods"] = "GET,OPTIONS" + result.headers["Access-Control-Allow-Methods"] = "GET, OPTIONS" + result.headers["Access-Control-Allow-Headers"] = "Content-Type, Authorization" of "tags": result.code = Http200 result.content = "" result.headers = newHttpHeaders(TAB_HEADERS) setOrigin(LS, req, result.headers) result.headers["Allow"] = "GET,OPTIONS" - result.headers["Access-Control-Allow-Methods"] = "GET,OPTIONS" + result.headers["Access-Control-Allow-Methods"] = "GET, OPTIONS" + result.headers["Access-Control-Allow-Headers"] = "Content-Type, Authorization" of "docs": var folder: string if id.isFolder:

@@ -612,12 +615,12 @@ if LS.readonly:

result.headers = newHttpHeaders(TAB_HEADERS) setOrigin(LS, req, result.headers) result.headers["Allow"] = "HEAD,GET,OPTIONS" - result.headers["Access-Control-Allow-Methods"] = "HEAD,GET,OPTIONS" + result.headers["Access-Control-Allow-Methods"] = "HEAD, GET, OPTIONS" else: result.headers = newHttpHeaders(TAB_HEADERS) setOrigin(LS, req, result.headers) result.headers["Allow"] = "HEAD,GET,OPTIONS,POST,PUT" - result.headers["Access-Control-Allow-Methods"] = "HEAD,GET,OPTIONS,POST,PUT" + result.headers["Access-Control-Allow-Methods"] = "HEAD, GET, OPTIONS, POST, PUT" elif id != "": result.code = Http200 result.content = ""

@@ -625,13 +628,13 @@ if LS.readonly:

result.headers = newHttpHeaders(TAB_HEADERS) setOrigin(LS, req, result.headers) result.headers["Allow"] = "HEAD,GET,OPTIONS" - result.headers["Access-Control-Allow-Methods"] = "HEAD,GET,OPTIONS" + result.headers["Access-Control-Allow-Methods"] = "HEAD, GET, OPTIONS" else: result.headers = newHttpHeaders(TAB_HEADERS) setOrigin(LS, req, result.headers) result.headers["Allow"] = "HEAD,GET,OPTIONS,PUT,PATCH,DELETE" result.headers["Allow-Patch"] = "application/json-patch+json" - result.headers["Access-Control-Allow-Methods"] = "HEAD,GET,OPTIONS,PUT,PATCH,DELETE" + result.headers["Access-Control-Allow-Methods"] = "HEAD, GET, OPTIONS, PUT, PATCH, DELETE" else: result.code = Http200 result.content = ""

@@ -639,12 +642,13 @@ if LS.readonly:

result.headers = newHttpHeaders(TAB_HEADERS) setOrigin(LS, req, result.headers) result.headers["Allow"] = "HEAD,GET,OPTIONS" - result.headers["Access-Control-Allow-Methods"] = "HEAD,GET,OPTIONS" + result.headers["Access-Control-Allow-Methods"] = "HEAD, GET, OPTIONS" else: result.headers = newHttpHeaders(TAB_HEADERS) setOrigin(LS, req, result.headers) result.headers["Allow"] = "HEAD,GET,OPTIONS,POST" - result.headers["Access-Control-Allow-Methods"] = "HEAD,GET,OPTIONS,POST" + result.headers["Access-Control-Allow-Methods"] = "HEAD, GET, OPTIONS, POST" + result.headers["Access-Control-Allow-Headers"] = "Content-Type, Authorization" else: discard # never happens really.
M src/litestorepkg/lib/utils.nimsrc/litestorepkg/lib/utils.nim

@@ -23,19 +23,19 @@ var protocol = "http"

if req.url.hostname != "" and req.url.port != "": host = req.url.hostname port = req.url.port - elif req.headers.hasKey("Host"): - var parts = req.headers["Host"].split(":") + elif req.headers.hasKey("origin"): + let parts = req.headers["origin"].split("://") + protocol = parts[0] + let server = parts[1].split(":") if (parts.len >= 2): - host = parts[0] - port = parts[1] + host = server[0] + port = server[1] else: - host = parts[0] + host = server[0] port = "80" else: headers["Access-Control-Allow-Origin"] = "*" return - if req.url.scheme != "": - protocol = req.url.scheme headers["Vary"] = "Origin" headers["Access-Control-Allow-Origin"] = "$1://$2:$3" % [protocol, host, port]