@uoa/lambda-tracing 2.1.0-beta.2 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.1.1
4
+ - Fixed issue where JSON requests & responses could only have content-type application/json. Will now parse request/response if content-type header includes "json" anywhere. If "json" is not present, it will check for "xml", then "image". If none are present, the raw string body will be used.
5
+
3
6
  ## 2.1.0
4
7
  - Unexpected errors are now caught within the library. When this occurs, the request promise will reject with the error.
5
8
  - http response promises will now be rejected if the response code is not in the 2xx range
package/dist/uoaHttps.js CHANGED
@@ -111,17 +111,17 @@ function doHttpsRequest(options, resolve, reject) {
111
111
  let parsedBody = body.toString();
112
112
  //Get the response content-type header value so we can apply different parsing methods
113
113
  const responseContentType = response.headers["content-type"]?.toLowerCase() ?? '';
114
- if (responseContentType === '' || responseContentType.includes('application/json')) {
114
+ if (responseContentType === '' || responseContentType.includes('json')) {
115
115
  parsedBody = JSON.parse(body.toString());
116
116
  }
117
- else if (responseContentType.includes('application/xml') || responseContentType.includes('text/xml')) {
117
+ else if (responseContentType.includes('xml')) {
118
118
  const parser = new fast_xml_parser_1.XMLParser({
119
119
  ignoreDeclaration: true,
120
120
  ignorePiTags: true
121
121
  });
122
122
  parsedBody = parser.parse(body.toString());
123
123
  }
124
- else if (responseContentType.includes('image/')) {
124
+ else if (responseContentType.includes('image')) {
125
125
  parsedBody = body.toString('base64');
126
126
  }
127
127
  if (response.statusCode !== undefined && response.statusCode >= 200 && response.statusCode < 300) {
@@ -144,7 +144,7 @@ function doHttpsRequest(options, resolve, reject) {
144
144
  function setRequestBody(request, data) {
145
145
  if (data) {
146
146
  const requestContentType = request.getHeader('content-type')?.toString() ?? '';
147
- if (requestContentType === '' || requestContentType.includes('application/json')) {
147
+ if (requestContentType === '' || requestContentType.includes('json')) {
148
148
  //We serialize using JSON.stringify as a default, or if JSON is specified
149
149
  request.write(JSON.stringify(data));
150
150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uoa/lambda-tracing",
3
- "version": "2.1.0-beta.2",
3
+ "version": "2.1.1",
4
4
  "description": "Library for logging & distributed tracing in UoA Lambda projects",
5
5
  "repository": {
6
6
  "type": "git",
package/uoaHttps.ts CHANGED
@@ -103,15 +103,15 @@ function doHttpsRequest(options: RequestOptions, resolve: any, reject: any): Cli
103
103
 
104
104
  //Get the response content-type header value so we can apply different parsing methods
105
105
  const responseContentType: string = response.headers["content-type"]?.toLowerCase() ?? '';
106
- if (responseContentType === '' || responseContentType.includes('application/json')) {
106
+ if (responseContentType === '' || responseContentType.includes('json')) {
107
107
  parsedBody = JSON.parse(body.toString());
108
- } else if (responseContentType.includes('application/xml') || responseContentType.includes('text/xml')) {
108
+ } else if (responseContentType.includes('xml')) {
109
109
  const parser = new XMLParser({
110
110
  ignoreDeclaration: true,
111
111
  ignorePiTags: true
112
112
  });
113
113
  parsedBody = parser.parse(body.toString());
114
- } else if (responseContentType.includes('image/')) {
114
+ } else if (responseContentType.includes('image')) {
115
115
  parsedBody = body.toString('base64');
116
116
  }
117
117
 
@@ -135,7 +135,7 @@ function doHttpsRequest(options: RequestOptions, resolve: any, reject: any): Cli
135
135
  function setRequestBody(request: ClientRequest, data: any) {
136
136
  if (data) {
137
137
  const requestContentType: string = request.getHeader('content-type')?.toString() ?? '';
138
- if (requestContentType === '' || requestContentType.includes('application/json')) {
138
+ if (requestContentType === '' || requestContentType.includes('json')) {
139
139
  //We serialize using JSON.stringify as a default, or if JSON is specified
140
140
  request.write(JSON.stringify(data));
141
141
  } else {