File tree Expand file tree Collapse file tree 3 files changed +33
-10
lines changed Expand file tree Collapse file tree 3 files changed +33
-10
lines changed Original file line number Diff line number Diff line change @@ -167,7 +167,7 @@ def update(
167
167
168
168
headers = {
169
169
"Accept" : _response_mime_types [self .returnFormat ],
170
- "Content-Type" : "application/sparql-update" ,
170
+ "Content-Type" : "application/sparql-update; charset=UTF-8 " ,
171
171
}
172
172
173
173
args = dict (self .kwargs ) # other QSAs
Original file line number Diff line number Diff line change
1
+ import logging
1
2
import re
2
3
import socket
3
4
from http .server import BaseHTTPRequestHandler , HTTPServer
@@ -457,23 +458,22 @@ def do_POST(self):
457
458
print(body)
458
459
```
459
460
"""
460
- contenttype = self .headers .get ("Content-Type" )
461
+ contenttype = [
462
+ part .strip () for part in f"{ self .headers .get ('Content-Type' )} " .split (";" )
463
+ ]
464
+ logging .debug ("contenttype = %s" , contenttype )
461
465
if self .path == "/query" or self .path == "/query?" :
462
- if self . headers . get ( "Content-Type" ) == " application/sparql-query" :
466
+ if " application/sparql-query" in contenttype :
463
467
pass
464
- elif (
465
- self .headers .get ("Content-Type" ) == "application/x-www-form-urlencoded"
466
- ):
468
+ elif "application/x-www-form-urlencoded" in contenttype :
467
469
pass
468
470
else :
469
471
self .send_response (406 , "Not Acceptable" )
470
472
self .end_headers ()
471
473
elif self .path == "/update" or self .path == "/update?" :
472
- if self . headers . get ( "Content-Type" ) == " application/sparql-update" :
474
+ if " application/sparql-update" in contenttype :
473
475
pass
474
- elif (
475
- self .headers .get ("Content-Type" ) == "application/x-www-form-urlencoded"
476
- ):
476
+ elif "application/x-www-form-urlencoded" in contenttype :
477
477
pass
478
478
else :
479
479
self .send_response (406 , "Not Acceptable" )
Original file line number Diff line number Diff line change @@ -58,3 +58,26 @@ def test_graph_update(self):
58
58
req = self .httpmock .requests [MethodName .POST ].pop (0 )
59
59
assert req .parsed_path .path == self .update_path
60
60
assert "application/sparql-update" in req .headers .get ("content-type" )
61
+
62
+ def test_update_encoding (self ):
63
+ graph = ConjunctiveGraph ("SPARQLUpdateStore" )
64
+ graph .open ((self .query_endpoint , self .update_endpoint ))
65
+ update_statement = f"INSERT DATA {{ { EG ['subj' ]} { EG ['pred' ]} { EG ['obj' ]} . }}"
66
+
67
+ self .httpmock .responses [MethodName .POST ].append (
68
+ MockHTTPResponse (
69
+ 200 ,
70
+ "OK" ,
71
+ b"Update succeeded" ,
72
+ {"Content-Type" : ["text/plain; charset=UTF-8" ]},
73
+ )
74
+ )
75
+
76
+ # This test assumes that updates are performed using POST
77
+ # at the moment this is the only supported way for SPARQLUpdateStore
78
+ # to do updates.
79
+ graph .update (update_statement )
80
+ assert self .httpmock .call_count == 1
81
+ req = self .httpmock .requests [MethodName .POST ].pop (0 )
82
+ assert req .parsed_path .path == self .update_path
83
+ assert "charset=UTF-8" in req .headers .get ("content-type" )
You can’t perform that action at this time.
0 commit comments