~smaioli/azureus/ubuntu-experimental

« back to all changes in this revision

Viewing changes to com/aelitis/azureus/core/util/HTTPUtils.java

MergedĀ VuzeĀ 4.2.0.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import java.io.ByteArrayOutputStream;
27
27
import java.io.IOException;
28
28
import java.io.InputStream;
 
29
import java.net.Socket;
29
30
import java.util.HashMap;
30
31
import java.util.HashSet;
31
32
import java.util.Map;
32
33
import java.util.Set;
33
34
 
 
35
import org.gudy.azureus2.core3.util.FileUtil;
 
36
 
34
37
public class HTTPUtils {
35
38
        public static final String      NL                              = "\r\n";
36
39
 
160
163
                return compression.contains(file_type);
161
164
        }
162
165
 
163
 
        public static InputStream decodeChunkedEncoding(InputStream is)
 
166
        public static InputStream 
 
167
        decodeChunkedEncoding(
 
168
                Socket          socket )
164
169
 
165
 
        throws IOException {
 
170
                throws IOException 
 
171
        {
 
172
                InputStream     is = socket.getInputStream();
 
173
                
166
174
                String reply_header = "";
167
175
 
168
176
                while (true) {
186
194
 
187
195
                String first_line = reply_header.substring(0, p1).trim();
188
196
 
189
 
                if (first_line.indexOf("200") == -1) {
 
197
                if ( first_line.indexOf( "200" ) == -1 ){
190
198
 
191
 
                        throw (new IOException("HTTP request failed:" + first_line));
 
199
                        String  info = null;
 
200
                        
 
201
                        try{
 
202
                                        // limit time spent trying to read debug
 
203
                                
 
204
                                int timeout = socket.getSoTimeout();
 
205
                                
 
206
                                socket.setSoTimeout( 500 );
 
207
                                
 
208
                                info = FileUtil.readInputStreamAsStringWithTruncation( is, 512 );
 
209
                                
 
210
                                socket.setSoTimeout( timeout );
 
211
                                
 
212
                        }catch( Throwable e ){
 
213
                        }
 
214
                        
 
215
                        String error = "HTTP request failed: " + first_line;
 
216
                        
 
217
                        if ( info != null ){
 
218
                                
 
219
                                error += " - " + info;
 
220
                        }
 
221
                        
 
222
                        throw ( new IOException( error ));
192
223
                }
193
224
 
194
225
                String lc_reply_header = reply_header.toLowerCase();