Skip to content

Commit 7d671ed

Browse files
committed
HTTP : add setUserAgent()
1 parent b95e3c1 commit 7d671ed

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/javaforce/HTTP.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class HTTP {
2222
public static boolean debug = false;
2323
private Progress progress;
2424
private static int timeout = 30000;
25+
private static String user_agent = "JavaForce.HTTP";
2526

2627
//form types : see RFC 1867, 7568
2728
/** Form Type for URL encoded data. */
@@ -329,10 +330,16 @@ public int getCode() {
329330
return code;
330331
}
331332

333+
/** Set Accept header value. */
332334
public void setAccept(String accept) {
333335
this.accept = accept;
334336
}
335337

338+
/** Set User-Agent header value. */
339+
public static void setUserAgent(String ua) {
340+
user_agent = ua;
341+
}
342+
336343
private int read(Buffer buf, int length) throws Exception {
337344
if (buf.count >= length) return length;
338345
int maxlength = buf.buf.length - buf.pos - buf.count;
@@ -574,7 +581,7 @@ public boolean get(String url, OutputStream os) {
574581
StringBuilder req = new StringBuilder();
575582
req.append("GET " + url + " HTTP/1.1\r\n");
576583
req.append("Host: " + host + (port != 80 ? (":" + port) : "") + "\r\n");
577-
req.append("User-Agent: JavaForce.HTTP\r\n");
584+
req.append("User-Agent: " + user_agent + "\r\n");
578585
req.append("Content-Length: 0\r\n");
579586
req.append("Accept: " + accept + "\r\n");
580587
req.append("Accept-Encoding: chunked\r\n");
@@ -644,7 +651,7 @@ public boolean post(String url, Part[] parts, OutputStream os) {
644651
StringBuilder req = new StringBuilder();
645652
req.append("POST " + url + " HTTP/1.1\r\n");
646653
req.append("Host: " + host + (port != 80 ? (":" + port) : "") + "\r\n");
647-
req.append("User-Agent: JavaForce.HTTP\r\n");
654+
req.append("User-Agent: " + user_agent + "\r\n");
648655
req.append("Accept: " + accept + "\r\n");
649656
req.append("Accept-Encoding: chunked\r\n");
650657
appendHeaders(req);
@@ -712,7 +719,7 @@ public boolean post(String url, byte[] data, String mimeType, OutputStream os) {
712719
StringBuilder req = new StringBuilder();
713720
req.append("POST " + url + " HTTP/1.1\r\n");
714721
req.append("Host: " + host + (port != 80 ? (":" + port) : "") + "\r\n");
715-
req.append("User-Agent: JavaForce.HTTP\r\n");
722+
req.append("User-Agent: " + user_agent + "\r\n");
716723
req.append("Accept: " + accept + "\r\n");
717724
req.append("Accept-Encoding: chunked\r\n");
718725
appendHeaders(req);

0 commit comments

Comments
 (0)