Skip to content

Commit

Permalink
issue #496 make the RequestSummary a life view rather than a snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
ryber committed Oct 10, 2023
1 parent 7ec37ac commit 86d2601
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
16 changes: 12 additions & 4 deletions unirest-bdd-tests/src/test/java/BehaviorTests/HeaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,19 +407,27 @@ void nullHeaderValues() {

@Test
void getHeadersInSummary() {
Unirest.config().setDefaultHeader("cheese", "wiz");
Unirest.config()
.setDefaultHeader("cheese", "wiz")
.interceptor(new Interceptor() {
@Override
public void onRequest(HttpRequest<?> request, Config config) {
request.header("beatles", "Ringo");
}
});

var headers = Unirest.get(MockServer.GET)
.header("foo", "bar")
.header("baz", "qux")
.toSummary()
.asEmpty()
.getRequestSummary()
.getHeaders();

assertEquals(3, headers.size());
assertEquals(4, headers.size());
assertContains(headers, "cheese", "wiz");
assertContains(headers, "foo", "bar");
assertContains(headers, "baz", "qux");

assertContains(headers, "beatles", "ringo");
}

private void assertContains(Collection<Header> headers, String key, String value) {
Expand Down
17 changes: 5 additions & 12 deletions unirest/src/main/java/kong/unirest/core/RequestSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,26 @@

class RequestSummary implements HttpRequestSummary {
private static final SummaryFormatter FORMATTER = new SummaryFormatter();
private final String rawPath;
private final BaseRequest request;
private final String url;
private final HttpMethod method;
private Collection<Header> headers;


RequestSummary(BaseRequest request) {
this.url = request.getUrl();
this.method = request.getHttpMethod();
this.rawPath = request.getPath().rawPath();
this.request = request;
this.headers = List.copyOf(request.getHeaders().all());
}

@Override
public HttpMethod getHttpMethod() {
return method;
return request.getHttpMethod();
}

@Override
public String getUrl() {
return url;
return request.getUrl();
}

@Override
public String getRawPath() {
return rawPath;
return request.getPath().rawPath();
}

@Override
Expand All @@ -66,6 +59,6 @@ public String asString() {

@Override
public Collection<Header> getHeaders() {
return headers;
return List.copyOf(request.getHeaders().all());
}
}
9 changes: 0 additions & 9 deletions unirest/src/main/java/kong/unirest/core/SummaryFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,4 @@ private String toMultiPartAproximation(Body b, StringJoiner sj) {
});
return sj.toString();
}

//--4-yp9f7bDX_Brgpd7oOwkUyZJPCHfBV_X
//Content-Disposition: form-data; name="album"
//
//77
//--4-yp9f7bDX_Brgpd7oOwkUyZJPCHfBV_X
//Content-Disposition: form-data; name="band"
//
//Talking Heads
}

0 comments on commit 86d2601

Please sign in to comment.