From 0b0336946b583df0f355869240d929e91516b2fa Mon Sep 17 00:00:00 2001 From: reluc Date: Tue, 10 Apr 2018 16:44:53 +0200 Subject: [PATCH] Fix Contet-type handling int POST method Content-Type header can have parameters like charset i.e: Content-Type: text/html; charset=utf-8 **Note**: header.getValue() **returns** "text/html; charset=utf-8" --- .../engine/protocol/http/handler/UpdateHandler.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/engine/src/main/java/it/unibo/arces/wot/sepa/engine/protocol/http/handler/UpdateHandler.java b/engine/src/main/java/it/unibo/arces/wot/sepa/engine/protocol/http/handler/UpdateHandler.java index f330d495..93f322e7 100644 --- a/engine/src/main/java/it/unibo/arces/wot/sepa/engine/protocol/http/handler/UpdateHandler.java +++ b/engine/src/main/java/it/unibo/arces/wot/sepa/engine/protocol/http/handler/UpdateHandler.java @@ -68,11 +68,17 @@ protected Request parse(HttpAsyncExchange exchange) { throw new SPARQL11ProtocolException(HttpStatus.SC_BAD_REQUEST, "Content-Type is missing"); } - if (headers[0].getValue().equals("application/sparql-update")) { + // Content-Type header can have parameters like charset + // i.e: Content-Type: text/html; charset=utf-8 + // Note: header.getValue() returns text/html; charset=utf-8 + // TODO: handle charset + String contentType = headers[0].getElements()[0].getName(); + + if (contentType.equals("application/sparql-update")) { logger.debug("update via POST directly"); return new UpdateRequest(body); - } else if (headers[0].getValue().equals("application/x-www-form-urlencoded")) { + } else if (contentType.equals("application/x-www-form-urlencoded")) { try { Map params = HttpUtilities.splitQuery(body);