Skip to content

Commit

Permalink
Update Apache getRequestHeader and getResponseHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahchen6 committed Dec 18, 2024
1 parent dad5213 commit ccbffdb
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,16 @@ protected int status(final HttpContext context) {

@Override
protected String getRequestHeader(HttpUriRequest request, String headerName) {
Header header = request.getFirstHeader(headerName);
if (header != null) {
return header.getValue();
Header[] headers = request.getHeaders(headerName);
if (headers.length > 0) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < headers.length; i++) {
result.append(headers[i].getValue());
if (i + 1 < headers.length) {
result.append(",");
}
}
return result.toString();
}
return null;
}
Expand All @@ -71,9 +78,16 @@ protected String getRequestHeader(HttpUriRequest request, String headerName) {
protected String getResponseHeader(HttpContext context, String headerName) {
final Object responseObject = context.getAttribute(HttpCoreContext.HTTP_RESPONSE);
if (responseObject instanceof HttpResponse) {
Header header = ((HttpResponse) responseObject).getFirstHeader(headerName);
if (header != null) {
return header.getValue();
Header[] headers = ((HttpResponse) responseObject).getHeaders(headerName);
if (headers.length > 0) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < headers.length; i++) {
result.append(headers[i].getValue());
if (i + 1 < headers.length) {
result.append(",");
}
}
return result.toString();
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,32 @@ protected int status(final HttpResponse httpResponse) {

@Override
protected String getRequestHeader(HttpUriRequest request, String headerName) {
Header header = request.getFirstHeader(headerName);
if (null != header) {
return header.getValue();
Header[] headers = request.getHeaders(headerName);
if (headers.length > 0) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < headers.length; i++) {
result.append(headers[i].getValue());
if (i + 1 < headers.length) {
result.append(",");
}
}
return result.toString();
}
return null;
}

@Override
protected String getResponseHeader(HttpResponse response, String headerName) {
Header header = response.getFirstHeader(headerName);
if (null != header) {
return header.getValue();
Header[] headers = response.getHeaders(headerName);
if (headers.length > 0) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < headers.length; i++) {
result.append(headers[i].getValue());
if (i + 1 < headers.length) {
result.append(",");
}
}
return result.toString();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,32 @@ protected int status(final HttpResponse httpResponse) {

@Override
protected String getRequestHeader(HttpRequest request, String headerName) {
Header header = request.getFirstHeader(headerName);
if (null != header) {
return header.getValue();
Header[] headers = request.getHeaders(headerName);
if (headers.length > 0) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < headers.length; i++) {
result.append(headers[i].getValue());
if (i + 1 < headers.length) {
result.append(",");
}
}
return result.toString();
}
return null;
}

@Override
protected String getResponseHeader(HttpResponse response, String headerName) {
Header header = response.getFirstHeader(headerName);
if (null != header) {
return header.getValue();
Header[] headers = response.getHeaders(headerName);
if (headers.length > 0) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < headers.length; i++) {
result.append(headers[i].getValue());
if (i + 1 < headers.length) {
result.append(",");
}
}
return result.toString();
}
return null;
}
Expand Down

0 comments on commit ccbffdb

Please sign in to comment.