Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * HttpRequest.java | 2 * HttpRequest.java |
3 * | 3 * |
4 * Brazil project web application toolkit, | 4 * Brazil project web application toolkit, |
5 * export version: 2.3 | 5 * export version: 2.3 |
6 * Copyright (c) 1999-2007 Sun Microsystems, Inc. | 6 * Copyright (c) 1999-2007 Sun Microsystems, Inc. |
7 * | 7 * |
8 * Sun Public License Notice | 8 * Sun Public License Notice |
9 * | 9 * |
10 * The contents of this file are subject to the Sun Public License Version | 10 * The contents of this file are subject to the Sun Public License Version |
11 * 1.0 (the "License"). You may not use this file except in compliance with | 11 * 1.0 (the "License"). You may not use this file except in compliance with |
12 * the License. A copy of the License is included as the file "license.terms", | 12 * the License. A copy of the License is included as the file "license.terms", |
13 * and also available at http://www.sun.com/ | 13 * and also available at http://www.sun.com/ |
14 * | 14 * |
15 * The Original Code is from: | 15 * The Original Code is from: |
16 * Brazil project web application toolkit release 2.3. | 16 * Brazil project web application toolkit release 2.3. |
17 * The Initial Developer of the Original Code is: cstevens. | 17 * The Initial Developer of the Original Code is: cstevens. |
18 * Portions created by cstevens are Copyright (C) Sun Microsystems, Inc. | 18 * Portions created by cstevens are Copyright (C) Sun Microsystems, Inc. |
19 * All Rights Reserved. | 19 * All Rights Reserved. |
20 * | 20 * |
21 * Contributor(s): cstevens, drach, suhler. | 21 * Contributor(s): cstevens, drach, suhler. |
22 * | 22 * |
23 * Version: 2.7 | 23 * Version: 2.7 |
24 * Created by cstevens on 99/09/15 | 24 * Created by cstevens on 99/09/15 |
25 * Last modified by suhler on 07/03/26 13:53:18 | 25 * Last modified by suhler on 07/03/26 13:53:18 |
26 * | 26 * |
27 * Version Histories: | 27 * Version Histories: |
28 * | |
29 * 13/04/09-12:44:12 (andrey@adblockplus.org) | |
30 * implemented proxying chunked request body | |
28 * | 31 * |
29 * 2.7 07/03/26-13:53:18 (suhler) | 32 * 2.7 07/03/26-13:53:18 (suhler) |
30 * doc updates | 33 * doc updates |
31 * | 34 * |
32 * 2.6 07/03/26-13:44:17 (suhler) | 35 * 2.6 07/03/26-13:44:17 (suhler) |
33 * add sample main() to act as a simple "wget" | 36 * add sample main() to act as a simple "wget" |
34 * | 37 * |
35 * 2.5 04/11/30-15:19:40 (suhler) | 38 * 2.5 04/11/30-15:19:40 (suhler) |
36 * fixed sccs version string | 39 * fixed sccs version string |
37 * | 40 * |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
872 requestHeaders.print(p); | 875 requestHeaders.print(p); |
873 p.print("\r\n"); | 876 p.print("\r\n"); |
874 | 877 |
875 if (postData != null) { | 878 if (postData != null) { |
876 postData.writeTo(p); | 879 postData.writeTo(p); |
877 postData = null; // Release memory. | 880 postData = null; // Release memory. |
878 } | 881 } |
879 | 882 |
880 // Pass any data left in client stream (in case of chunked request conte nt) | 883 // Pass any data left in client stream (in case of chunked request conte nt) |
881 String encoding = requestHeaders.get("Transfer-Encoding", ""); | 884 String encoding = requestHeaders.get("Transfer-Encoding", ""); |
882 if (encoding != null && encoding.equals("chunked") && cs != null) | 885 if (encoding != null && encoding.equals("chunked") && cs != null) |
Felix Dahlke
2013/04/09 09:16:48
You could just do '"chunked".equals(encoding)' to
Andrey Novikov
2013/04/10 08:30:30
Done.
| |
883 { | 886 { |
884 byte[] buf = new byte[4096]; | 887 byte[] buf = new byte[4096]; |
Felix Dahlke
2013/04/09 09:16:48
Indentation is off here
| |
885 int bytesLeft = -1; | 888 int bytesLeft = -1; |
886 while (true) | 889 while (true) |
887 { | 890 { |
888 // Read chunk size | 891 // Read chunk size |
889 if (bytesLeft <= 0) | 892 if (bytesLeft <= 0) |
890 { | 893 { |
891 bytesLeft = getChunkSize(cs); | 894 bytesLeft = getChunkSize(cs); |
892 // Output chunk size | 895 // Output chunk size |
893 p.print(Integer.toHexString(bytesLeft) + "\r\n") ; | 896 p.print(Integer.toHexString(bytesLeft) + "\r\n") ; |
894 } | 897 } |
(...skipping 23 matching lines...) Expand all Loading... | |
918 p.print(line + "\r\n"); | 921 p.print(line + "\r\n"); |
919 if (line.length() == 0) | 922 if (line.length() == 0) |
920 break; | 923 break; |
921 } | 924 } |
922 } | 925 } |
923 } | 926 } |
924 | 927 |
925 p.flush(); | 928 p.flush(); |
926 } | 929 } |
927 | 930 |
931 /* | |
932 * Copied (with some amendmends) from UnchunkingInputStream / andrey@adblock plus.org | |
933 */ | |
928 private int | 934 private int |
929 getChunkSize(HttpInputStream is) | 935 getChunkSize(HttpInputStream is) |
930 throws IOException | 936 throws IOException |
931 { | 937 { |
932 /* | 938 /* |
933 * Although HTTP/1.1 chunking spec says that there is one "\r\n" | 939 * Although HTTP/1.1 chunking spec says that there is one "\r\n" |
934 * between chunks, some servers (for example, maps.yahoo.com) | 940 * between chunks, some servers (for example, maps.yahoo.com) |
935 * send more than one blank line between chunks. So, read and skip | 941 * send more than one blank line between chunks. So, read and skip |
936 * all the blank lines seen between chunks. | 942 * all the blank lines seen between chunks. |
937 */ | 943 */ |
938 | 944 |
939 int bytesLeft = 0; | 945 int bytesLeft = 0; |
940 String line; | 946 String line; |
941 do { | 947 do { |
942 // Sanity check: limit chars when expecting a chunk size. | 948 // Sanity check: limit chars when expecting a chunk size. |
943 line = is.readLine(HttpRequest.LINE_LIMIT); | 949 line = is.readLine(HttpRequest.LINE_LIMIT); |
944 } while ((line != null) && (line.length() == 0)); | 950 } while ((line != null) && (line.length() == 0)); |
Felix Dahlke
2013/04/09 09:16:48
Here's a shorter alternative: while("".equals(line
Andrey Novikov
2013/04/10 08:30:30
This was copied from another part of Brazil, I'll
| |
945 | 951 |
946 try { | 952 try { |
947 bytesLeft = Integer.parseInt(line.trim(), 16); | 953 bytesLeft = Integer.parseInt(line.trim(), 16); |
948 } catch (Exception e) { | 954 } catch (Exception e) { |
949 throw new IOException("malformed chunk"); | 955 throw new IOException("malformed chunk"); |
950 } | 956 } |
951 return bytesLeft; | 957 return bytesLeft; |
952 } | 958 } |
953 | 959 |
954 void | 960 void |
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1841 return "(null)"; | 1847 return "(null)"; |
1842 } | 1848 } |
1843 StringBuffer sb = new StringBuffer(); | 1849 StringBuffer sb = new StringBuffer(); |
1844 for (int i = 0; i < idle.size(); i++) { | 1850 for (int i = 0; i < idle.size(); i++) { |
1845 HttpSocket hs = (HttpSocket) idle.elementAt(i); | 1851 HttpSocket hs = (HttpSocket) idle.elementAt(i); |
1846 sb.append(hs.toString() + ", "); | 1852 sb.append(hs.toString() + ", "); |
1847 } | 1853 } |
1848 return sb.toString(); | 1854 return sb.toString(); |
1849 } | 1855 } |
1850 } | 1856 } |
LEFT | RIGHT |