Skip to content

Commit f68f2db

Browse files
author
unknown
committed
Merge branch 'master' of github.com:Arronlong/httpclientUtil
Lines starting with '#' will be ignored, and an empty message aborts
2 parents 67d0e90 + 0243e4e commit f68f2db

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/main/java/com/tgb/ccl/http/common/HttpConfig.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public static HttpConfig custom(){
4949
* Header头信息
5050
*/
5151
private Header[] headers;
52+
53+
/**
54+
* 是否返回response的headers
55+
*/
56+
private boolean isReturnRespHeaders;
5257

5358
/**
5459
* 请求方法
@@ -127,6 +132,15 @@ public HttpConfig headers(Header[] headers) {
127132
return this;
128133
}
129134

135+
/**
136+
* Header头信息(是否返回response中的headers)
137+
*/
138+
public HttpConfig headers(Header[] headers, boolean isReturnRespHeaders) {
139+
this.headers = headers;
140+
this.isReturnRespHeaders=isReturnRespHeaders;
141+
return this;
142+
}
143+
130144
/**
131145
* 请求方法
132146
*/
@@ -214,6 +228,9 @@ public CloseableHttpAsyncClient asynclient() {
214228
public Header[] headers() {
215229
return headers;
216230
}
231+
public boolean isReturnRespHeaders() {
232+
return isReturnRespHeaders;
233+
}
217234

218235
public String url() {
219236
return url;

src/main/java/com/tgb/ccl/http/httpclient/HttpClientUtil.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,11 @@ private static HttpResponse execute(HttpConfig config) throws HttpProcessExcepti
372372
//执行请求操作,并拿到结果(同步阻塞)
373373
resp = (config.context()==null)?config.client().execute(request) : config.client().execute(request, config.context()) ;
374374

375+
if(config.isReturnRespHeaders()){
376+
//获取所有response的header信息
377+
config.headers(resp.getAllHeaders());
378+
}
379+
375380
//获取结果实体
376381
return resp;
377382

@@ -428,7 +433,7 @@ public static OutputStream fmt2Stream(HttpResponse resp, OutputStream out) throw
428433
}
429434
return out;
430435
}
431-
436+
432437
/**
433438
* 根据请求方法名,获取request对象
434439
*

0 commit comments

Comments
 (0)