Skip to content

Commit 78aca86

Browse files
committed
WIP response header validation: resolve request
1 parent c399f39 commit 78aca86

4 files changed

Lines changed: 53 additions & 18 deletions

File tree

runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/config/HttpBindingConfig.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,28 @@ private List<HttpRequestType> createRequestTypes(
225225
List<HttpRequestType.Response> responses = new LinkedList<>();
226226
if (request.responses != null)
227227
{
228-
for (HttpResponseConfig config : request.responses)
228+
for (HttpResponseConfig response0 : request.responses)
229229
{
230-
HttpRequestType.Response response = new HttpRequestType.Response(config.status, config.contentType,
231-
createValidator.apply(config.content, this.resolveId));
230+
Map<String8FW, Validator> responseHeaderValidators = new HashMap<>();
231+
if (response0.headers != null)
232+
{
233+
for (HttpParamConfig header : response0.headers)
234+
{
235+
String8FW name = new String8FW(header.name);
236+
Validator validator = createValidator.apply(header.validator, this.resolveId);
237+
if (validator != null)
238+
{
239+
responseHeaderValidators.put(name, validator);
240+
}
241+
}
242+
}
243+
Validator contentValidator = null;
244+
if (response0.content != null)
245+
{
246+
contentValidator = createValidator.apply(response0.content, this.resolveId);
247+
}
248+
HttpRequestType.Response response = new HttpRequestType.Response(response0.status, response0.contentType,
249+
responseHeaderValidators, contentValidator);
232250
responses.add(response);
233251
}
234252
}
@@ -272,11 +290,11 @@ public HttpRequestType resolveRequestType(
272290
return result;
273291
}
274292

275-
public Validator resolveResponseValidator(
293+
public HttpRequestType.Response resolveResponse(
276294
HttpRequestType requestType,
277295
HttpBeginExFW beginEx)
278296
{
279-
Validator result = null;
297+
HttpRequestType.Response result = null;
280298
if (requestType != null && requestType.responses != null)
281299
{
282300
String status = resolveHeaderValue(beginEx, HEADER_STATUS);
@@ -286,7 +304,7 @@ public Validator resolveResponseValidator(
286304
if (matchResponseStatus(response, status) &&
287305
matchResponseContentType(response, contentType))
288306
{
289-
result = response.content;
307+
result = response;
290308
}
291309
}
292310
}

runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/config/HttpRequestType.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,18 @@ public static final class Response
7979
{
8080
public final List<String> status;
8181
public final List<String> contentType;
82+
public final Map<String8FW, Validator> headers;
8283
public final Validator content;
8384

84-
public Response(List<String> status, List<String> contentType, Validator content)
85+
public Response(
86+
List<String> status,
87+
List<String> contentType,
88+
Map<String8FW, Validator> headers,
89+
Validator content)
8590
{
8691
this.status = status;
8792
this.contentType = contentType;
93+
this.headers = headers;
8894
this.content = content;
8995
}
9096
}

runtime/binding-http/src/main/java/io/aklivity/zilla/runtime/binding/http/internal/stream/HttpClientFactory.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,7 +2896,7 @@ private void onDecodeHttp11Headers(
28962896
pool.onUpgradedOrClosed(this);
28972897
}
28982898

2899-
exchange.resolveResponseValidator(beginEx);
2899+
exchange.resolveResponse(beginEx);
29002900
}
29012901

29022902
private void onDecodeHttp11HeadersOnly(
@@ -2918,9 +2918,9 @@ private int onDecodeHttp11Body(
29182918
{
29192919
int result;
29202920
boolean valid = true;
2921-
if (exchange.responseValidator != null)
2921+
if (exchange.response != null && exchange.response.content != null)
29222922
{
2923-
valid = exchange.responseValidator.read(buffer, offset, limit - offset);
2923+
valid = exchange.response.content.read(buffer, offset, limit - offset);
29242924
}
29252925
if (valid)
29262926
{
@@ -3354,9 +3354,9 @@ private int onDecodeHttp2Data(
33543354
else
33553355
{
33563356
boolean valid = true;
3357-
if (exchange.responseValidator != null)
3357+
if (exchange.response != null && exchange.response.content != null)
33583358
{
3359-
valid = exchange.responseValidator.read(payload, 0, payloadLength);
3359+
valid = exchange.response.content.read(payload, 0, payloadLength);
33603360
}
33613361
if (valid)
33623362
{
@@ -3467,7 +3467,7 @@ else if (headersDecoder.httpError())
34673467
.headers(hs -> headers.forEach((n, v) -> hs.item(h -> h.name(n).value(v))))
34683468
.build();
34693469

3470-
exchange.resolveResponseValidator(beginEx);
3470+
exchange.resolveResponse(beginEx);
34713471
exchange.doResponseBegin(traceId, authorization, beginEx);
34723472

34733473
if (endResponse)
@@ -4497,7 +4497,7 @@ private final class HttpExchange
44974497

44984498
private final HttpBindingConfig binding;
44994499
private HttpRequestType requestType;
4500-
private Validator responseValidator;
4500+
private HttpRequestType.Response response;
45014501

45024502
private HttpExchange(
45034503
HttpClient client,
@@ -5049,10 +5049,10 @@ private void cleanup(
50495049
doResponseAbort(traceId, authorization, EMPTY_OCTETS);
50505050
}
50515051

5052-
public void resolveResponseValidator(
5052+
public void resolveResponse(
50535053
HttpBeginExFW beginEx)
50545054
{
5055-
this.responseValidator = binding.resolveResponseValidator(requestType, beginEx);
5055+
this.response = binding.resolveResponse(requestType, beginEx);
50565056
}
50575057
}
50585058

specs/binding-http.spec/src/main/scripts/io/aklivity/zilla/specs/binding/http/schema/http.schema.patch.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,20 @@
366366
"$ref": "#/$defs/validator/type"
367367
}
368368
},
369-
"required":
369+
"anyOf":
370370
[
371-
"content"
371+
{
372+
"required":
373+
[
374+
"content"
375+
]
376+
},
377+
{
378+
"required":
379+
[
380+
"headers"
381+
]
382+
}
372383
],
373384
"additionalProperties": false
374385
}

0 commit comments

Comments
 (0)