Turn Browser Curl Calls into Fast Java Performance Tests
This article explains how to capture browser curl requests, parse them into Java HttpRequestBase objects, and run high‑concurrency performance tests using a custom FunTester framework, complete with code examples, metrics, and repository links.
Copying Browser Requests as cURL
To avoid manually constructing request payloads, the raw curl commands displayed in the browser’s network panel are copied and saved to a plain‑text file. Both GET and POST examples are shown (domains omitted). The curl format is chosen because it is compact and easy to parse.
curl 'https://example.cn/home/course_list?...' \
-H 'Connection: keep-alive' \
-H 'User-Agent: Mozilla/5.0 ...' \
-H 'Cookie: db_log=1; org_id=640; ...' \
--compressed curl 'https://example.cn/myResourcePool/deleteResource' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
-H 'Cookie: db_log=1; org_id=640; ...' \
--data-raw 'res_id=2317045&res_type=3' \
--compressedParsing cURL into a Request Object
The file is read line‑by‑line. Each line is examined and the information is stored in a CurlRequestBase data holder:
static class CurlRequestBase {
String url
RequestType type = RequestType.GET
List<Header> headers = new ArrayList<>()
JSONObject params = new JSONObject()
}The parser extracts the URL, header key/value pairs, and POST body parameters (splitting on ‘&’). After the file is processed, the holder is converted to an Apache HttpRequestBase using the helper class FunRequest:
public static HttpRequestBase getRequest(String path) {
def lines = WriteRead.readTxtFileByLine(LONG_Path + path).stream().map { it.trim() }
def base = new CurlRequestBase()
lines.each { line ->
if (line.startsWith('curl')) {
def parts = line.split(' ', 2)
def urlPart = parts[1]
base.url = urlPart.substring(urlPart.indexOf('h'), urlPart.lastIndexOf("'"))
} else if (line.startsWith('-H')) {
def kv = line.split(' ', 2)[1].split(': ')
base.headers << getHeader(kv[0].substring(1), kv[1].substring(0, kv[1].lastIndexOf("'")))
} else if (line.startsWith('--data-raw')) {
base.params = getJson(line.substring(line.indexOf("'")+1, line.lastIndexOf("'"))).split('&')
base.type = RequestType.POST
}
}
return base.type == RequestType.GET ?
FunRequest.isGet().setUri(base.url).addHeader(base.headers).getRequest() :
FunRequest.isPost().setUri(base.url).addHeader(base.headers).addParams(base.params).getRequest()
}Integrating with the Performance‑Testing Framework
The generated HttpRequestBase is fed into an existing load‑testing harness. The demo launches 30 concurrent threads, each issuing the request 100 times (total 3 000 executions):
public static void main(String[] args) {
def request = getRequest("get")
output FanLibrary.getHttpResponse(request)
def thread = new RequestThreadTimes<HttpRequestBase>(request, 100)
new Concurrent(thread, 30, "FunTester get request test").start()
testOver()
}After the run, the framework prints a JSON summary containing total time, QPS, failure rate and response‑time distribution. Example metrics from a sample execution:
QPS: 225.86
Total requests: 3 000
Fail rate: 0 %
Response time (median): 93 ms – 204 ms
Source Code and Repository
The complete implementation and additional documentation are hosted at:
Gitee: https://gitee.com/fanapi/tester GitHub:
https://github.com/JunManYuanLong/FunTesterSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
