Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: iothub_client_sample_http simplesample_http temp_sensor_anomaly
Revision 32:4d4a226b072b, committed 2017-08-25
- Comitter:
- AzureIoTClient
- Date:
- Fri Aug 25 11:22:14 2017 -0700
- Parent:
- 31:c889be99d3f7
- Child:
- 33:270c65ccd77d
- Commit message:
- 1.1.22
Changed in this revision
| iothubtransporthttp.c | Show annotated file Show diff for this revision Revisions of this file |
--- a/iothubtransporthttp.c Mon May 22 10:34:45 2017 -0700
+++ b/iothubtransporthttp.c Fri Aug 25 11:22:14 2017 -0700
@@ -25,8 +25,12 @@
#include "azure_c_shared_utility/agenttime.h"
#define IOTHUB_APP_PREFIX "iothub-app-"
-const char* IOTHUB_MESSAGE_ID = "iothub-messageid";
-const char* IOTHUB_CORRELATION_ID = "iothub-correlationid";
+static const char* IOTHUB_MESSAGE_ID = "iothub-messageid";
+static const char* IOTHUB_CORRELATION_ID = "iothub-correlationid";
+static const char* IOTHUB_CONTENT_TYPE_D2C = "iothub-contenttype";
+static const char* IOTHUB_CONTENT_ENCODING_D2C = "iothub-contentencoding";
+static const char* IOTHUB_CONTENT_TYPE_C2D = "ContentType";
+static const char* IOTHUB_CONTENT_ENCODING_C2D = "ContentEncoding";
#define CONTENT_TYPE "Content-Type"
#define APPLICATION_OCTET_STREAM "application/octet-stream"
@@ -1514,7 +1518,7 @@
size_t count;
if (Map_GetInternals(map, &keys, &values, &count) != MAP_OK)
{
- /*Codes_SRS_TRANSPORTMULTITHTTP_17_078: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */
+ /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */
LogError("unable to Map_GetInternals");
}
else
@@ -1523,6 +1527,8 @@
bool goOn = true;
const char* msgId;
const char* corrId;
+ const char* userDefinedContentType;
+ const char* contentEncoding;
for (i = 0; (i < count) && goOn; i++)
{
@@ -1588,6 +1594,28 @@
}
}
+ // Codes_SRS_TRANSPORTMULTITHTTP_09_001: [ If the IoTHubMessage being sent contains property `content-type` it shall be added to the HTTP headers as "iothub-contenttype":"value". ]
+ userDefinedContentType = IoTHubMessage_GetContentTypeSystemProperty(message->messageHandle);
+ if (goOn && userDefinedContentType != NULL)
+ {
+ if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, IOTHUB_CONTENT_TYPE_D2C, userDefinedContentType) != HTTP_HEADERS_OK)
+ {
+ LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair (content-type)");
+ goOn = false;
+ }
+ }
+
+ // Codes_SRS_TRANSPORTMULTITHTTP_09_002: [ If the IoTHubMessage being sent contains property `content-encoding` it shall be added to the HTTP headers as "iothub-contentencoding":"value". ]
+ contentEncoding = IoTHubMessage_GetContentEncodingSystemProperty(message->messageHandle);
+ if (goOn && contentEncoding != NULL)
+ {
+ if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, IOTHUB_CONTENT_ENCODING_D2C, contentEncoding) != HTTP_HEADERS_OK)
+ {
+ LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair (content-encoding)");
+ goOn = false;
+ }
+ }
+
if (!goOn)
{
/*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */
@@ -2172,6 +2200,37 @@
}
}
}
+ // Codes_SRS_TRANSPORTMULTITHTTP_09_003: [ The HTTP header value of `ContentType` shall be set in the `IoTHubMessage_SetContentTypeSystemProperty`. ]
+ else if (strncmp(IOTHUB_CONTENT_TYPE_C2D, completeHeader, strlen(IOTHUB_CONTENT_TYPE_C2D)) == 0)
+ {
+ char* whereIsColon = strchr(completeHeader, ':');
+ if (whereIsColon != NULL)
+ {
+ *whereIsColon = '\0'; /*cut it down*/
+ if (IoTHubMessage_SetContentTypeSystemProperty(receivedMessage, whereIsColon + 2) != IOTHUB_MESSAGE_OK)
+ {
+ LogError("Failed setting IoTHubMessage content-type");
+ free(completeHeader);
+ break;
+ }
+ }
+ }
+ // Codes_SRS_TRANSPORTMULTITHTTP_09_004: [ The HTTP header value of `ContentEncoding` shall be set in the `IoTHub_SetContentEncoding`. ]
+ else if (strncmp(IOTHUB_CONTENT_ENCODING_C2D, completeHeader, strlen(IOTHUB_CONTENT_ENCODING_C2D)) == 0)
+ {
+ char* whereIsColon = strchr(completeHeader, ':');
+ if (whereIsColon != NULL)
+ {
+ *whereIsColon = '\0'; /*cut it down*/
+ if (IoTHubMessage_SetContentEncodingSystemProperty(receivedMessage, whereIsColon + 2) != IOTHUB_MESSAGE_OK)
+ {
+ LogError("Failed setting IoTHubMessage content-encoding");
+ free(completeHeader);
+ break;
+ }
+ }
+ }
+
free(completeHeader);
}
}
