Code Monkey home page Code Monkey logo

Comments (5)

frmichel avatar frmichel commented on July 26, 2024

Hi Christian, good one. I did not know it is possible to pass this charset within the Content-Type header.
So clearly this is a bug, easily identifiable in module frmichel/sparqlms/commonUtils.php, function getSparqlQuery().

If you want a quick and dirty fix, you can connect to the container and change the code in /sparql-micro-service/src/common/Utils.php. But of course this will be lost every time you restart the container. At least you'll know if that fixes the pb.

Here is the new code of the function. I've written it quickly but did not test it... so it may not work straight away. It replaces the internal switch with an if-then-else using str_contains.

    static public function getSparqlQuery()
    {
        $method = $_SERVER['REQUEST_METHOD'];
        switch ($method) {
            case 'GET':
                {
                    if (array_key_exists('query', $_GET))
                        $sparqlQuery = $_GET['query'];
                    else
                        self::httpBadRequest("SPARQL query with HTTP GET method but no 'query' argument.");
                    break;
                }
            case 'POST':
                {
                    if (array_key_exists('CONTENT_TYPE', $_SERVER))
                        $contentType = $_SERVER['CONTENT_TYPE'];
                    else
                        self::httpBadRequest("SPARQL query with HTTP POST method but no 'Content-Type' header.");

                    if (str_contains($contentType, 'application/x-www-form-urlencoded')) {
                        if (array_key_exists('query', $_POST))
                            $sparqlQuery = $_POST['query'];
                            else
                                self::httpBadRequest("SPARQL query with HTTP POST method and Content-Type' application/x-www-form-urlencoded' but no 'query' argument.");
                                break;
                    } else if (str_contains($contentType, 'application/sparql-query')) {
                        $sparqlQuery = file_get_contents('php://input');
                        break;
                    } else
                        self::httpBadRequest("SPARQL query with HTTP POST method but unexpected 'Content-Type': " . $contentType);
                    break;
                }
            default:
                self::httpMethodNotAllowed("Unsupported HTTP method " . $method);
        }
        return $sparqlQuery;
    }

I'll need a bit more time to test it, commit and publish a new version of the Docker image. I guess you have already produced your own version of the Docker image so you may put this change into it.

I'm pretty busy these coming days and weeks, I'll try to find a moment to do that. Meanwhile, if you try that let me know if that works.

from sparql-micro-service.

kleegrewec avatar kleegrewec commented on July 26, 2024

from sparql-micro-service.

kleegrewec avatar kleegrewec commented on July 26, 2024

Hi Frank

The solution you provided solved the problem. Thanks for your help,

Christian

from sparql-micro-service.

frmichel avatar frmichel commented on July 26, 2024

Ok great, thx for the hint. I've still not taken time to test it further and commit it and all. I let you know when the image is updated.

from sparql-micro-service.

frmichel avatar frmichel commented on July 26, 2024

Hi @kleegrewec, just to let you know, I've commited the fix and published a new release + updated Docker image v0.5.4.

from sparql-micro-service.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.