Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A little problem with URL parsing #13

Open
cold01water opened this issue Jun 14, 2023 · 0 comments
Open

A little problem with URL parsing #13

cold01water opened this issue Jun 14, 2023 · 0 comments

Comments

@cold01water
Copy link

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"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant