ErikMinekus / sm-ripext

SourceMod REST in Pawn Extension
https://forums.alliedmods.net/showthread.php?t=298024
GNU General Public License v3.0
136 stars 38 forks source link

Valid handle with empty baseURL #40

Closed Bara closed 3 years ago

Bara commented 3 years ago

That's not really important, but I think that's worth to mention. With empty base url the returned handle is valid, but if we use this handle with simple Get, it returns status code 0 with empty error message. That's bit confusing while debugging.

Example plugin

#include <sourcemod>
#include <ripext>

public void OnPluginStart()
{
    HTTPClient httpClient = new HTTPClient("");

    PrintToServer("Hande valid: %d", (httpClient != null));

    httpClient.Get("Test", GetCallback);
}

public void GetCallback(HTTPResponse response, any value, const char[] error)
{
    PrintToServer("Status: %d, Error: %s", response.Status, error);
}

Output is

sm plugins load test
Hande valid: 1
Status: 0, Error:
ErikMinekus commented 3 years ago

It looks like libcurl will do this with any invalid URL. As URL validation is complex, I don't think it's worth the time to deal with this.

Bara commented 3 years ago

How about a simple string length check, as example strings with a length of 2 or lower are invalid.

ErikMinekus commented 3 years ago

I think libcurl will happily accept "a", if there is such a hostname. But I will throw an exception when the base URL is empty, that makes sense.

ErikMinekus commented 3 years ago

This was fixed in 6e7dc5a, I plan to release it soon.