Skip to content

Commit

Permalink
Resolve HttpClientConnection methods temporarily un-deprecated in S…
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Feb 25, 2019
1 parent e83819e commit b6b6317
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 36 deletions.
28 changes: 0 additions & 28 deletions Sming/SmingCore/Network/Http/HttpClientConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,6 @@ bool HttpClientConnection::send(HttpRequest* request)
return connect(request->uri.Host, request->uri.Port, useSsl);
}

String HttpClientConnection::getResponseHeader(String headerName, String defaultValue)
{
if(response.headers.contains(headerName))
return response.headers[headerName];

return defaultValue;
}

DateTime HttpClientConnection::getLastModifiedDate()
{
DateTime res;
String strLM = response.headers[HTTP_HEADER_LAST_MODIFIED];
if(res.fromHttpDate(strLM))
return res;
else
return DateTime();
}

DateTime HttpClientConnection::getServerDate()
{
DateTime res;
String strSD = response.headers[HTTP_HEADER_DATE];
if(res.fromHttpDate(strSD))
return res;
else
return DateTime();
}

void HttpClientConnection::reset()
{
delete incomingRequest;
Expand Down
23 changes: 16 additions & 7 deletions Sming/SmingCore/Network/Http/HttpClientConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@ class HttpClientConnection : public HttpConnection
/**
* @deprecated Use `getResponse()->code` instead
*/
int getResponseCode() SMING_DEPRECATED
int getResponseCode() const SMING_DEPRECATED
{
return response.code;
}

/**
* @deprecated Use `getResponse()->headers[headerName]` instead
* @deprecated Use `getResponse()->headers[]` instead
*/
String getResponseHeader(String headerName, String defaultValue = nullptr) SMING_DEPRECATED;
String getResponseHeader(const String& headerName, const String& defaultValue = nullptr) const SMING_DEPRECATED
{
return response.headers[headerName] ?: defaultValue;
}

/**
* @deprecated Use `getResponse()->headers` instead
Expand All @@ -98,14 +101,20 @@ class HttpClientConnection : public HttpConnection
}

/**
* @todo deprecate: Use `getResponse()->headers[HTTP_HEADER_LAST_MODIFIED]` instead
* @deprecated Use `getResponse()->headers.getLastModifiedDate()` instead
*/
DateTime getLastModifiedDate();
DateTime getLastModifiedDate() const SMING_DEPRECATED
{
return response.headers.getLastModifiedDate();
}

/**
* @todo deprecate: Use `getResponse()->headers[HTTP_HEADER_DATE]` instead
* @deprecated Use `getResponse()->headers.getServerDate()` instead
*/
DateTime getServerDate();
DateTime getServerDate() const SMING_DEPRECATED
{
return response.headers.getServerDate();
}

/**
* @deprecated Use `getResponse()->getBody()` instead
Expand Down
17 changes: 16 additions & 1 deletion Sming/SmingCore/Network/Http/HttpHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "Data/CStringArray.h"
#include "WString.h"
#include "WHashMap.h"
#include "DateTime.h"

/*
* Common HTTP header field names. Enumerating these simplifies matching
Expand Down Expand Up @@ -159,7 +160,7 @@ class HttpHeaders : private HashMap<HttpHeaderFieldName, String>

using HashMap::contains;

bool contains(const String& name)
bool contains(const String& name) const
{
return contains(fromString(name));
}
Expand Down Expand Up @@ -195,6 +196,20 @@ class HttpHeaders : private HashMap<HttpHeaderFieldName, String>

using HashMap::count;

DateTime getLastModifiedDate() const
{
DateTime dt;
String strLM = operator[](HTTP_HEADER_LAST_MODIFIED);
return dt.fromHttpDate(strLM) ? dt : DateTime();
}

DateTime getServerDate() const
{
DateTime dt;
String strSD = operator[](HTTP_HEADER_DATE);
return dt.fromHttpDate(strSD) ? dt : DateTime();
}

private:
/** @brief Try to match a string against the list of custom field names
* @param name
Expand Down

0 comments on commit b6b6317

Please sign in to comment.