--[[
	MOD/addons/SenHack v1/lua/client/libs/glib/http.lua [#2290 (#2290), 2541271336, UID:269560691]
	(ARP)konrad50024 | STEAM_0:0:36097632 <92.234.95.154:27005> | [11.05.14 04:00:13PM]
	===BadFile===
]]

/* * * * * * * * * * * * * * * * 
 * 	 ______     __  __     ______     __  __     ______     ______     __  __    
 *	/\  __ \   /\ \/\ \   /\  == \   /\ \_\ \   /\  __ \   /\  ___\   /\ \/ /    
 *	\ \ \/\ \  \ \ \_\ \  \ \  __<   \ \  __ \  \ \  __ \  \ \ \____  \ \  _"-.  
 *	 \ \_____\  \ \_____\  \ \_____\  \ \_\ \_\  \ \_\ \_\  \ \_____\  \ \_\ \_\ 
 *	  \/_____/   \/_____/   \/_____/   \/_/\/_/   \/_/\/_/   \/_____/   \/_/\/_/ 
 *
 *  - Version : 3L
 *  - By Oubliette
 * * * * * * * * * * * * * * * */

--
local arg = { ... };
local g = arg[ 1 ];
--

local http = g.table.Copy( http or {} );

--[[---------------------------------------------------------
	HTTP Module. Interaction with HTTP.
-----------------------------------------------------------]]

--[[---------------------------------------------------------

	Get the contents of a webpage.
	
	Callback should be 
	
	function callback( (args optional), contents, size )
	
-----------------------------------------------------------]]
function http.Fetch( url, onsuccess, onfailure )

	local request = 
	{
		url			= url,
		method		= "get",

		success		= function( code, body, headers )
	
			if ( !onsuccess ) then return end

			onsuccess( body, body:len(), headers, code )

		end,

		failed		= function( err )

			if ( !onfailure ) then return end

			onfailure( err )

		end
	}

	HTTP( request )

end


function http.Post( url, params, onsuccess, onfailure )

	local request = 
	{
		url			= url,
		method		= "post",
		parameters	= params,

		success		= function( code, body, headers )
	
			if ( !onsuccess ) then return end

			onsuccess( body, body:len(), headers, code )

		end,

		failed		= function( err )

			if ( !onfailure ) then return end

			onfailure( err )

		end
	}

	HTTP( request )

end

--[[

Or use HTTP( table )

local request = 
{
	url			= "http://pastebin.com/raw.php?i=3jsf50nL",

	method		= "post",

	parameters  = 
	{
			id			=	"548",
			country		=	"England"
	}

	success		= function( code, body, headers )
	
		Msg( "Request Successful\n" )
		Msg( "Code: ", code, "\n" )
		Msg( "Body Length:\n", body:len(), "\n" )
		Msg( "Body:\n", body, "\n" )
		PrintTable( headers )

	end,

	failed		= function( reason )
		Msg( "Request failed: ", reason, "\n" )
	end
}

HTTP( request )

---]]

return http;