Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e299104

Browse files
Make default user agent configurable (public static field)
1 parent 11d2203 commit e299104

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

sources/net.sf.j2s.ajax/ajaxcore/net/sf/j2s/ajax/HttpRequest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
import java.io.UnsupportedEncodingException;
2121
import java.net.HttpURLConnection;
2222
import java.net.URL;
23-
import java.util.HashMap;
2423
import java.util.Iterator;
2524
import java.util.List;
2625
import java.util.Map;
26+
import java.util.concurrent.ConcurrentHashMap;
2727
import java.util.regex.Matcher;
2828
import java.util.regex.Pattern;
2929

@@ -134,6 +134,8 @@ public static interface IXHRReceiving {
134134
*/
135135
public boolean receiving(ByteArrayOutputStream baos, byte b[], int off, int len);
136136
}
137+
138+
public static String DEFAULT_USER_AGENT = "Java2Script/2.0.2";
137139

138140
protected int status;
139141
protected String statusText;
@@ -153,7 +155,7 @@ public static interface IXHRReceiving {
153155
protected String user;
154156
protected String password;
155157

156-
protected Map<String, String> headers = new HashMap<String, String>();
158+
protected Map<String, String> headers = new ConcurrentHashMap<String, String>();
157159
protected String content;
158160

159161
protected boolean toAbort = false;
@@ -442,8 +444,7 @@ private void request() {
442444
connection.setInstanceFollowRedirects(false);
443445
connection.setDoInput(true);
444446
connection.setRequestMethod(method);
445-
connection.setRequestProperty("User-Agent",
446-
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69 Safari/537.36");
447+
connection.setRequestProperty("User-Agent", DEFAULT_USER_AGENT);
447448
if ("post".equalsIgnoreCase(method)) {
448449
connection.setDoOutput(true);
449450
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

0 commit comments

Comments
 (0)