feat: add custom header
This commit is contained in:
parent
2600e3e6fa
commit
addda5c45a
@ -56,8 +56,34 @@ const MonitorHttp: React.FC = React.memo(() => {
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label="Headers"
|
||||
name={['payload', 'headers']}
|
||||
rules={[
|
||||
{
|
||||
validator(rule, value, callback) {
|
||||
try {
|
||||
const obj = JSON.parse(value);
|
||||
if (typeof obj !== 'object') {
|
||||
callback('Not JSON Object');
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
} catch {
|
||||
callback('Not valid JSON string');
|
||||
}
|
||||
},
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Input.TextArea
|
||||
rows={4}
|
||||
placeholder='For example: { "key": "value" }'
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="Body" name={['payload', 'bodyValue']}>
|
||||
<Input.TextArea
|
||||
rows={4}
|
||||
placeholder='For example: { "key": "value" }'
|
||||
/>
|
||||
</Form.Item>
|
||||
|
@ -10,6 +10,7 @@ export const http: MonitorProvider<{
|
||||
method?: string;
|
||||
timeout?: number; // second
|
||||
contentType?: string;
|
||||
headers?: string;
|
||||
bodyValue?: string;
|
||||
maxRedirects?: number;
|
||||
ignoreTLS?: boolean;
|
||||
@ -24,6 +25,7 @@ export const http: MonitorProvider<{
|
||||
method = 'get',
|
||||
timeout = 30,
|
||||
contentType,
|
||||
headers,
|
||||
bodyValue,
|
||||
maxRedirects,
|
||||
ignoreTLS,
|
||||
@ -44,6 +46,20 @@ export const http: MonitorProvider<{
|
||||
// },
|
||||
};
|
||||
|
||||
if (headers) {
|
||||
try {
|
||||
const customHeaders = JSON.parse(headers);
|
||||
if (typeof customHeaders === 'object') {
|
||||
config.headers = {
|
||||
...config.headers,
|
||||
...customHeaders,
|
||||
};
|
||||
}
|
||||
} catch (err) {
|
||||
logger.warn('Unabled header:', headers);
|
||||
}
|
||||
}
|
||||
|
||||
if (bodyValue) {
|
||||
config.data = bodyValue;
|
||||
}
|
||||
@ -55,6 +71,8 @@ export const http: MonitorProvider<{
|
||||
|
||||
config.httpsAgent = new https.Agent(httpsAgentOptions);
|
||||
|
||||
console.log('config', config);
|
||||
|
||||
try {
|
||||
const startTime = dayjs();
|
||||
const res = await axios({ ...config });
|
||||
|
Loading…
Reference in New Issue
Block a user