Raised This Month: $12 Target: $400
 3% 

Module: Threaded HTTP


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 07-08-2012 , 21:49   Module: Threaded HTTP
Reply With Quote #1

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
}
Attached Files
File Type: inc thttp.inc (2.2 KB, 393 views)
File Type: zip thttp.zip (53.1 KB, 341 views)
File Type: so thttp_amxx_i386.so (106.4 KB, 340 views)
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 07-08-2012 , 23:27   Re: Module: Threaded HTTP
Reply With Quote #2

You finally released it good job man
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Neeeeeeeeeel.-
Some Guy Yellin'
Join Date: Jul 2010
Location: Argentina
Old 07-09-2012 , 00:31   Re: Module: Threaded HTTP
Reply With Quote #3

Interesting :O I will use it (When someone compile it to Windows ).
GJ.
__________________
Neeeeeeeeeel.- is offline
Send a message via Skype™ to Neeeeeeeeeel.-
rak
Veteran Member
Join Date: Oct 2011
Location: banned country
Old 07-10-2012 , 21:47   Re: Module: Threaded HTTP
Reply With Quote #4

good job
__________________

www.amxmodx-es.com

Steam: Luchokoldo
rak is offline
Send a message via MSN to rak Send a message via Skype™ to rak
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-11-2012 , 03:40   Re: Module: Threaded HTTP
Reply With Quote #5

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.
Attached Files
File Type: dll thttp_amxx.dll (116.5 KB, 294 views)
__________________

Last edited by Arkshine; 07-11-2012 at 11:47.
Arkshine is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 07-11-2012 , 04:59   Re: Module: Threaded HTTP
Reply With Quote #6

Would be cool if you could set custom user-agent.

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

Last edited by xPaw; 07-11-2012 at 04:59.
xPaw is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 07-11-2012 , 12:29   Re: Module: Threaded HTTP
Reply With Quote #7

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

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
ConorCC
Member
Join Date: Feb 2014
Old 05-02-2021 , 14:06   Re: Module: Threaded HTTP
Reply With Quote #8

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.
ConorCC is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:48.


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