adamfisk / LittleProxy

High performance HTTP proxy originally written by your friends at Lantern and now maintained by a stellar group of volunteer open source programmers.

Home Page:https://www.getlantern.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

http response which ssl not-used is garbled.

kccstaro opened this issue · comments

I checked the charset of target site is utf-8.
Anybody knows why is this garbled?

The following is my HttpFiltersMethodInvokedAdapter.

class HttpFilterAdapter extends HttpFiltersMethodInvokedAdapter{

  @Override
  public HttpObject serverToProxyResponse(HttpObject httpObject) {	
    if(httpObject instanceof DefaultHttpContent) {
      DefaultHttpContent h = (DefaultHttpContent)httpObject;

      if(requestMap.get(id).host.equals("apache.org")) {
        ByteBuf buf = h.content();
        byte[] array;
        int offset;
        int length;
						
        if(buf.hasArray()) {
          array = buf.array();
          offset = buf.arrayOffset() + buf.readerIndex();
          length = buf.readableBytes();

          } else {
            array = new byte[buf.readableBytes()];
            offset = 0;
            length = array.length;
            buf.getBytes(offset, array);
            }
						
        System.out.println(array.length);

        for(int i = 0; i < array.length && i < 1000; i++) {
          if(array.length < 1000) {
            break;
          }

          System.out.print(Integer.toHexString((char)array[i]) +" ");
							
          }
}

And this is response.

34 ffe8 19 41 ff8f 73 ffd6 ff8f ffbf ffd3 39 ffeb 5a 38 ff81 73 ff86 1 8 ffe7 6c ff96 ffce 76 ff8b ff87 10 ffa5 75 1b 42 5c ff8c ffd7 14 ffd6 ff9b ff9c 60 c 2d 34 fff2 41 ff8e 5e ffd0 15 ffeb 75 75 41 fff6 7a 5d ffdc ff88 ffef 6a ff82 45 fff5 36 ffdd 56 42 4f ffef ffaa ffcb 71 ffeb 3e 2d 3d ffda 2f 4b ffc4 9 ffb3 1 39 
4��A�s֏��9�Z8�s����l��v����u�B\���֛�`-4�A�^���uuA�z]܈�j�E�6�VBO��q�>-=�/K�	��9_������u��#��]<��E��f