geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r572967 - in /geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec: HttpRequestEncoder.java HttpRequestMessage.java
Date Wed, 05 Sep 2007 15:15:54 GMT
Author: jgenender
Date: Wed Sep  5 08:15:53 2007
New Revision: 572967

URL: http://svn.apache.org/viewvc?rev=572967&view=rev
Log:
Add user agent and fix Host header

Modified:
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
    geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java?rev=572967&r1=572966&r2=572967&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
(original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java
Wed Sep  5 08:15:53 2007
@@ -96,9 +96,19 @@
             //This header is required for HTTP/1.1
             buf.putString("Host: ", encoder);
             buf.putString(url.getHost(), encoder);
-            buf.putString(":", encoder);
-            buf.putString(url.getPort() + "", encoder);
+            if ((url.getProtocol().equals("http") && url.getPort() != 80 &&
url.getPort() != -1) &&
+                    (url.getProtocol().equals("https") && url.getPort() != 443 &&
url.getPort() != -1)) {
+                buf.putString(":", encoder);
+                buf.putString(url.getPort() + "", encoder);
+            }
             buf.put(CRLF);
+
+            //User agent
+            if (msg.getUserAgent() != null){
+                buf.putString("User-Agent: ", encoder);
+                buf.putString(msg.getUserAgent(), encoder);
+                buf.put(CRLF);
+            }
 
             //Process any headers we have
             List<NameValuePair> headers = msg.getHeaders();

Modified: geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java?rev=572967&r1=572966&r2=572967&view=diff
==============================================================================
--- geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
(original)
+++ geronimo/sandbox/AsyncHttpClient/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java
Wed Sep  5 08:15:53 2007
@@ -36,6 +36,7 @@
     private String requestMethod = REQUEST_GET;
     private String path;
     private Map<String, String> parameters = new HashMap<String,String>();
+    private String userAgent = "AsyncHttpClient 1.0";
 
 
     public HttpRequestMessage(String path) {
@@ -86,5 +87,13 @@
 
     public void setParameter(String name, String value){
         parameters.put(name, value);
+    }
+
+    public String getUserAgent() {
+        return userAgent;
+    }
+
+    public void setUserAgent(String userAgent) {
+        this.userAgent = userAgent;
     }
 }



Mime
View raw message