Move to default headers
Set the $httpProvider.defaults.headers.
Overwrite the default on upload image.
For more information see:
https://docs.angularjs.org/api/ng/service/$http#setting-http-headers
Removed "Content-Type" on GET request.
There is no "Content-Type" on a GET request.
Content-Type is only used with POST, PUT, and PATCH requests. See:
https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
Tested: Manual regression test of Web UI. Performed tasks such as
firmware image upload, booting the server, and deleting
event logs.
Change-Id: I9217ba3eab40d40a331322d0848bdc5c5ca93767
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/app/common/services/api-utils.js b/app/common/services/api-utils.js
index c783082..434ca2f 100644
--- a/app/common/services/api-utils.js
+++ b/app/common/services/api-utils.js
@@ -38,10 +38,6 @@
method: 'GET',
url: DataService.getHost() +
'/xyz/openbmc_project/state/chassis0/attr/CurrentPowerState',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(
@@ -67,10 +63,6 @@
method: 'GET',
url: DataService.getHost() +
'/xyz/openbmc_project/state/host0/attr/CurrentHostState',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(
@@ -90,10 +82,6 @@
method: 'GET',
url: DataService.getHost() +
'/xyz/openbmc_project/network/snmp/manager/enumerate',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(function(response) {
@@ -106,10 +94,6 @@
method: 'GET',
url: DataService.getHost() +
'/xyz/openbmc_project/network/enumerate',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(
@@ -218,10 +202,6 @@
url: DataService.getHost() +
'/xyz/openbmc_project/network/' + interface_name +
'/attr/MACAddress',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': mac_address})
})
@@ -234,10 +214,6 @@
method: 'PUT',
url: DataService.getHost() +
'/xyz/openbmc_project/network/config/attr/DefaultGateway',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': defaultGateway})
})
@@ -251,10 +227,6 @@
url: DataService.getHost() +
'/xyz/openbmc_project/network/' + interfaceName +
'/attr/DHCPEnabled',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': dhcpEnabled})
})
@@ -268,10 +240,6 @@
url: DataService.getHost() +
'/xyz/openbmc_project/network/' + interfaceName +
'/attr/Nameservers',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': dnsServers})
})
@@ -285,10 +253,6 @@
url: DataService.getHost() +
'/xyz/openbmc_project/network/' + interfaceName +
'/ipv4/' + networkID + '/action/Delete',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': []})
})
@@ -303,10 +267,6 @@
url: DataService.getHost() +
'/xyz/openbmc_project/network/' + interfaceName +
'/action/IP',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({
'data': [
@@ -325,10 +285,6 @@
method: 'GET',
url: DataService.getHost() +
'/xyz/openbmc_project/led/groups/enclosure_identify',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(
@@ -347,10 +303,6 @@
$http({
method: 'POST',
url: DataService.getHost() + '/login',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': [username, password]})
})
@@ -377,10 +329,6 @@
return $http({
method: 'POST',
url: DataService.getHost() + '/login',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: false,
data: JSON.stringify({'data': [username, password]})
})
@@ -392,10 +340,6 @@
$http({
method: 'POST',
url: DataService.getHost() + '/logout',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': []})
})
@@ -418,10 +362,6 @@
method: 'POST',
url: DataService.getHost() + '/xyz/openbmc_project/user/' + user +
'/action/SetPassword',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': [newPassword]}),
responseType: 'arraybuffer'
@@ -443,10 +383,6 @@
method: 'PUT',
url: DataService.getHost() +
'/xyz/openbmc_project/state/chassis0/attr/RequestedPowerTransition',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify(
{'data': 'xyz.openbmc_project.State.Chassis.Transition.Off'})
@@ -468,10 +404,6 @@
method: 'PUT',
url: DataService.getHost() +
'/xyz/openbmc_project/led/groups/enclosure_identify/attr/Asserted',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': state})
})
@@ -496,10 +428,6 @@
method: 'PUT',
url: DataService.getHost() +
'/xyz/openbmc_project/state/bmc0/attr/RequestedBmcTransition',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify(
{'data': 'xyz.openbmc_project.State.BMC.Transition.Reboot'})
@@ -525,10 +453,6 @@
method: 'GET',
url: DataService.getHost() +
'/xyz/openbmc_project/state/bmc0/attr/LastRebootTime',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(function(response) {
@@ -541,10 +465,6 @@
method: 'PUT',
url: DataService.getHost() +
'/xyz/openbmc_project/state/host0/attr/RequestedHostTransition',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify(
{'data': 'xyz.openbmc_project.State.Host.Transition.On'})
@@ -567,10 +487,6 @@
method: 'PUT',
url: DataService.getHost() +
'/xyz/openbmc_project/state/host0/attr/RequestedHostTransition',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify(
{'data': 'xyz.openbmc_project.State.Host.Transition.Off'})
@@ -593,10 +509,6 @@
method: 'PUT',
url: DataService.getHost() +
'/xyz/openbmc_project/state/host0/attr/RequestedHostTransition',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify(
{'data': 'xyz.openbmc_project.State.Host.Transition.Reboot'})
@@ -618,10 +530,6 @@
$http({
method: 'POST',
url: DataService.getHost() + '/xyz/openbmc_project/state/host0',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': []})
})
@@ -646,10 +554,6 @@
method: 'GET',
url: DataService.getHost() +
'/xyz/openbmc_project/state/chassis0/attr/LastStateChangeTime',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(function(response) {
@@ -662,10 +566,6 @@
method: 'GET',
url: DataService.getHost() +
'/xyz/openbmc_project/logging/enumerate',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(
@@ -749,10 +649,6 @@
method: 'GET',
url: DataService.getHost() +
'/xyz/openbmc_project/sensors/enumerate',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(
@@ -907,10 +803,6 @@
url: DataService.getHost() +
'/xyz/openbmc_project/software/' + imageId +
'/attr/Activation',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(function(response) {
@@ -923,10 +815,6 @@
method: 'GET',
url: DataService.getHost() +
'/xyz/openbmc_project/software/enumerate',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(
@@ -1041,10 +929,6 @@
method: 'PUT',
url: DataService.getHost() + '/xyz/openbmc_project/software/' +
imageId + '/attr/Priority',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': priority})
})
@@ -1067,10 +951,6 @@
method: 'POST',
url: DataService.getHost() + '/xyz/openbmc_project/software/' +
imageId + '/action/Delete',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': []})
})
@@ -1093,10 +973,6 @@
method: 'PUT',
url: DataService.getHost() + '/xyz/openbmc_project/software/' +
imageId + '/attr/RequestedActivation',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data:
JSON.stringify({'data': Constants.FIRMWARE.ACTIVATE_FIRMWARE})
@@ -1119,6 +995,7 @@
method: 'POST',
timeout: 5 * 60 * 1000,
url: DataService.getHost() + '/upload/image',
+ // Overwrite the default 'application/json' Content-Type
headers: {'Content-Type': 'application/octet-stream'},
withCredentials: true,
data: file
@@ -1132,10 +1009,6 @@
method: 'POST',
url: DataService.getHost() +
'/xyz/openbmc_project/software/action/DownloadViaTFTP',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': [filename, host]}),
responseType: 'arraybuffer'
@@ -1152,10 +1025,6 @@
method: 'GET',
url: DataService.getHost() +
'/xyz/openbmc_project/inventory/system',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(function(response) {
@@ -1166,10 +1035,6 @@
return $http({
method: 'GET',
url: DataService.getHost() + '/xyz/openbmc_project/time/bmc',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(function(response) {
@@ -1181,10 +1046,6 @@
method: 'GET',
url: DataService.getHost() +
'/xyz/openbmc_project/time/enumerate',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(function(response) {
@@ -1196,10 +1057,6 @@
method: 'GET',
url: DataService.getHost() +
'/xyz/openbmc_project/inventory/enumerate',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
}).then(function(response) {
var json = JSON.stringify(response.data);
@@ -1329,10 +1186,6 @@
url: DataService.getHost() +
'/xyz/openbmc_project/logging/entry/' + item.Id +
'/action/Delete',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': []})
}));
@@ -1356,10 +1209,6 @@
url: DataService.getHost() +
'/xyz/openbmc_project/logging/entry/' + item.Id +
'/attr/Resolved',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': '1'})
}));
@@ -1374,10 +1223,6 @@
method: 'GET',
url: DataService.getHost() +
'/xyz/openbmc_project/sensors/power/total_power',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(
@@ -1403,10 +1248,6 @@
method: 'GET',
url: DataService.getHost() +
'/xyz/openbmc_project/control/host0/power_cap',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true
})
.then(function(response) {
@@ -1418,10 +1259,6 @@
method: 'PUT',
url: DataService.getHost() +
'/xyz/openbmc_project/control/host0/power_cap/attr/PowerCapEnable',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': powerCapEnable})
})
@@ -1434,10 +1271,6 @@
method: 'PUT',
url: DataService.getHost() +
'/xyz/openbmc_project/control/host0/power_cap/attr/PowerCap',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': powerCap})
})
@@ -1450,10 +1283,6 @@
method: 'PUT',
url: DataService.getHost() +
'/xyz/openbmc_project/network/config/attr/HostName',
- headers: {
- 'Accept': 'application/json',
- 'Content-Type': 'application/json'
- },
withCredentials: true,
data: JSON.stringify({'data': hostname})
})
diff --git a/app/index.js b/app/index.js
index 7eff968..1e11804 100644
--- a/app/index.js
+++ b/app/index.js
@@ -122,6 +122,18 @@
'$httpProvider',
function($httpProvider) {
$httpProvider.interceptors.push('apiInterceptor');
+ $httpProvider.defaults.headers.common = {
+ 'Accept': 'application/json'
+ };
+ $httpProvider.defaults.headers.post = {
+ 'Content-Type': 'application/json'
+ };
+ $httpProvider.defaults.headers.put = {
+ 'Content-Type': 'application/json'
+ };
+ $httpProvider.defaults.headers.patch = {
+ 'Content-Type': 'application/json'
+ };
}
])
.run([