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(
167167
168168 headers = {
169169 "Accept" : _response_mime_types [self .returnFormat ],
170- "Content-Type" : "application/sparql-update" ,
170+ "Content-Type" : "application/sparql-update; charset=UTF-8 " ,
171171 }
172172
173173 args = dict (self .kwargs ) # other QSAs
Original file line number Diff line number Diff line change 1+ import logging
12import re
23import socket
34from http .server import BaseHTTPRequestHandler , HTTPServer
@@ -457,23 +458,22 @@ def do_POST(self):
457458 print(body)
458459 ```
459460 """
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 )
461465 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 :
463467 pass
464- elif (
465- self .headers .get ("Content-Type" ) == "application/x-www-form-urlencoded"
466- ):
468+ elif "application/x-www-form-urlencoded" in contenttype :
467469 pass
468470 else :
469471 self .send_response (406 , "Not Acceptable" )
470472 self .end_headers ()
471473 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 :
473475 pass
474- elif (
475- self .headers .get ("Content-Type" ) == "application/x-www-form-urlencoded"
476- ):
476+ elif "application/x-www-form-urlencoded" in contenttype :
477477 pass
478478 else :
479479 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):
5858 req = self .httpmock .requests [MethodName .POST ].pop (0 )
5959 assert req .parsed_path .path == self .update_path
6060 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