Browse Source

Merge pull request #8 from HariKamath/master

Wrapper function for mg_get_header()
sunsetbrew 12 năm trước cách đây
mục cha
commit
dc6a3d7faf
2 tập tin đã thay đổi với 18 bổ sung5 xóa
  1. 11 4
      include/CivetServer.h
  2. 7 1
      src/CivetServer.cpp

+ 11 - 4
include/CivetServer.h

@@ -153,15 +153,22 @@ public:
     CivetHandler *getHandler(const char *uri, unsigned urilen) const;
 	
 	/**
-	 * getCookie(const std::string &_cookieName, std::string &_cookieValue)
-	 * @param conn - the 
-	 * @param _cookieName - cookie name to h=get the value from
-	 * @param _cookieValue - cookie value is returned using thiis reference
+	 * getCookie(struct mg_connection *conn, const std::string &cookieName, std::string &cookieValue)
+	 * @param conn - the connection information 
+	 * @param cookieName - cookie name to get the value from
+	 * @param cookieValue - cookie value is returned using thiis reference
 	 * @puts the cookie value string that matches the cookie name in the _cookieValue string.
 	 * @returns the size of the cookie value string read.
 	*/
 	int getCookie(struct mg_connection *conn, const std::string &cookieName, std::string &cookieValue);
 
+	/**
+	 * getHeader(struct mg_connection *conn, const std::string &headerName)
+	 * @param conn - the connection information 
+	 * @param headerName - header name to get the value from
+	 * @returns a char array whcih contains the header value as string
+	*/
+	const char* getHeader(struct mg_connection *conn, const std::string &headerName);
 protected:
 
     /**

+ 7 - 1
src/CivetServer.cpp

@@ -160,6 +160,12 @@ int CivetServer::getCookie(struct mg_connection *conn, const std::string &cookie
 	char _cookieValue[4096];
 	const char *cookie = mg_get_header(conn, "Cookie");
 	int lRead = mg_get_cookie(cookie, cookieName.c_str(), _cookieValue, sizeof(_cookieValue));
-	cookieValue = std::string(_cookieValue);
+	cookieValue.clear();
+	cookieValue.append(_cookieValue);
 	return lRead;
+}
+
+const char* CivetServer::getHeader(struct mg_connection *conn, const std::string &headerName)
+{
+	return mg_get_header(conn, headerName.c_str());
 }