I can see a problem similar to this when I use the browser to connect
to my company's web portal. I had a patch for Android 1.x which fixed
this, but it doesn't work on Android 2.x.  I'd really like to find a
fix so I can access my web mail again.

-Howard

On Mar 3, 12:10 pm, SN <[email protected]> wrote:
> I can't find a way to attach a test project, so I just post the test
> file in here:
> package com.example.helloandroid;
>
> import java.io.IOException;
> import java.io.InputStream;
> import java.net.HttpURLConnection;
> import java.net.MalformedURLException;
> import java.net.URL;
> import java.util.zip.GZIPInputStream;
> import android.util.Log;
>
> public class Tester {
>
>         private final static String TAG = "GZIP";
>
>         public void testChunkedGZip(){
>                 InputStream is = null;
>                 try {
>                         byte[] buf = new byte[512];
>                         int read = -1;
>                         int readSize = 0;
>
>                         // Just pick a site, as long as it supported 
> accept-encoding=gzip
>                         // and the response is large enough to have Transfer-
> Encoding=chunked.
>                         HttpURLConnection conn = (HttpURLConnection) new 
> URL("http://
> vnexpress.net/GL/Home/").openConnection();
>                         conn.setRequestProperty("Accept-Encoding", "gzip");
>                         conn.setRequestProperty("Connection", "Keep-Alive");
>                         int response = conn.getResponseCode();
>                         Log.d(TAG, "======================");
>                         Log.d(TAG,"HTTP Response: " + response);
>
>                         Log.d(TAG,"header");
>                         for (String headerName : 
> conn.getHeaderFields().keySet()) {
>                                 for (String headerValue : 
> conn.getHeaderFields().get(headerName))
> {
>                                         Log.d(TAG,headerName + ":" + 
> headerValue);
>                                 }
>                         }
>
>                         Log.d(TAG,"body");
>                         is = conn.getInputStream();
>
>                         if (conn.getHeaderField("Content-encoding") != null &&
> conn.getHeaderField("Content-
> encoding").trim().toLowerCase().equals("gzip")){
>                                 is = new GZIPInputStream(is);
>                         }
>
>                         while ((read = is.read(buf)) != -1 ) {
>                                 readSize += read;
>                         }
>                         Log.d(TAG,"bytes read:" + readSize);
>
>                 } catch (MalformedURLException e) {
>                         e.printStackTrace();
>                 } catch (IOException e) {
>                         e.printStackTrace();
>                 } finally {
>                         try{
>                                 if (is != null) is.close();
>                         } catch(Exception e){}
>                 }
>         }
>
> }
>
> //////////////////////
> Testing Activity
> package com.example.helloandroid;
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.util.Log;
> import android.view.View;
> import android.widget.Button;
>
> public class HelloAndroid extends Activity {
>
>         private Button button;
>         private final static String TAG = "GZIP";
>
>         Runnable urlReaderRunnable = new Runnable(){
>
>                 public void run() {
>                         Tester tester = new Tester();
>                         try {
>                                 tester.testChunkedGZip();
>                         } catch (Exception e) {
>                                 Log.d(TAG, "Exception", e);
>                         }
>                 }
>         };
>
>         @Override
>         public void onCreate(Bundle savedInstanceState) {
>                 super.onCreate(savedInstanceState);
>                 this.setContentView(R.layout.main);
>                 this.button = (Button) this.findViewById(R.id.TestButton);
>
>                 this.button.setOnClickListener(new View.OnClickListener() {
>
>                         public void onClick(View v) {
>                                 // 2nd click always return -1
>                                 // this is only happens when Connection = 
> Keep-Alive, Content-
> Encoding=Gzip, Transfer-Encoding=Chunked
>                                 // the error comes from InflaterInputStream 
> (line 190-192) doesn't
> clean up
>                                 // the last chunk (ending chunk) correctly. 
> The last chunk is (0x)
> 30 0d 0a.
>
>                                 // This is tested with Android 1.6 and 2.1 
> with the same result.
>                                 Log.d(TAG, "Button is clicked");
>                                 new Thread(urlReaderRunnable).start();
>                         }
>                 });
>         }
>
> }
>
> On Mar 3, 6:05 am, SN <[email protected]> wrote:
>
>
>
> > Hi,
>
> > I found a problem with GZIP input stream when wrapping InputStream
> > from HttpURLConnection. When the server response with Transfer-
> > Encoding=chunked, Content-Encoding=gzip and Connection=Keep-Alive. The
> > second post always return -1.
>
> > After digging into the source code, I found the place that could be a
> > bug:
> >   InflaterInputStream.java (line 190 to 192)
> >               if (inf.needsInput()) {
> >                    fill();
> >                }
>
> > Because InflaterInputStream doesn't need more input, it doesn't try to
> > read the end of chunked encoding (0x)(30 0a 0d) that cause the second
> > post to return with -1 every time. Does anybody have the same issue?
>
> > Thanks,

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to