Skip to content

Commit

Permalink
Add startRequest() to API
Browse files Browse the repository at this point in the history
  • Loading branch information
imrehorvath committed Jan 8, 2017
1 parent 01f8bde commit d7f35db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
6 changes: 6 additions & 0 deletions BridgeHttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ bool BridgeHttpClient::getResponseHeaderValue(const String& header, String& valu
return true;
}

void BridgeHttpClient::startRequest() {
clearHeaders();
clearAuth();
_isInsecureEnabled = false;
}

void BridgeHttpClient::request(const char *verb, const char *url, const char *data, bool async) {
Process p;
p.runShellCommand("mktemp");
Expand Down
32 changes: 19 additions & 13 deletions BridgeHttpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,44 @@ class BridgeHttpClient : public Process {
_user(NULL), _passwd(NULL),
_extraHeaderIdx(0) {}

/**
/*
* Synchronous methods
*/
void get(const char *url);
void post(const char *url, const char *data);
void put(const char *url, const char *data);
void del(const char *url);

/**
/*
* Asynchronous methods
*/
void getAsync(const char *url);
void postAsync(const char *url, const char *data);
void putAsync(const char *url, const char *data);
void delAsync(const char *url);

/**
/*
* Method to check, if the async request is still running or has finished.
*/
bool finished();

/**
/*
* Call this method after the request has finished,
* to get the HTTP response code from the server.
*
* Returns the response code eg. 200
*/
unsigned int getResponseCode();

/**
/*
* Call this method after the request has finished,
* to get the response headers received from the server.
*
* Returns a String object with all the response headers included.
*/
String getResponseHeaders();

/**
/*
* Call this method before issuing the requests,
* to allows "insecure" SSL.
*
Expand All @@ -77,33 +77,33 @@ class BridgeHttpClient : public Process {
*/
void enableInsecure();

/**
/*
* Call this method before issuing the request,
* to add an extra header to the request.
*
* Returns 0 if the header fits into the array of headers. -1 otherwise.
*/
int addHeader(const char *header);

/**
/*
* Call this method before issuing the request,
* to include basic authorization into the request.
*/
void basicAuth(const char *user, const char *passwd);

/**
/*
* Call this method between the different request calls on the same client,
* to clear/setup the request headers for the next call.
*/
void clearHeaders();

/**
/*
* Call this method between the different request calls on the same client,
* to clear the previously set basic authorization for the subsequent call.
*/
void clearAuth();

/**
/*
* Call this method after the request has finished,
* to get a particular response header value.
*
Expand All @@ -112,6 +112,12 @@ class BridgeHttpClient : public Process {
*/
bool getResponseHeaderValue(const String& header, String& value);

/*
* Reset client request settings.
* Clears the request headers, basic auth. settings and the insecure-enabled flag.
*/
void startRequest();

private:
String _tempFileName;

Expand All @@ -125,12 +131,12 @@ class BridgeHttpClient : public Process {

String _cachedRespHeaders;

/**
/*
* Sends the actual request via cURL on the Linux side
*/
void request(const char *verb, const char *url, const char *data, bool async=false);

/**
/*
* Clears the cached response headers between subsequent requests
*/
void clearCachedRespHeaders();
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=BridgeHttpClient
version=3.0.4
version=3.1.0
author=Imre Horvath <[email protected]>
maintainer=Imre Horvath <[email protected]>
sentence=A practical and easy to use generic HTTP client library for the Yun.
Expand Down

0 comments on commit d7f35db

Please sign in to comment.