From f945415210f0e18c2c6d941fda6b7d45cb0f06f1 Mon Sep 17 00:00:00 2001 From: Don Kjer Date: Wed, 13 Mar 2013 06:26:25 +0000 Subject: Large changes to the LLCurl::Responder API, as well as pulling in some changes to common libraries from the server codebase: * Additional error checking in http handlers. * Uniform log spam for http errors. * Switch to using constants for http heads and status codes. * Fixed bugs in incorrectly checking if parsing LLSD xml resulted in an error. * Reduced spam regarding LLSD parsing errors in the default completedRaw http handler. It should not longer be necessary to short-circuit completedRaw to avoid spam. * Ported over a few bug fixes from the server code. * Switch mode http status codes to use S32 instead of U32. * Ported LLSD::asStringRef from server code; avoids copying strings all over the place. * Ported server change to LLSD::asBinary; this always returns a reference now instead of copying the entire binary blob. * Ported server pretty notation format (and pretty binary format) to llsd serialization. * The new LLCurl::Responder API no longer has two error handlers to choose from. Overriding the following methods have been deprecated: ** error - use httpFailure ** errorWithContent - use httpFailure ** result - use httpSuccess ** completed - use httpCompleted ** completedHeader - no longer necessary; call getResponseHeaders() from a completion method to obtain these headers. * In order to 'catch' a completed http request, override one of these methods: ** httpSuccess - Called for any 2xx status code. ** httpFailure - Called for any non-2xx status code. ** httpComplete - Called for all status codes. Default implementation is to call either httpSuccess or httpFailure. * It is recommended to keep these methods protected/private in order to avoid triggering of these methods without using a 'push' method (see below). * Uniform error handling should followed whenever possible by calling a variant of this during httpFailure: ** llwarns << dumpResponse() << llendl; * Be sure to include LOG_CLASS(your_class_name) in your class in order for the log entry to give more context. * In order to 'push' a result into the responder, you should no longer call error, errorWithContent, result, or completed. * Nor should you directly call httpSuccess/Failure/Completed (unless passing a message up to a parent class). * Instead, you can set the internal content of a responder and trigger a corresponding method using the following methods: ** successResult - Sets results and calls httpSuccess ** failureResult - Sets results and calls httpFailure ** completedResult - Sets results and calls httpCompleted * To obtain information about a the response from a reponder method, use the following getters: ** getStatus - HTTP status code ** getReason - Reason string ** getContent - Content (Parsed body LLSD) ** getResponseHeaders - Response Headers (LLSD map) ** getHTTPMethod - HTTP method of the request ** getURL - URL of the request * It is still possible to override completeRaw if you want to manipulate data directly out of LLPumpIO. * See indra/llmessage/llcurl.h for more information. --- indra/llmessage/llcurl.h | 112 +++++++++++++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 38 deletions(-) (limited to 'indra/llmessage/llcurl.h') diff --git a/indra/llmessage/llcurl.h b/indra/llmessage/llcurl.h index 7bcf61e233..c72e1e493a 100644 --- a/indra/llmessage/llcurl.h +++ b/indra/llmessage/llcurl.h @@ -39,6 +39,7 @@ #include // TODO: remove dependency #include "llbuffer.h" +#include "llhttpconstants.h" #include "lliopipe.h" #include "llsd.h" #include "llthread.h" @@ -77,59 +78,92 @@ public: Responder(); virtual ~Responder(); - /** - * @brief return true if the status code indicates success. - */ - static bool isGoodStatus(U32 status) + virtual bool followRedir() { - return((200 <= status) && (status < 300)); + return false; } - - virtual void errorWithContent( - U32 status, - const std::string& reason, - const LLSD& content); - //< called by completed() on bad status - - virtual void error(U32 status, const std::string& reason); - //< called by default error(status, reason, content) - - virtual void result(const LLSD& content); - //< called by completed for good status codes. + /** + * @brief return true if the status code indicates success. + */ + bool isGoodStatus() const { return isHttpGoodStatus(mStatus); } + + S32 getStatus() const { return mStatus; } + const std::string& getReason() const { return mReason; } + const LLSD& getContent() const { return mContent; } + bool hasResponseHeader(const std::string& header, bool check_lower=false) const; + const std::string& getResponseHeader(const std::string& header, bool check_lower=true) const; + const LLSD& getResponseHeaders() const { return mResponseHeaders; } + const std::string& getURL() const { return mURL; } + EHTTPMethod getHTTPMethod() const { return mHTTPMethod; } + + // This formats response information for use in log spam. Includes content spam. + std::string dumpResponse() const; + + // Allows direct triggering of success/error with different results. + void completeResult(S32 status, const std::string& reason, const LLSD& content = LLSD()); + void successResult(const LLSD& content); + void failureResult(S32 status, const std::string& reason, const LLSD& content = LLSD()); + + // The default implementation will try to parse body content as an LLSD, however + // it should not spam about parsing failures unless the server sent a + // Content-Type: application/llsd+xml header. virtual void completedRaw( - U32 status, - const std::string& reason, const LLChannelDescriptors& channels, const LLIOPipe::buffer_ptr_t& buffer); /**< Override point for clients that may want to use this class when the response is some other format besides LLSD */ + - virtual void completed( - U32 status, - const std::string& reason, - const LLSD& content); - /**< The default implemetnation calls + // The http* methods are not public since these should be triggered internally + // after status, reason, content, etc have been set. + // If you need to trigger a completion method, use the *Result methods, above. + protected: + // These methods are the preferred way to process final results. + // By default, when one of these is called the following information will be resolved: + // * HTTP status code - getStatus() + // * Reason string - getReason() + // * Content - getContent() + // * Response Headers - getResponseHeaders() + + // By default, httpSuccess is triggered whenever httpCompleted is called with a 2xx status code. + virtual void httpSuccess(); + //< called by completed for good status codes. + + // By default, httpFailure is triggered whenever httpCompleted is called with a non-2xx status code. + virtual void httpFailure(); + //< called by httpCompleted() on bad status + + // httpCompleted does not generally need to be overridden, unless + // you don't care about the status code (which determine httpFailure or httpSuccess) + // or if you want to re-interpret what a 'good' vs' bad' status code is. + virtual void httpCompleted(); + /**< The default implementation calls either: - * result(), or - * error() + * httpSuccess(), or + * httpFailure() */ - - // Override to handle parsing of the header only. Note: this is the only place where the contents - // of the header can be parsed. In the ::completed call above only the body is contained in the LLSD. - virtual void completedHeader(U32 status, const std::string& reason, const LLSD& content); - - // Used internally to set the url for debugging later. - void setURL(const std::string& url); - virtual bool followRedir() - { - return false; - } + public: + void setHTTPMethod(EHTTPMethod method); + void setURL(const std::string& url); + void setResult(S32 status, const std::string& reason, const LLSD& content = LLSD()); + void setResponseHeader(const std::string& header, const std::string& value); private: + // These can be accessed by the get* methods. Treated as 'read-only' during completion handlers. + EHTTPMethod mHTTPMethod; std::string mURL; + LLSD mResponseHeaders; + + protected: + // These should also generally be treated as 'read-only' during completion handlers + // and should be accessed by the get* methods. The exception to this rule would + // be when overriding the completedRaw method in preparation for calling httpCompleted(). + S32 mStatus; + std::string mReason; + LLSD mContent; }; typedef LLPointer ResponderPtr; @@ -225,10 +259,11 @@ public: // Copies the string so that it is guaranteed to stick around void setoptString(CURLoption option, const std::string& value); + void slist_append(const std::string& header, const std::string& value); void slist_append(const char* str); void setHeaders(); - U32 report(CURLcode); + S32 report(CURLcode); void getTransferInfo(LLCurl::TransferInfo* info); void prepRequest(const std::string& url, const std::vector& headers, LLCurl::ResponderPtr, S32 time_out = 0, bool post = false); @@ -484,6 +519,7 @@ public: void setWriteCallback(curl_write_callback callback, void* userdata); void setReadCallback(curl_read_callback callback, void* userdata); void setSSLCtxCallback(curl_ssl_ctx_callback callback, void* userdata); + void slist_append(const std::string& header, const std::string& value); void slist_append(const char* str); void sendRequest(const std::string& url); void requestComplete(); -- cgit v1.2.3 From beeefb45269f45ea717f58b30a0985951ae23c20 Mon Sep 17 00:00:00 2001 From: Don Kjer Date: Thu, 4 Apr 2013 21:50:45 +0000 Subject: Renaming HTTP_HEADER_* into HTTP_IN_HEADER_* and HTTP_OUT_HEADER_* to make it more clear which header strings should be used for incoming vs outgoing situations. Using constants for commonly used llhttpnode context strings. --- indra/llmessage/llcurl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llmessage/llcurl.h') diff --git a/indra/llmessage/llcurl.h b/indra/llmessage/llcurl.h index c72e1e493a..8a65c783be 100644 --- a/indra/llmessage/llcurl.h +++ b/indra/llmessage/llcurl.h @@ -91,8 +91,8 @@ public: S32 getStatus() const { return mStatus; } const std::string& getReason() const { return mReason; } const LLSD& getContent() const { return mContent; } - bool hasResponseHeader(const std::string& header, bool check_lower=false) const; - const std::string& getResponseHeader(const std::string& header, bool check_lower=true) const; + bool hasResponseHeader(const std::string& header) const; + const std::string& getResponseHeader(const std::string& header) const; const LLSD& getResponseHeaders() const { return mResponseHeaders; } const std::string& getURL() const { return mURL; } EHTTPMethod getHTTPMethod() const { return mHTTPMethod; } -- cgit v1.2.3 From fd0e84296e1f20b90bc6e7c0ad4fbfcecf0aa6d9 Mon Sep 17 00:00:00 2001 From: Stinson Linden Date: Wed, 23 Apr 2014 19:36:08 +0100 Subject: MAINT-4009: Cleaning up the curl easy handle during shutdown. --- indra/llmessage/llcurl.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indra/llmessage/llcurl.h') diff --git a/indra/llmessage/llcurl.h b/indra/llmessage/llcurl.h index fc9761ff9f..b033a3d4ab 100755 --- a/indra/llmessage/llcurl.h +++ b/indra/llmessage/llcurl.h @@ -269,6 +269,9 @@ private: static std::set sFreeHandles; static std::set sActiveHandles; static LLMutex* sHandleMutexp ; + + static void deleteAllActiveHandles(); + static void deleteAllFreeHandles(); }; class LLCurl::Multi -- cgit v1.2.3