Skip to content

Commit

Permalink
fix: log rate response request (#40)
Browse files Browse the repository at this point in the history
Co-authored-by: Aliaksandr Stsiapanay <[email protected]>
  • Loading branch information
astsiapanay and astsiapanay authored Nov 21, 2023
1 parent f914774 commit 788e94e
Showing 1 changed file with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,10 @@ public void handle(String deploymentId) {
return;
}

if (deployment.getRateEndpoint() == null) {
context.respond(HttpStatus.OK);
proxy.getLogStore().save(context);
} else {
context.setDeployment(deployment);
context.getRequest().body()
.onSuccess(this::handleRequestBody)
.onFailure(this::handleRequestBodyError);
}
context.setDeployment(deployment);
context.getRequest().body()
.onSuccess(this::handleRequestBody)
.onFailure(this::handleRequestBodyError);
}

private Deployment getDeployment(String id) {
Expand Down Expand Up @@ -81,7 +76,13 @@ private void sendRequest() {

private void handleRequestBody(Buffer requestBody) {
context.setRequestBody(requestBody);
sendRequest();
Deployment deployment = context.getDeployment();
if (deployment.getRateEndpoint() == null) {
context.respond(HttpStatus.OK);
proxy.getLogStore().save(context);
} else {
sendRequest();
}
}

/**
Expand Down Expand Up @@ -110,11 +111,6 @@ private void handleProxyResponse(HttpClientResponse proxyResponse) {
log.info("Received response header from origin: status={}, headers={}", proxyResponse.statusCode(),
proxyResponse.headers().size());

if (proxyResponse.statusCode() == HttpStatus.TOO_MANY_REQUESTS.getCode()) {
sendRequest(); // try next
return;
}

BufferingReadStream proxyResponseStream = new BufferingReadStream(proxyResponse,
ProxyUtil.contentLength(proxyResponse, 1024));

Expand Down Expand Up @@ -155,7 +151,7 @@ private void handleRequestBodyError(Throwable error) {
*/
private void handleProxyConnectionError(Throwable error) {
log.warn("Can't connect to origin: {}", error.getMessage());
sendRequest(); // try next
context.respond(HttpStatus.BAD_GATEWAY, "connection error to origin");
}

/**
Expand Down

0 comments on commit 788e94e

Please sign in to comment.