AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   Module: Threaded HTTP (https://forums.alliedmods.net/showthread.php?t=189598)

joropito 07-08-2012 21:49

Module: Threaded HTTP
 
3 Attachment(s)
This module implements an HTTP client in a threaded mode.

What is threaded?

To avoid process blocking, this technique sends the request and wait for response in asynchronous way.

At each StartFrame of hlds server, it checks if there's some pending request and in that case it checks for data in buffer.

It's implemented using a free library HappyHTTP.


How to use it?

From the plugin, call the native: thttp_request

Wait for the forward to be called: thttp_response

Just that.

Example plugin:

Code:

#include <amxmodx>
#include <thttp>

public plugin_init()
{
        register_concmd("httpget", "httpget")
}

public thttp_response(key[], data[], code, reason[])
{
        log_amx("HTTP: key:%s code:%i reason:%s data:%s\n", key, code, reason, data);
}

public httpget(id)
{
        thttp_request("thisisthekey", "www.google.com", "GET", "/search?q=alliedmods");
        return PLUGIN_HANDLED
}

public xxx(id)
{
        thttp_request("pepepe", "www.google.com", "GET", "/search?q=test");
        return PLUGIN_HANDLED
}


meTaLiCroSS 07-08-2012 23:27

Re: Module: Threaded HTTP
 
You finally released it :) good job man

Neeeeeeeeeel.- 07-09-2012 00:31

Re: Module: Threaded HTTP
 
Interesting :O I will use it:twisted: (When someone compile it to Windows :cry:).
GJ.

rak 07-10-2012 21:47

Re: Module: Threaded HTTP
 
good job :3

Arkshine 07-11-2012 03:40

Re: Module: Threaded HTTP
 
1 Attachment(s)
Try that.

@joropito :

You don't include autoload in the .inc file.
I've tried the .dll, and is it normal when you throw the command, it does not show always the result ? It seems to be shown randomly. Like I can use 4 times the command, nothing happens, then the 5th, it answers. If I try again, it appears. And the next time, not. etc.

xPaw 07-11-2012 04:59

Re: Module: Threaded HTTP
 
Would be cool if you could set custom user-agent.

Perhaps thttp_request("thisisthekey", "this is custom useragent for this key");

joropito 07-11-2012 12:29

Re: Module: Threaded HTTP
 
HappyHTTP (the library used) can send headers.
Here I just implemented a direct request. Of course more functions could, should and would be added :)

ConorCC 05-02-2021 14:06

Re: Module: Threaded HTTP
 
I have tried to use the compiled binary but it dosn't work. After thttp_request is called the response is never received or the forward is never called. Idk. Since I'm not clever enough maybe the reason is same as using socket for https. If not and someone can fix this would be nice to see with custom header option. :)


All times are GMT -4. The time now is 22:47.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.