PageRenderTime 76ms CodeModel.GetById 44ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/llmessage/llhttpclient.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 162 lines | 81 code | 23 blank | 58 comment | 0 complexity | a9c2136273af730a28b4d52c07073c36 MD5 | raw file
  1/** 
  2 * @file llhttpclient.h
  3 * @brief Declaration of classes for making HTTP client requests.
  4 *
  5 * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLHTTPCLIENT_H
 28#define LL_LLHTTPCLIENT_H
 29
 30/**
 31 * These classes represent the HTTP client framework.
 32 */
 33
 34#include <string>
 35
 36#include <boost/intrusive_ptr.hpp>
 37#include <openssl/x509_vfy.h>
 38#include "llurlrequest.h"
 39#include "llassettype.h"
 40#include "llcurl.h"
 41#include "lliopipe.h"
 42
 43extern const F32 HTTP_REQUEST_EXPIRY_SECS;
 44
 45class LLUUID;
 46class LLPumpIO;
 47class LLSD;
 48
 49
 50class LLHTTPClient
 51{
 52public:
 53	// class Responder moved to LLCurl
 54
 55	// For convenience
 56	typedef LLCurl::Responder Responder;
 57	typedef LLCurl::ResponderPtr ResponderPtr;
 58
 59	
 60	/** @name non-blocking API */
 61	//@{
 62	static void head(
 63		const std::string& url,
 64		ResponderPtr,
 65		const LLSD& headers = LLSD(),
 66		const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
 67	static void getByteRange(const std::string& url, S32 offset, S32 bytes, ResponderPtr, const LLSD& headers=LLSD(), const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
 68	static void get(const std::string& url, ResponderPtr, const LLSD& headers = LLSD(), const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
 69	static void get(const std::string& url, const LLSD& query, ResponderPtr, const LLSD& headers = LLSD(), const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
 70
 71	static void put(
 72		const std::string& url,
 73		const LLSD& body,
 74		ResponderPtr,
 75		const LLSD& headers = LLSD(),
 76		const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
 77	static void getHeaderOnly(const std::string& url, ResponderPtr, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
 78	static void getHeaderOnly(const std::string& url, ResponderPtr, const LLSD& headers, const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
 79
 80	static void post(
 81		const std::string& url,
 82		const LLSD& body,
 83		ResponderPtr,
 84		const LLSD& headers = LLSD(),
 85		const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
 86	/** Takes ownership of data and deletes it when sent */
 87	static void postRaw(
 88		const std::string& url,
 89		const U8* data,
 90		S32 size,
 91		ResponderPtr responder,
 92		const LLSD& headers = LLSD(),
 93		const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
 94	static void postFile(
 95		const std::string& url,
 96		const std::string& filename,
 97		ResponderPtr,
 98		const LLSD& headers = LLSD(),
 99		const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
100	static void postFile(
101		const std::string& url,
102		const LLUUID& uuid,
103		LLAssetType::EType asset_type,
104		ResponderPtr responder,
105		const LLSD& headers = LLSD(),
106		const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
107
108	static void del(
109		const std::string& url,
110		ResponderPtr responder,
111		const LLSD& headers = LLSD(),
112		const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
113		///< sends a DELETE method, but we can't call it delete in c++
114	
115	/**
116	 * @brief Send a MOVE webdav method
117	 *
118	 * @param url The complete serialized (and escaped) url to get.
119	 * @param destination The complete serialized destination url.
120	 * @param responder The responder that will handle the result.
121	 * @param headers A map of key:value headers to pass to the request
122	 * @param timeout The number of seconds to give the server to respond.
123	 */
124	static void move(
125		const std::string& url,
126		const std::string& destination,
127		ResponderPtr responder,
128		const LLSD& headers = LLSD(),
129		const F32 timeout=HTTP_REQUEST_EXPIRY_SECS);
130
131	//@}
132
133	/**
134	 * @brief Blocking HTTP get that returns an LLSD map of status and body.
135	 *
136	 * @param url the complete serialized (and escaped) url to get
137	 * @return An LLSD of { 'status':status, 'body':payload }
138	 */
139	static LLSD blockingGet(const std::string& url);
140
141	/**
142	 * @brief Blocking HTTP POST that returns an LLSD map of status and body.
143	 *
144	 * @param url the complete serialized (and escaped) url to get
145	 * @param body the LLSD post body
146	 * @return An LLSD of { 'status':status (an int), 'body':payload (an LLSD) }
147	 */
148	static LLSD blockingPost(const std::string& url, const LLSD& body);
149
150	
151	static void setPump(LLPumpIO& pump);
152		///< must be called before any of the above calls are made
153	static bool hasPump();
154
155	static void setCertVerifyCallback(LLURLRequest::SSLCertVerifyCallback callback);
156	static  LLURLRequest::SSLCertVerifyCallback getCertVerifyCallback() { return mCertVerifyCallback; }
157
158protected:
159	static LLURLRequest::SSLCertVerifyCallback mCertVerifyCallback;
160};
161
162#endif // LL_LLHTTPCLIENT_H