mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-07-28 16:37:42 +00:00
test curlify function
This commit is contained in:
@@ -1,37 +1,25 @@
|
||||
export function curlify(recordDetail) {
|
||||
const headers = { ...recordDetail.reqHeader };
|
||||
const acceptEncoding = headers['Accept-Encoding'] || headers['accept-encoding'];
|
||||
// escape reserve character in url
|
||||
const url = recordDetail.url.replace(/([\[\]])/g, '\\$1');
|
||||
const curlified = ['curl', `'${url}'`];
|
||||
|
||||
export function curlify(recordDetail){
|
||||
let curlified = []
|
||||
let type = ''
|
||||
let headers = { ...recordDetail.reqHeader }
|
||||
curlified.push('curl')
|
||||
curlified.push('-X', recordDetail.method)
|
||||
curlified.push(`'${recordDetail.url}'`)
|
||||
|
||||
if (headers) {
|
||||
type = headers['Content-Type']
|
||||
delete headers['Accept-Encoding']
|
||||
|
||||
for(let k of Object.keys(headers)){
|
||||
let v = headers[k]
|
||||
curlified.push('-H')
|
||||
curlified.push(`'${k}: ${v}'`)
|
||||
}
|
||||
if (recordDetail.method.toUpperCase() !== 'GET') {
|
||||
curlified.push('-X', recordDetail.method);
|
||||
}
|
||||
|
||||
if (recordDetail.reqBody){
|
||||
Object.keys(headers).forEach((key) => {
|
||||
curlified.push('-H', `'${key}: ${headers[key]}'`);
|
||||
});
|
||||
|
||||
if(type === 'multipart/form-data' && recordDetail.method === 'POST') {
|
||||
let formDataBody = recordDetail.reqBody.split('&')
|
||||
|
||||
for(let data of formDataBody) {
|
||||
curlified.push('-F')
|
||||
curlified.push(data)
|
||||
}
|
||||
} else {
|
||||
curlified.push('-d')
|
||||
curlified.push(recordDetail.reqBody)
|
||||
}
|
||||
if (recordDetail.reqBody) {
|
||||
curlified.push('-d', `'${recordDetail.reqBody}'`);
|
||||
}
|
||||
|
||||
return curlified.join(' ')
|
||||
if (/deflate|gzip/.test(acceptEncoding)) {
|
||||
curlified.push('--compressed');
|
||||
}
|
||||
|
||||
return curlified.join(' ');
|
||||
}
|
||||
|
Reference in New Issue
Block a user