Skip to content

A little problem with URL parsing #13

@cold01water

Description

@cold01water

In the code below, the path of the URL is processed with rtrim and ltrim.

This process trims the "?" at the end, but it cannot be processed when parameters are included, such as /_bulk?timeout=60s.

  • src/Network/Request.php
    protected function parseOrFail(array $payload): static {
        static::validateInputFields($payload, static::PAYLOAD_FIELDS);

        // Checking if request format and endpoint are supported
        $this->path = rtrim(ltrim($payload['message']['path_query'], '/'), '?');    # here!

I understand that it currently evaluates endpoints containing parameters such as "sql?mode=raw".
I don't think this implementation is clean.

In the first place, PHP has a parse_url() function, so it may be easier to implement using that function.
And I think it's better to evaluate paths and parameters separately. Also in the future.

$origin = "/_bulk?timeout=60s";
$pathInfo =  parse_url($origin);
var_dump($pathInfo);

# array(2) {
#  ["path"]=>
#  string(6) "/_bulk"
#  ["query"]=>
#  string(11) "timeout=60s"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions