use of io.servicetalk.http.api.HttpHeaderNames.ALLOW in project servicetalk by apple.
the class BlockingProtobufStreamingServer method main.
public static void main(String[] args) throws Exception {
HttpServers.forPort(8080).listenBlockingStreamingAndAwait((ctx, request, response) -> {
if (!"/protobuf".equals(request.requestTarget())) {
response.status(NOT_FOUND).sendMetaData().close();
} else if (!POST.equals(request.method())) {
response.status(METHOD_NOT_ALLOWED).addHeader(ALLOW, POST.name()).sendMetaData().close();
} else {
BlockingIterable<RequestMessage> values = request.payloadBody(REQ_STREAMING_SERIALIZER);
response.status(CREATED);
try (HttpPayloadWriter<ResponseMessage> writer = response.sendMetaData(RESP_STREAMING_SERIALIZER)) {
for (RequestMessage req : values) {
writer.write(ResponseMessage.newBuilder().setLength(req.getMessage().length()).build());
}
}
}
}).awaitShutdown();
}
use of io.servicetalk.http.api.HttpHeaderNames.ALLOW in project servicetalk by apple.
the class BlockingPojoStreamingServer method main.
public static void main(String[] args) throws Exception {
HttpServers.forPort(8080).listenBlockingStreamingAndAwait((ctx, request, response) -> {
if (!"/pojos".equals(request.requestTarget())) {
response.status(NOT_FOUND).sendMetaData().close();
} else if (!POST.equals(request.method())) {
response.status(METHOD_NOT_ALLOWED).addHeader(ALLOW, POST.name()).sendMetaData().close();
} else {
BlockingIterable<CreatePojoRequest> values = request.payloadBody(REQ_STREAMING_SERIALIZER);
response.status(CREATED);
try (HttpPayloadWriter<PojoResponse> writer = response.sendMetaData(RESP_STREAMING_SERIALIZER)) {
for (CreatePojoRequest req : values) {
writer.write(new PojoResponse(ID_GENERATOR.getAndIncrement(), req.getValue()));
}
}
}
}).awaitShutdown();
}
Aggregations