Fix REST API authentication errors

The authentication errors were not sent as the connection was closed
immediately. The reason for this was the fact that if a client request
uploaded data with bad credentials, MaxScale would not send a response if
the connection was kept open. Closing the socket solved the hang but
caused confusing errors on the client side.

The libmicrohttpd library appears to require full processing of any data
uploaded by a client request before a request can be sent. With this
change, the clients receive proper authentication errors in all cases.
This commit is contained in:
Markus Mäkelä
2017-09-07 22:05:36 +03:00
parent 5abb30c357
commit 81a3ff6c27
2 changed files with 95 additions and 14 deletions

View File

@ -21,15 +21,27 @@
class Client
{
Client(const Client&);
Client& operator=(const Client&);
public:
enum state
{
OK,
FAILED,
INIT,
CLOSED
};
/**
* @brief Create a new client
*
* @param connection The connection handle for this client
*/
Client(MHD_Connection *connection):
m_connection(connection)
m_connection(connection),
m_state(INIT)
{
}
@ -52,9 +64,41 @@ public:
*/
int process(std::string url, std::string method, const char* data, size_t *size);
/**
* @brief Authenticate the client
*
* @param connection The MHD connection object
* @param url Requested URL
* @param method The request method
*
* @return True if authentication was successful
*/
bool auth(MHD_Connection* connection, const char* url, const char* method);
/**
* Get client state
*
* @return The client state
*/
state get_state() const
{
return m_state;
}
/**
* Close the client connection
*
* All further requests will be rejected immediately
*/
void close()
{
m_state = CLOSED;
}
private:
MHD_Connection* m_connection; /**< Connection handle */
std::string m_data; /**< Uploaded data */
state m_state; /**< Client state */
};
/**