add http metod option, add monitor.method guard to buildResponse
This commit is contained in:
1 parent
32ec909bf7
commit
93b9c5033a
1 file changed
+18
@@ -53,6 +53,22 @@ export class HttpProvider implements IStatusProvider<HttpStatusPayload> {
|
|||||||
}
|
}
|
||||||
): MonitorStatusResponse<T> {
|
): MonitorStatusResponse<T> {
|
||||||
const { body, contentType, statusCode, statusUp, message, responseTime, timings } = opts;
|
const { body, contentType, statusCode, statusUp, message, responseTime, timings } = opts;
|
||||||
|
|
||||||
|
// Return early for HEAD requests, no body to parse
|
||||||
|
if (monitor.method === "HEAD") {
|
||||||
|
return {
|
||||||
|
monitorId: monitor.id,
|
||||||
|
teamId: monitor.teamId,
|
||||||
|
type: monitor.type,
|
||||||
|
status: statusUp,
|
||||||
|
code: statusCode,
|
||||||
|
message,
|
||||||
|
responseTime,
|
||||||
|
timings,
|
||||||
|
payload: body as T | string,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const isJson = contentType.includes("application/json");
|
const isJson = contentType.includes("application/json");
|
||||||
|
|
||||||
if (monitor.jsonPath && !isJson) {
|
if (monitor.jsonPath && !isJson) {
|
||||||
@@ -155,6 +171,8 @@ export class HttpProvider implements IStatusProvider<HttpStatusPayload> {
|
|||||||
https: ignoreTlsErrors ? this.httpsAgentInsecure : this.httpsAgent,
|
https: ignoreTlsErrors ? this.httpsAgentInsecure : this.httpsAgent,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
options.method = monitor.method;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.got<string>(url, options);
|
const response = await this.got<string>(url, options);
|
||||||
const statusUp = isStatusUp(response.statusCode, monitor.customUpCodes);
|
const statusUp = isStatusUp(response.statusCode, monitor.customUpCodes);
|
||||||
|
|||||||
Reference in new issue
Block a user