Skip to content

Commit

Permalink
Http headers enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
sbouchex committed Aug 22, 2016
1 parent c5ab897 commit e421ab3
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 3 deletions.
10 changes: 10 additions & 0 deletions notifications/NotificationHTTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CNotificationHTTP::CNotificationHTTP() : CNotificationBase(std::string("http"),
SetupConfigBase64(std::string("HTTPTo"), _HTTPTo);
SetupConfigBase64(std::string("HTTPURL"), _HTTPURL);
SetupConfigBase64(std::string("HTTPPostData"), _HTTPPostData);
SetupConfigBase64(std::string("HTTPPostHeaders"), _HTTPPostHeaders);
SetupConfigBase64(std::string("HTTPPostContentType"), _HTTPPostContentType);
}

Expand Down Expand Up @@ -50,6 +51,15 @@ bool CNotificationHTTP::SendMessageImplementation(const std::string &Subject, co
{
std::vector<std::string> ExtraHeaders;
ExtraHeaders.push_back("Content-type: " + _HTTPPostContentType);
if (_HTTPPostHeaders.length() > 0)
{
std::vector<std::string> ExtraHeaders2;
StringSplit(_HTTPPostHeaders, "\r\n", ExtraHeaders2);
for (size_t i = 0; i < ExtraHeaders2.size(); i++)
{
ExtraHeaders.push_back(ExtraHeaders2[i]);
}
}
std::string httpData = _HTTPPostData;
stdreplace(httpData, "#FIELD1", _HTTPField1);
stdreplace(httpData, "#FIELD2", _HTTPField2);
Expand Down
1 change: 1 addition & 0 deletions notifications/NotificationHTTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ class CNotificationHTTP : public CNotificationBase {
std::string _HTTPURL;
std::string _HTTPPostData;
std::string _HTTPPostContentType;
std::string _HTTPPostHeaders;
};
18 changes: 18 additions & 0 deletions push/HttpPush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void CHttpPush::DoHttpPush()
{
std::string httpUrl = "";
std::string httpData = "";
std::string httpHeaders= "";
int httpMethodInt = 0;
int httpAuthInt = 0;
std::string httpAuth = "";
Expand Down Expand Up @@ -80,6 +81,7 @@ void CHttpPush::DoHttpPush()
{
m_sql.GetPreferencesVar("HttpUrl", httpUrl);
m_sql.GetPreferencesVar("HttpData", httpData);
m_sql.GetPreferencesVar("HttpHeaders", httpHeaders);
if (httpUrl == "")
return;

Expand Down Expand Up @@ -216,6 +218,16 @@ void CHttpPush::DoHttpPush()
}
}
else if (httpMethodInt == 1) { // POST
if (httpHeaders.size() > 0)
{
// Add additional headers
std::vector<std::string> ExtraHeaders2;
StringSplit(httpHeaders,"\r\n", ExtraHeaders2);
for (size_t i = 0; i < ExtraHeaders2.size(); i++)
{
ExtraHeaders.push_back(ExtraHeaders2[i]);
}
}
if (!HTTPClient::POST(httpUrl, httpData, ExtraHeaders, sResult))
{
_log.Log(LOG_ERROR, "HttpLink: Error sending data to http with POST!");
Expand Down Expand Up @@ -251,6 +263,7 @@ namespace http {
std::string url = request::findValue(&req, "url");
std::string method = request::findValue(&req, "method");
std::string data = request::findValue(&req, "data");
std::string headers = request::findValue(&req, "headers");
std::string linkactive = request::findValue(&req, "linkactive");
std::string debugenabled = request::findValue(&req, "debugenabled");
std::string auth = request::findValue(&req, "auth");
Expand All @@ -269,6 +282,7 @@ namespace http {
m_sql.UpdatePreferencesVar("HttpUrl", url.c_str());
m_sql.UpdatePreferencesVar("HttpMethod", atoi(method.c_str()));
m_sql.UpdatePreferencesVar("HttpData", data.c_str());
m_sql.UpdatePreferencesVar("HttpHeaders", headers.c_str());
m_sql.UpdatePreferencesVar("HttpActive", ilinkactive);
m_sql.UpdatePreferencesVar("HttpDebug", idebugenabled);
m_sql.UpdatePreferencesVar("HttpAuth", atoi(auth.c_str()));
Expand Down Expand Up @@ -306,6 +320,10 @@ namespace http {
{
root["HttpData"] = sValue;
}
if (m_sql.GetPreferencesVar("HttpHeaders", sValue))
{
root["HttpHeaders"] = sValue;
}
if (m_sql.GetPreferencesVar("HttpMethod", nValue))
{
root["HttpMethod"] = nValue;
Expand Down
10 changes: 9 additions & 1 deletion www/app/DPHttpController.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@ define(['app'], function (app) {
switch(targetType) {
case "0":
$("#httpremote #lblremotedata").hide();
$("#httpremote #lblremoteheaders").hide();
$("#httpremote #data").hide();
$("#httpremote #headers").hide();
break;
case "1":
$("#httpremote #lblremotedata").show();
$("#httpremote #data").show();
$("#httpremote #lblremoteheaders").show();
$("#httpremote #headers").show();
break;
case "2":
$("#httpremote #lblremotedata").show();
$("#httpremote #data").show();
$("#httpremote #lblremoteheaders").show();
$("#httpremote #headers").show();
break;
default:
break;
Expand Down Expand Up @@ -100,6 +106,7 @@ define(['app'], function (app) {
{
var cleanurl = $('#httpremote #url').val();
var httpdata = $('#httpremote #data').val();
var httpheaders = $('#httpremote #headers').val();
var method = $('#httpremote #combomethod').val();
var linkactive = 0;
if ($('#httpremote #httplinkenabled').is(":checked"))
Expand All @@ -117,7 +124,7 @@ define(['app'], function (app) {
var authbasicpassword = $('#httpremote #authBasicPassword').val();
$.ajax({
url: "json.htm?type=command&param=savehttplinkconfig" +
"&url=" + encodeURIComponent(cleanurl) + "&method=" + method + "&data=" + encodeURIComponent(httpdata) + "&linkactive=" + linkactive + "&debugenabled=" + debugenabled + "&auth=" + auth + "&authbasiclogin=" + authbasiclogin + "&authbasicpassword=" + authbasicpassword,
"&url=" + encodeURIComponent(cleanurl) + "&method=" + method + "&headers=" + encodeURIComponent(httpheaders) + "&data=" + encodeURIComponent(httpdata) + "&linkactive=" + linkactive + "&debugenabled=" + debugenabled + "&auth=" + auth + "&authbasiclogin=" + authbasiclogin + "&authbasicpassword=" + authbasicpassword,
async: false,
dataType: 'json',
success: function(data) {
Expand Down Expand Up @@ -211,6 +218,7 @@ define(['app'], function (app) {
$('#httpremote #url').val(data.HttpUrl);
$('#httpremote #combomethod').val(data.HttpMethod);
$('#httpremote #data').val(data.HttpData);
$('#httpremote #headers').val(data.HttpHeaders);
$('#httpremote #httplinkenabled').prop('checked', false);
if (data.HttpActive) {
$('#httpremote #httplinkenabled').prop('checked', true);
Expand Down
6 changes: 5 additions & 1 deletion www/app/SetupController.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ define(['app'], function (app) {
var HTTPTo=encodeURIComponent($("#httptable #HTTPTo").val());
var HTTPURL = encodeURIComponent($("#httptable #HTTPURL").val());
var HTTPPostData = encodeURIComponent($("#httptable #HTTPPostData").val());
var HTTPPostHeaders = encodeURIComponent($("#httptable #HTTPPostHeaders").val());
var HTTPPostContentType = encodeURIComponent($("#httptable #HTTPPostContentType").val());
if (HTTPPostData != "" && HTTPPostContentType=="") {
ShowNotify($.t('Please specify the content type...'), 3500, true);
Expand All @@ -60,7 +61,7 @@ define(['app'], function (app) {
ShowNotify($.t('Please specify the base URL!...'), 3500, true);
return;
}
extraparams = "HTTPField1=" + HTTPField1 + "&HTTPField2=" + HTTPField2 + "&HTTPField3=" + HTTPField3 + "&HTTPField4=" + HTTPField4 + "&HTTPTo=" + HTTPTo + "&HTTPURL=" + HTTPURL + "&HTTPPostData=" + HTTPPostData + "&HTTPPostContentType=" + HTTPPostContentType;
extraparams = "HTTPField1=" + HTTPField1 + "&HTTPField2=" + HTTPField2 + "&HTTPField3=" + HTTPField3 + "&HTTPField4=" + HTTPField4 + "&HTTPTo=" + HTTPTo + "&HTTPURL=" + HTTPURL + "&HTTPPostData=" + HTTPPostData + "&HTTPPostContentType=" + HTTPPostContentType + "&HTTPPostHeaders=" + HTTPPostHeaders;
break;
case "prowl":
var ProwlAPI=encodeURIComponent($("#prowltable #ProwlAPI").val());
Expand Down Expand Up @@ -317,6 +318,9 @@ define(['app'], function (app) {
if (typeof data.HTTPPostContentType != 'undefined') {
$("#httptable #HTTPPostContentType").val(atob(data.HTTPPostContentType));
}
if (typeof data.HTTPPostHeaders != 'undefined') {
$("#httptable #HTTPPostHeaders").val(atob(data.HTTPPostHeaders));
}

if (typeof data.KodiEnabled != 'undefined') {
$("#koditable #KodiEnabled").prop('checked',data.KodiEnabled==1);
Expand Down
2 changes: 1 addition & 1 deletion www/html5.appcache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CACHE MANIFEST
# ref 1285
# ref 1286

CACHE:
# CSS
Expand Down
4 changes: 4 additions & 0 deletions www/views/dphttp.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ <h2 data-i18n="General settings">General settings</h2><br>
<td align="right" style="width:110px"><label id="lblremotedata" for="name"><span data-i18n="Data">Data</span>:</label></td>
<td><textarea id="data" rows="4" style="width: 450px; padding: .2em;" class="text ui-widget-content ui-corner-all"></textarea></td>
</tr>
<tr>
<td align="right" style="width:110px"><label id="lblremoteheaders" for="name"><span data-i18n="Headers">Headers</span>:</label></td>
<td><textarea id="headers" rows="4" style="width: 450px; padding: .2em;" class="text ui-widget-content ui-corner-all"></textarea></td>
</tr>
<tr>
<td align="right" style="width:80px"><label for="httplinkenabled"><span data-i18n="Active">Active</span>:</label></td>
<td><input type="checkbox" id="httplinkenabled" checked></td>
Expand Down
6 changes: 6 additions & 0 deletions www/views/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,12 @@ <h2><span data-i18n="Custom HTTP">Custom HTTP</span>/<span data-i18n="Action">Ac
<input type="input" id="HTTPPostContentType" name="HTTPPostContentType" style="width: 356px; padding: .2em;" class="text ui-widget-content ui-corner-all" /> <button data-i18n="Test" class="btn btn-info" ng-click="TestNotification('http')">Test</button><br>
</td>
</tr>
<tr>
<td align="right"><label for="HTTPPostHeaders">POST Headers: </label></td>
<td>
<textarea id="HTTPPostHeaders" name="HTTPPostHeaders" rows="4" style="width: 356px; padding: .2em;" class="text ui-widget-content ui-corner-all"></textarea><br>
</td>
</tr>
</table>
<br>
</div>
Expand Down

0 comments on commit e421ab3

Please sign in to comment.