Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify response(Bad Gateway:xxxxxxx) #359

Closed
wolflowhereu opened this issue Mar 22, 2017 · 2 comments · Fixed by LittleProxy/LittleProxy#142
Closed

modify response(Bad Gateway:xxxxxxx) #359

wolflowhereu opened this issue Mar 22, 2017 · 2 comments · Fixed by LittleProxy/LittleProxy#142

Comments

@wolflowhereu
Copy link

`private boolean respondWithShortCircuitResponse(HttpResponse httpResponse) {
// we are sending a response to the client, so we are done handling this request
this.currentRequest = null;

    HttpResponse filteredResponse = (HttpResponse) currentFilters.proxyToClientResponse(httpResponse);
    if (filteredResponse == null) {
        disconnect();
        return false;
    }

    // allow short-circuit messages to close the connection. normally the Connection header would be stripped when modifying
    // the message for proxying, so save the keep-alive status before the modifications are made.
    boolean isKeepAlive = HttpHeaders.isKeepAlive(httpResponse);

    // if the response is not a Bad Gateway or Gateway Timeout, modify the headers "as if" the short-circuit response were proxied
    int statusCode = httpResponse.getStatus().code();
    if (statusCode != HttpResponseStatus.BAD_GATEWAY.code() && statusCode != HttpResponseStatus.GATEWAY_TIMEOUT.code()) {
        modifyResponseHeadersToReflectProxying(httpResponse);
    }

    // restore the keep alive status, if it was overwritten when modifying headers for proxying
    HttpHeaders.setKeepAlive(httpResponse, isKeepAlive);

    write(httpResponse);

    if (ProxyUtils.isLastChunk(httpResponse)) {
        writeEmptyBuffer();
    }

    if (!HttpHeaders.isKeepAlive(httpResponse)) {
        disconnect();
        return false;
    }

    return true;
}`

HttpResponse filteredResponse = (HttpResponse) currentFilters.proxyToClientResponse(httpResponse);

I try to use filteredResponse repeat httpResponse, but this not support; why not use filteredResponse to write????

@wolflowhereu
Copy link
Author

write(filteredResponse);

@AleksejsGrocevs
Copy link

Fix proposed in #383 pull request

asolntsev added a commit to LittleProxy/LittleProxy that referenced this issue Aug 9, 2022
Re-do the original PR adamfisk#383

this should fix adamfisk#359
asolntsev added a commit to LittleProxy/LittleProxy that referenced this issue Aug 9, 2022
Re-do the original PR adamfisk#383

this should fix adamfisk#359
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants