Skip to content

Commit 9566844

Browse files
committed
feat: pass through mu headers for sparql queries
1 parent e79b740 commit 9566844

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

helpers.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import os
55
import sys
6-
from flask import jsonify
6+
from flask import jsonify, request
77
from rdflib.namespace import DC
88
from escape_helpers import sparql_escape
99
from SPARQLWrapper import SPARQLWrapper, JSON
@@ -85,17 +85,29 @@ def validate_resource_type(expected_type, data):
8585
sparqlQuery.setTimeout(timeout)
8686
sparqlUpdate.setTimeout(timeout)
8787

88+
MU_HEADERS = [
89+
"HTTP_MU_CALL_ID",
90+
"HTTP_MU_AUTH_ALLOWED_GROUPS",
91+
"HTTP_MU_AUTH_USED_GROUPS"
92+
]
93+
8894
def query(the_query):
8995
"""Execute the given SPARQL query (select/ask/construct)on the tripple store and returns the results
9096
in the given returnFormat (JSON by default)."""
9197
log("execute query: \n" + the_query)
98+
sparqlQuery.customHttpHeaders["HTTP_MU_SESSION_ID"] = session_id_header(request)
99+
for header in MU_HEADERS:
100+
sparqlQuery.customHttpHeaders[header] = request.headers.get(header)
92101
sparqlQuery.setQuery(the_query)
93102
return sparqlQuery.query().convert()
94103

95104

96105
def update(the_query):
97106
"""Execute the given update SPARQL query on the tripple store,
98107
if the given query is no update query, nothing happens."""
108+
sparqlQuery.customHttpHeaders["HTTP_MU_SESSION_ID"] = session_id_header(request)
109+
for header in MU_HEADERS:
110+
sparqlQuery.customHttpHeaders[header] = request.headers.get(header)
99111
sparqlUpdate.setQuery(the_query)
100112
if sparqlUpdate.isSparqlUpdateRequest():
101113
sparqlUpdate.query()

0 commit comments

Comments
 (0)