Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8217951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:37:16+00:00 2026-06-07T12:37:16+00:00

I am building a HTTP proxy with netty, which supports HTTP pipelining. Therefore I

  • 0

I am building a HTTP proxy with netty, which supports HTTP pipelining. Therefore I receive multiple HttpRequest Objects on a single Channel and got the matching HttpResponse Objects. The order of the HttpResponse writes is the same than I got the HttpRequest. If a HttpResponse was written, the next one will be written when the HttpProxyHandler receives a writeComplete event.

The Pipeline should be convenient:

final ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("writer", new HttpResponseWriteDelayHandler());
pipeline.addLast("deflater", new HttpContentCompressor(9));
pipeline.addLast("handler", new HttpProxyHandler());

Regarding this question only the order of the write calls should be important, but to be sure I build another Handler (HttpResponseWriteDelayHandler) which suppresses the writeComplete event until the whole response was written.

To test this I enabled network.http.proxy.pipelining in Firefox and visited a page with many images and connections (a news page). The problem is, that the browser does not receive some responses in spite of the logs of the proxy consider them as sent successfully.

I have some findings:

  • The problem only occurs if the connection from proxy to server is faster than the connection from proxy to browser.
  • The problem occurs more often after sending a larger image on that connection, e.g. 20kB
  • The problem does not occur if only 304 - Not Modified responses were sent (refreshing the page considering browser cache)
  • Setting bootstrap.setOption("sendBufferSize", 1048576); or above does not help
  • Sleeping a timeframe dependent on the responses body size in before sending the writeComplete event in HttpResponseWriteDelayHandler solves the problem, but is a very bad solution.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:37:18+00:00Added an answer on June 7, 2026 at 12:37 pm

    I found the solution and want to share it, if anyone else has a similar problem:

    The content of the HttpResponse is too big. To analyze the content the whole HTML document was in the buffer. This must be splitted in Chunks again to send it properly. If the HttpResponse is not chunked I wrote a simple solution to do it. One needs to put a ChunkedWriteHandler next to the logic handler and write this class instead of the response itself:

    public class ChunkedHttpResponse implements ChunkedInput {
    
        private final static int       CHUNK_SIZE = 8196;
        private final HttpResponse     response;
        private final Queue<HttpChunk> chunks;
        private boolean                isResponseWritten;
    
        public ChunkedHttpResponse(final HttpResponse response) {
            if (response.isChunked())
                throw new IllegalArgumentException("response must not be chunked");
    
            this.chunks = new LinkedList<HttpChunk>();
            this.response = response;
            this.isResponseWritten = false;
    
            if (response.getContent().readableBytes() > CHUNK_SIZE) {
                while (CHUNK_SIZE < response.getContent().readableBytes()) {
                    chunks.add(new DefaultHttpChunk(response.getContent().readSlice(CHUNK_SIZE)));
                }
                chunks.add(new DefaultHttpChunk(response.getContent().readSlice(response.getContent().readableBytes())));
                chunks.add(HttpChunk.LAST_CHUNK);
    
                response.setContent(ChannelBuffers.EMPTY_BUFFER);
                response.setChunked(true);
                response.setHeader(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
            }
        }
    
        @Override
        public boolean hasNextChunk() throws Exception {
            return !isResponseWritten || !chunks.isEmpty();
        }
    
        @Override
        public Object nextChunk() throws Exception {
            if (!isResponseWritten) {
                isResponseWritten = true;
                return response;
            } else {
                HttpChunk chunk = chunks.poll();
                return chunk;
            }
        }
    
        @Override
        public boolean isEndOfInput() throws Exception {
            return isResponseWritten && chunks.isEmpty();
        }
    
        @Override
        public void close() {}
    }
    

    Then one can call just channel.write(new ChunkedHttpResponse(response) and the chunking is done automatically if needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building simple http status checker in C. I've got the network part done,
I'm building an application with a self-contained HTTP server which can be either accessed
When building HTTP API which respond only JSON format with Rails 3.2, should I
I got the following Request Queue implementation from this blog: http://dsgdev.wordpress.com/2006/10/28/building-a-javascript-http-request-queue/ and want to
I'm building an HTTP API which does a heavy site scraping in the background.
I'm building up my site over at http://royronalds.com , and I'm trying to figure
The application I'm building right now has problems when using HTTP post. When timeout
I'm building Flex 3 application and I have a geocoding service ( http://.../GeocodeServer )
I'm building a client that talks to the http server. Now my client needs
I am building a page using blocks of sections: http://jsfiddle.net/NrkTn/3/ You can see I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.