Hi all,

Cups uses IPP over HTTP for communication. However the current cups versions
don't correctly implement HTTP 1.1. In particular they fail if 'Expect: 100-continue' header is set. And thats the default in GNU classpath.

The bug is known upstream and will be fixed in CUPS 1.2.

I currently work in my local tree with an addition to Request and
HTTPURLConnection to disable 'Expect: 100-continue' on request.

2006-01-30  Wolfgang Baer  <[EMAIL PROTECTED]>

        * gnu/java/net/protocol/http/HTTPURLConnection.java:
        (disableExpect): New field.
        (disableExpectHeader): New method.
        (connect): If disableExpect is true set requestBodyNegotiationThreshold
        to -1 to diable 'Expect: 100-continue' usage.
        * gnu/java/net/protocol/http/Request.java
        (dispatch): Don't use 'Expect: 100-continue' if
        requestBodyNegotiationThreshold is negative as explained in api docs.   
I don't know if its good to introduce a new public method which could be used
at least per reflection, as HTTPURLConnection is the GNU specific
implementation class for java.net.HttpURLConnection. The default behaviour is
not changed by this patch.

The change to Request is actually a fix to implement the behaviour as
advertised by the API documentation of the setRequestBodyNegotiationThreshold
method.

Comments, or other ideas how I can use the class without expect header ?

Thanks,
Wolfgang
Index: gnu/java/net/protocol/http/HTTPURLConnection.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/net/protocol/http/HTTPURLConnection.java,v
retrieving revision 1.17
diff -u -r1.17 HTTPURLConnection.java
--- gnu/java/net/protocol/http/HTTPURLConnection.java	20 Jan 2006 22:15:58 -0000	1.17
+++ gnu/java/net/protocol/http/HTTPURLConnection.java	30 Jan 2006 14:00:59 -0000
@@ -87,6 +87,7 @@
   int proxyPort;
   String agent;
   boolean keepAlive;
+  boolean disableExpect;
 
   private Request request;
   private Headers requestHeaders;
@@ -204,6 +205,10 @@
         try
           {
             request = connection.newRequest(method, file);
+            if (disableExpect)
+              {
+                request.setRequestBodyNegotiationThreshold(-1);
+              }
             if (!keepAlive)
               {
                 request.setHeader("Connection", "close");
@@ -216,6 +221,7 @@
             if (requestSink != null)
               {
                 byte[] content = requestSink.toByteArray();
+                System.out.println("Length X: " + content.length);
                 RequestBodyWriter writer = new ByteArrayRequestBodyWriter(content);
                 request.setRequestBodyWriter(writer);
               }
@@ -710,6 +716,19 @@
       }
     return handshakeEvent.getPeerCertificates();
   }
+  
+  /**
+   * Disable 'Expect: 100-Continue' handshake.
+   * <p>
+   * 'Expect: 100-Continue' handshake may cause problems
+   * if the server only supports HTTP 1.0 or otherwise
+   * does not support this handshake.
+   * </p> 
+   */
+  public void disableExpectHeader() {
+      disableExpect = true;
+  }
+ 
 
   // HandshakeCompletedListener
 
Index: gnu/java/net/protocol/http/Request.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/net/protocol/http/Request.java,v
retrieving revision 1.7
diff -u -r1.7 Request.java
--- gnu/java/net/protocol/http/Request.java	16 Jan 2006 20:43:20 -0000	1.7
+++ gnu/java/net/protocol/http/Request.java	30 Jan 2006 14:00:59 -0000
@@ -291,7 +291,8 @@
     if (requestBodyWriter != null)
       {
         contentLength = requestBodyWriter.getContentLength();
-        if (contentLength > requestBodyNegotiationThreshold)
+        if (requestBodyNegotiationThreshold > 0 
+            && contentLength > requestBodyNegotiationThreshold)
           {
             expectingContinue = true;
             setHeader("Expect", "100-continue");

Reply via email to