sebb        2004/02/22 06:37:51

  Modified:    src/protocol/http/org/apache/jmeter/protocol/http/sampler
                        HTTPSampler.java
  Log:
  Extract charset from Content-Type and store in dataEncoding
  
  Revision  Changes    Path
  1.86      +26 -13    
jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java
  
  Index: HTTPSampler.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java,v
  retrieving revision 1.85
  retrieving revision 1.86
  diff -u -r1.85 -r1.86
  --- HTTPSampler.java  10 Feb 2004 23:20:31 -0000      1.85
  +++ HTTPSampler.java  22 Feb 2004 14:37:51 -0000      1.86
  @@ -809,8 +809,7 @@
           boolean logError=false; // Should we log the error?
           try
           {
  -            if (conn.getContentEncoding() != null
  -                && conn.getContentEncoding().equals("gzip"))
  +            if ("gzip".equals(conn.getContentEncoding()))// works OK even if CE is 
null
               {
                   in=
                       new BufferedInputStream(
  @@ -1086,15 +1085,29 @@
   
               res.setResponseMessage(conn.getResponseMessage());
   
  -            String ct= conn.getHeaderField("Content-type");
  -            res.setContentType(ct);
  -            if (ct != null && ct.startsWith("image/"))
  -            {
  -                res.setDataType(HTTPSampleResult.BINARY);
  -            }
  -            else
  -            {
  -                res.setDataType(HTTPSampleResult.TEXT);
  +            String ct= conn.getContentType();//getHeaderField("Content-type");
  +            res.setContentType(ct);// e.g. text/html; charset=ISO-8859-1
  +            if (ct != null)
  +            {
  +             // Extract charset and store as DataEncoding
  +             // TODO do we need process http-equiv META tags, e.g.:
  +             // <META http-equiv="content-type" content="text/html; charset=foobar">
  +             // or can we leave that to the renderer ?
  +             String de=ct.toLowerCase();
  +             final String cs="charset=";
  +             int cset= de.indexOf(cs);
  +             if (cset >= 0)
  +             {
  +                     res.setDataEncoding(de.substring(cset+cs.length()));
  +             }
  +                     if (ct.startsWith("image/"))
  +                 {
  +                     res.setDataType(HTTPSampleResult.BINARY);
  +                 }
  +                 else
  +                 {
  +                     res.setDataType(HTTPSampleResult.TEXT);
  +                 }
               }
   
               res.setResponseHeaders(getResponseHeaders(conn));
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to