From e6573be00feb27b2b16446c07d16c37d3d69d3c9 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sun, 30 Aug 2015 20:45:09 -0700 Subject: api 23, remove deprecated apache http stuff. --- AndroidAsync/build.gradle | 6 +- .../src/com/koushikdutta/async/AsyncServer.java | 1 + .../src/com/koushikdutta/async/ByteBufferList.java | 7 +- .../com/koushikdutta/async/dns/DnsResponse.java | 3 - .../koushikdutta/async/http/AsyncHttpRequest.java | 139 ---------- .../async/http/BasicNameValuePair.java | 174 +++++++++++++ .../src/com/koushikdutta/async/http/Headers.java | 16 -- .../src/com/koushikdutta/async/http/Multimap.java | 1 - .../com/koushikdutta/async/http/NameValuePair.java | 108 ++++++++ .../koushikdutta/async/http/ProtocolVersion.java | 286 +++++++++++++++++++++ .../com/koushikdutta/async/http/RequestLine.java | 53 ++++ .../com/koushikdutta/async/http/body/FilePart.java | 3 +- .../async/http/server/AsyncHttpServer.java | 15 ++ .../com/koushikdutta/async/util/StreamUtility.java | 11 +- 14 files changed, 657 insertions(+), 166 deletions(-) create mode 100644 AndroidAsync/src/com/koushikdutta/async/http/BasicNameValuePair.java create mode 100644 AndroidAsync/src/com/koushikdutta/async/http/NameValuePair.java create mode 100644 AndroidAsync/src/com/koushikdutta/async/http/ProtocolVersion.java create mode 100644 AndroidAsync/src/com/koushikdutta/async/http/RequestLine.java diff --git a/AndroidAsync/build.gradle b/AndroidAsync/build.gradle index 74ae497..2f87f53 100644 --- a/AndroidAsync/build.gradle +++ b/AndroidAsync/build.gradle @@ -22,12 +22,12 @@ android { } defaultConfig { - targetSdkVersion 22 + targetSdkVersion 23 minSdkVersion 9 } - compileSdkVersion 21 - buildToolsVersion '21.1.2' + compileSdkVersion 23 + buildToolsVersion '23.0.0' } // upload to maven task diff --git a/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java b/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java index 7245d79..03c69fe 100644 --- a/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java +++ b/AndroidAsync/src/com/koushikdutta/async/AsyncServer.java @@ -317,6 +317,7 @@ public class AsyncServer { }); } catch (IOException e) { + Log.e(LOGTAG, "wtf", e); StreamUtility.closeQuietly(closeableWrapper, closeableServer); handler.onCompleted(e); } diff --git a/AndroidAsync/src/com/koushikdutta/async/ByteBufferList.java b/AndroidAsync/src/com/koushikdutta/async/ByteBufferList.java index b42a58a..af6ed56 100644 --- a/AndroidAsync/src/com/koushikdutta/async/ByteBufferList.java +++ b/AndroidAsync/src/com/koushikdutta/async/ByteBufferList.java @@ -412,8 +412,11 @@ public class ByteBufferList { static PriorityQueue reclaimed = new PriorityQueue(8, new Reclaimer()); private static PriorityQueue getReclaimed() { - if (Thread.currentThread() == Looper.getMainLooper().getThread()) - return null; + Looper mainLooper = Looper.getMainLooper(); + if (mainLooper != null) { + if (Thread.currentThread() == mainLooper.getThread()) + return null; + } return reclaimed; } diff --git a/AndroidAsync/src/com/koushikdutta/async/dns/DnsResponse.java b/AndroidAsync/src/com/koushikdutta/async/dns/DnsResponse.java index d708089..06caf7b 100644 --- a/AndroidAsync/src/com/koushikdutta/async/dns/DnsResponse.java +++ b/AndroidAsync/src/com/koushikdutta/async/dns/DnsResponse.java @@ -3,9 +3,6 @@ package com.koushikdutta.async.dns; import com.koushikdutta.async.ByteBufferList; import com.koushikdutta.async.http.Multimap; -import org.apache.http.NameValuePair; -import org.apache.http.message.BasicNameValuePair; - import java.net.InetAddress; import java.net.InetSocketAddress; import java.nio.ByteBuffer; diff --git a/AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpRequest.java b/AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpRequest.java index 35fb193..412463b 100644 --- a/AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpRequest.java +++ b/AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpRequest.java @@ -6,17 +6,6 @@ import android.util.Log; import com.koushikdutta.async.AsyncSSLException; import com.koushikdutta.async.http.body.AsyncHttpRequestBody; -import org.apache.http.Header; -import org.apache.http.HeaderIterator; -import org.apache.http.HttpRequest; -import org.apache.http.ProtocolVersion; -import org.apache.http.RequestLine; -import org.apache.http.message.BasicHeader; -import org.apache.http.params.HttpParams; - -import java.util.List; -import java.util.Map; - public class AsyncHttpRequest { public RequestLine getRequestLine() { return new RequestLine() { @@ -140,134 +129,6 @@ public class AsyncHttpRequest { mTimeout = timeout; return this; } - - public static AsyncHttpRequest create(HttpRequest request) { - AsyncHttpRequest ret = new AsyncHttpRequest(Uri.parse(request.getRequestLine().getUri()), request.getRequestLine().getMethod()); - for (Header header: request.getAllHeaders()) { - ret.getHeaders().add(header.getName(), header.getValue()); - } - return ret; - } - - private static class HttpRequestWrapper implements HttpRequest { - AsyncHttpRequest request; - - @Override - public RequestLine getRequestLine() { - return request.getRequestLine(); - } - - public HttpRequestWrapper(AsyncHttpRequest request) { - this.request = request; - } - - - @Override - public void addHeader(Header header) { - request.getHeaders().add(header.getName(), header.getValue()); - } - - @Override - public void addHeader(String name, String value) { - request.getHeaders().add(name, value); - } - - @Override - public boolean containsHeader(String name) { - return request.getHeaders().get(name) != null; - } - - @Override - public Header[] getAllHeaders() { - return request.getHeaders().toHeaderArray(); - } - - @Override - public Header getFirstHeader(String name) { - String value = request.getHeaders().get(name); - if (value == null) - return null; - return new BasicHeader(name, value); - } - - @Override - public Header[] getHeaders(String name) { - Map> map = request.getHeaders().getMultiMap(); - List vals = map.get(name); - if (vals == null) - return new Header[0]; - Header[] ret = new Header[vals.size()]; - for (int i = 0; i < ret.length; i++) - ret[i] = new BasicHeader(name, vals.get(i)); - return ret; - } - - @Override - public Header getLastHeader(String name) { - Header[] vals = getHeaders(name); - if (vals.length == 0) - return null; - return vals[vals.length - 1]; - } - - HttpParams params; - @Override - public HttpParams getParams() { - return params; - } - - @Override - public ProtocolVersion getProtocolVersion() { - return new ProtocolVersion("HTTP", 1, 1); - } - - @Override - public HeaderIterator headerIterator() { - assert false; - return null; - } - - @Override - public HeaderIterator headerIterator(String name) { - assert false; - return null; - } - - @Override - public void removeHeader(Header header) { - request.getHeaders().remove(header.getName()); - } - - @Override - public void removeHeaders(String name) { - request.getHeaders().remove(name); - } - - @Override - public void setHeader(Header header) { - setHeader(header.getName(), header.getValue()); - } - - @Override - public void setHeader(String name, String value) { - request.getHeaders().set(name, value); - } - - @Override - public void setHeaders(Header[] headers) { - for (Header header: headers) - setHeader(header); - } - - @Override - public void setParams(HttpParams params) { - this.params = params; - } - } - - public HttpRequest asHttpRequest() { - return new HttpRequestWrapper(this); - } public AsyncHttpRequest setHeader(String name, String value) { getHeaders().set(name, value); diff --git a/AndroidAsync/src/com/koushikdutta/async/http/BasicNameValuePair.java b/AndroidAsync/src/com/koushikdutta/async/http/BasicNameValuePair.java new file mode 100644 index 0000000..546575b --- /dev/null +++ b/AndroidAsync/src/com/koushikdutta/async/http/BasicNameValuePair.java @@ -0,0 +1,174 @@ +/* + * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicNameValuePair.java $ + * $Revision: 604625 $ + * $Date: 2007-12-16 06:11:11 -0800 (Sun, 16 Dec 2007) $ + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package com.koushikdutta.async.http; + +import android.text.TextUtils; + +import org.apache.http.NameValuePair; + +/** + * A simple class encapsulating an attribute/value pair. + *

+ * This class comforms to the generic grammar and formatting rules outlined in the + * Section 2.2 + * and + * Section 3.6 + * of RFC 2616 + *

+ * 2.2 Basic Rules + *

+ * The following rules are used throughout this specification to describe basic parsing constructs. + * The US-ASCII coded character set is defined by ANSI X3.4-1986. + *

+ *
+ *     OCTET          = 
+ *     CHAR           = 
+ *     UPALPHA        = 
+ *     LOALPHA        = 
+ *     ALPHA          = UPALPHA | LOALPHA
+ *     DIGIT          = 
+ *     CTL            = 
+ *     CR             = 
+ *     LF             = 
+ *     SP             = 
+ *     HT             = 
+ *     <">            = 
+ * 
+ *

+ * Many HTTP/1.1 header field values consist of words separated by LWS or special + * characters. These special characters MUST be in a quoted string to be used within + * a parameter value (as defined in section 3.6). + *

+ *

+ * token          = 1*
+ * separators     = "(" | ")" | "<" | ">" | "@"
+ *                | "," | ";" | ":" | "\" | <">
+ *                | "/" | "[" | "]" | "?" | "="
+ *                | "{" | "}" | SP | HT
+ * 
+ *

+ * A string of text is parsed as a single word if it is quoted using double-quote marks. + *

+ *
+ * quoted-string  = ( <"> *(qdtext | quoted-pair ) <"> )
+ * qdtext         = >
+ * 
+ *

+ * The backslash character ("\") MAY be used as a single-character quoting mechanism only + * within quoted-string and comment constructs. + *

+ *
+ * quoted-pair    = "\" CHAR
+ * 
+ * 3.6 Transfer Codings + *

+ * Parameters are in the form of attribute/value pairs. + *

+ *
+ * parameter               = attribute "=" value
+ * attribute               = token
+ * value                   = token | quoted-string
+ * 
+ * + * @author Oleg Kalnichevski + * + */ +public class BasicNameValuePair implements NameValuePair, Cloneable { + + private final String name; + private final String value; + + /** + * Default Constructor taking a name and a value. The value may be null. + * + * @param name The name. + * @param value The value. + */ + public BasicNameValuePair(final String name, final String value) { + super(); + if (name == null) { + throw new IllegalArgumentException("Name may not be null"); + } + this.name = name; + this.value = value; + } + + /** + * Returns the name. + * + * @return String name The name + */ + public String getName() { + return this.name; + } + + /** + * Returns the value. + * + * @return String value The current value. + */ + public String getValue() { + return this.value; + } + + + /** + * Get a string representation of this pair. + * + * @return A string representation. + */ + public String toString() { + return name + "=" + value; + } + + public boolean equals(final Object object) { + if (object == null) return false; + if (this == object) return true; + if (object instanceof NameValuePair) { + BasicNameValuePair that = (BasicNameValuePair) object; + return this.name.equals(that.name) + && TextUtils.equals(this.value, that.value); + } else { + return false; + } + } + + public int hashCode() { + return name.hashCode() ^ value.hashCode(); + } + + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + +} diff --git a/AndroidAsync/src/com/koushikdutta/async/http/Headers.java b/AndroidAsync/src/com/koushikdutta/async/http/Headers.java index 92c2b19..7d56edb 100644 --- a/AndroidAsync/src/com/koushikdutta/async/http/Headers.java +++ b/AndroidAsync/src/com/koushikdutta/async/http/Headers.java @@ -3,13 +3,8 @@ package com.koushikdutta.async.http; import android.text.TextUtils; -import com.koushikdutta.async.http.server.AsyncHttpServer; import com.koushikdutta.async.util.TaggedList; -import org.apache.http.Header; -import org.apache.http.message.BasicHeader; - -import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; @@ -113,17 +108,6 @@ public class Headers { return this; } - public Header[] toHeaderArray() { - ArrayList
ret = new ArrayList
(); - for (String key: map.keySet()) { - TaggedList list = (TaggedList)map.get(key); - for (String v: map.get(key)) { - ret.add(new BasicHeader((String)list.tag(), v)); - } - } - return ret.toArray(new Header[ret.size()]); - } - public StringBuilder toStringBuilder() { StringBuilder result = new StringBuilder(256); for (String key: map.keySet()) { diff --git a/AndroidAsync/src/com/koushikdutta/async/http/Multimap.java b/AndroidAsync/src/com/koushikdutta/async/http/Multimap.java index 111b336..89932db 100644 --- a/AndroidAsync/src/com/koushikdutta/async/http/Multimap.java +++ b/AndroidAsync/src/com/koushikdutta/async/http/Multimap.java @@ -3,7 +3,6 @@ package com.koushikdutta.async.http; import android.net.Uri; import org.apache.http.NameValuePair; -import org.apache.http.message.BasicNameValuePair; import java.net.URLDecoder; import java.util.ArrayList; diff --git a/AndroidAsync/src/com/koushikdutta/async/http/NameValuePair.java b/AndroidAsync/src/com/koushikdutta/async/http/NameValuePair.java new file mode 100644 index 0000000..28300b3 --- /dev/null +++ b/AndroidAsync/src/com/koushikdutta/async/http/NameValuePair.java @@ -0,0 +1,108 @@ +/* + * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/NameValuePair.java $ + * $Revision: 496070 $ + * $Date: 2007-01-14 04:18:34 -0800 (Sun, 14 Jan 2007) $ + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http; + +/** + * A simple class encapsulating an attribute/value pair. + *

+ * This class comforms to the generic grammar and formatting rules outlined in the + * Section 2.2 + * and + * Section 3.6 + * of RFC 2616 + *

+ * 2.2 Basic Rules + *

+ * The following rules are used throughout this specification to describe basic parsing constructs. + * The US-ASCII coded character set is defined by ANSI X3.4-1986. + *

+ *
+ *     OCTET          = 
+ *     CHAR           = 
+ *     UPALPHA        = 
+ *     LOALPHA        = 
+ *     ALPHA          = UPALPHA | LOALPHA
+ *     DIGIT          = 
+ *     CTL            = 
+ *     CR             = 
+ *     LF             = 
+ *     SP             = 
+ *     HT             = 
+ *     <">            = 
+ * 
+ *

+ * Many HTTP/1.1 header field values consist of words separated by LWS or special + * characters. These special characters MUST be in a quoted string to be used within + * a parameter value (as defined in section 3.6). + *

+ *

+ * token          = 1*
+ * separators     = "(" | ")" | "<" | ">" | "@"
+ *                | "," | ";" | ":" | "\" | <">
+ *                | "/" | "[" | "]" | "?" | "="
+ *                | "{" | "}" | SP | HT
+ * 
+ *

+ * A string of text is parsed as a single word if it is quoted using double-quote marks. + *

+ *
+ * quoted-string  = ( <"> *(qdtext | quoted-pair ) <"> )
+ * qdtext         = >
+ * 
+ *

+ * The backslash character ("\") MAY be used as a single-character quoting mechanism only + * within quoted-string and comment constructs. + *

+ *
+ * quoted-pair    = "\" CHAR
+ * 
+ * 3.6 Transfer Codings + *

+ * Parameters are in the form of attribute/value pairs. + *

+ *
+ * parameter               = attribute "=" value
+ * attribute               = token
+ * value                   = token | quoted-string
+ * 
+ * + * @author Oleg Kalnichevski + * + */ +public interface NameValuePair { + + String getName(); + + String getValue(); + +} diff --git a/AndroidAsync/src/com/koushikdutta/async/http/ProtocolVersion.java b/AndroidAsync/src/com/koushikdutta/async/http/ProtocolVersion.java new file mode 100644 index 0000000..b4c150b --- /dev/null +++ b/AndroidAsync/src/com/koushikdutta/async/http/ProtocolVersion.java @@ -0,0 +1,286 @@ +/* + * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/ProtocolVersion.java $ + * $Revision: 609106 $ + * $Date: 2008-01-05 01:15:42 -0800 (Sat, 05 Jan 2008) $ + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package com.koushikdutta.async.http; + +import java.io.Serializable; + + +/** + * Represents a protocol version, as specified in RFC 2616. + * RFC 2616 specifies only HTTP versions, like "HTTP/1.1" and "HTTP/1.0". + * RFC 3261 specifies a message format that is identical to HTTP except + * for the protocol name. It defines a protocol version "SIP/2.0". + * There are some nitty-gritty differences between the interpretation + * of versions in HTTP and SIP. In those cases, HTTP takes precedence. + *

+ * This class defines a protocol version as a combination of + * protocol name, major version number, and minor version number. + * Note that {@link #equals} and {@link #hashCode} are defined as + * final here, they cannot be overridden in derived classes. + * + * @author Oleg Kalnichevski + * @author Roland Weber + * + * @version $Revision: 609106 $ + */ +public class ProtocolVersion implements Serializable, Cloneable { + + private static final long serialVersionUID = 8950662842175091068L; + + + /** Name of the protocol. */ + protected final String protocol; + + /** Major version number of the protocol */ + protected final int major; + + /** Minor version number of the protocol */ + protected final int minor; + + + /** + * Create a protocol version designator. + * + * @param protocol the name of the protocol, for example "HTTP" + * @param major the major version number of the protocol + * @param minor the minor version number of the protocol + */ + public ProtocolVersion(String protocol, int major, int minor) { + if (protocol == null) { + throw new IllegalArgumentException + ("Protocol name must not be null."); + } + if (major < 0) { + throw new IllegalArgumentException + ("Protocol major version number must not be negative."); + } + if (minor < 0) { + throw new IllegalArgumentException + ("Protocol minor version number may not be negative"); + } + this.protocol = protocol; + this.major = major; + this.minor = minor; + } + + /** + * Returns the name of the protocol. + * + * @return the protocol name + */ + public final String getProtocol() { + return protocol; + } + + /** + * Returns the major version number of the protocol. + * + * @return the major version number. + */ + public final int getMajor() { + return major; + } + + /** + * Returns the minor version number of the HTTP protocol. + * + * @return the minor version number. + */ + public final int getMinor() { + return minor; + } + + + /** + * Obtains a specific version of this protocol. + * This can be used by derived classes to instantiate themselves instead + * of the base class, and to define constants for commonly used versions. + *
+ * The default implementation in this class returns this + * if the version matches, and creates a new {@link ProtocolVersion} + * otherwise. + * + * @param major the major version + * @param minor the minor version + * + * @return a protocol version with the same protocol name + * and the argument version + */ + public ProtocolVersion forVersion(int major, int minor) { + + if ((major == this.major) && (minor == this.minor)) { + return this; + } + + // argument checking is done in the constructor + return new ProtocolVersion(this.protocol, major, minor); + } + + + /** + * Obtains a hash code consistent with {@link #equals}. + * + * @return the hashcode of this protocol version + */ + public final int hashCode() { + return this.protocol.hashCode() ^ (this.major * 100000) ^ this.minor; + } + + + /** + * Checks equality of this protocol version with an object. + * The object is equal if it is a protocl version with the same + * protocol name, major version number, and minor version number. + * The specific class of the object is not relevant, + * instances of derived classes with identical attributes are + * equal to instances of the base class and vice versa. + * + * @param obj the object to compare with + * + * @return true if the argument is the same protocol version, + * false otherwise + */ + public final boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof ProtocolVersion)) { + return false; + } + ProtocolVersion that = (ProtocolVersion) obj; + + return ((this.protocol.equals(that.protocol)) && + (this.major == that.major) && + (this.minor == that.minor)); + } + + + /** + * Checks whether this protocol can be compared to another one. + * Only protocol versions with the same protocol name can be + * {@link #compareToVersion compared}. + * + * @param that the protocol version to consider + * + * @return true if {@link #compareToVersion compareToVersion} + * can be called with the argument, false otherwise + */ + public boolean isComparable(ProtocolVersion that) { + return (that != null) && this.protocol.equals(that.protocol); + } + + + /** + * Compares this protocol version with another one. + * Only protocol versions with the same protocol name can be compared. + * This method does not define a total ordering, as it would be + * required for {@link java.lang.Comparable}. + * + * @param that the protocl version to compare with + * + * @return a negative integer, zero, or a positive integer + * as this version is less than, equal to, or greater than + * the argument version. + * + * @throws IllegalArgumentException + * if the argument has a different protocol name than this object, + * or if the argument is null + */ + public int compareToVersion(ProtocolVersion that) { + if (that == null) { + throw new IllegalArgumentException + ("Protocol version must not be null."); + } + if (!this.protocol.equals(that.protocol)) { + throw new IllegalArgumentException + ("Versions for different protocols cannot be compared. " + + this + " " + that); + } + + int delta = getMajor() - that.getMajor(); + if (delta == 0) { + delta = getMinor() - that.getMinor(); + } + return delta; + } + + + /** + * Tests if this protocol version is greater or equal to the given one. + * + * @param version the version against which to check this version + * + * @return true if this protocol version is + * {@link #isComparable comparable} to the argument + * and {@link #compareToVersion compares} as greater or equal, + * false otherwise + */ + public final boolean greaterEquals(ProtocolVersion version) { + return isComparable(version) && (compareToVersion(version) >= 0); + } + + + /** + * Tests if this protocol version is less or equal to the given one. + * + * @param version the version against which to check this version + * + * @return true if this protocol version is + * {@link #isComparable comparable} to the argument + * and {@link #compareToVersion compares} as less or equal, + * false otherwise + */ + public final boolean lessEquals(ProtocolVersion version) { + return isComparable(version) && (compareToVersion(version) <= 0); + } + + + /** + * Converts this protocol version to a string. + * + * @return a protocol version string, like "HTTP/1.1" + */ + public String toString() { + StringBuilder buffer = new StringBuilder(); + buffer.append(this.protocol); + buffer.append('/'); + buffer.append(Integer.toString(this.major)); + buffer.append('.'); + buffer.append(Integer.toString(this.minor)); + return buffer.toString(); + } + + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + +} diff --git a/AndroidAsync/src/com/koushikdutta/async/http/RequestLine.java b/AndroidAsync/src/com/koushikdutta/async/http/RequestLine.java new file mode 100644 index 0000000..63bda12 --- /dev/null +++ b/AndroidAsync/src/com/koushikdutta/async/http/RequestLine.java @@ -0,0 +1,53 @@ +/* + * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/RequestLine.java $ + * $Revision: 573864 $ + * $Date: 2007-09-08 08:53:25 -0700 (Sat, 08 Sep 2007) $ + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package com.koushikdutta.async.http; + +/** + * The first line of an {@link HttpRequest HttpRequest}. + * It contains the method, URI, and HTTP version of the request. + * For details, see RFC 2616. + * + * @author Oleg Kalnichevski + * + * @version $Revision: 573864 $ + * + * @since 4.0 + */ +public interface RequestLine { + + String getMethod(); + + ProtocolVersion getProtocolVersion(); + + String getUri(); + +} diff --git a/AndroidAsync/src/com/koushikdutta/async/http/body/FilePart.java b/AndroidAsync/src/com/koushikdutta/async/http/body/FilePart.java index 20cfe1f..aed1ced 100644 --- a/AndroidAsync/src/com/koushikdutta/async/http/body/FilePart.java +++ b/AndroidAsync/src/com/koushikdutta/async/http/body/FilePart.java @@ -1,7 +1,8 @@ package com.koushikdutta.async.http.body; +import com.koushikdutta.async.http.BasicNameValuePair; + import org.apache.http.NameValuePair; -import org.apache.http.message.BasicNameValuePair; import java.io.File; import java.io.FileInputStream; diff --git a/AndroidAsync/src/com/koushikdutta/async/http/server/AsyncHttpServer.java b/AndroidAsync/src/com/koushikdutta/async/http/server/AsyncHttpServer.java index 27ba4e5..d987c91 100644 --- a/AndroidAsync/src/com/koushikdutta/async/http/server/AsyncHttpServer.java +++ b/AndroidAsync/src/com/koushikdutta/async/http/server/AsyncHttpServer.java @@ -283,6 +283,21 @@ public class AsyncHttpServer { } final Hashtable> mActions = new Hashtable>(); + + public void removeAction(String action, String regex) { + synchronized (mActions) { + ArrayList pairs = mActions.get(action); + if (pairs == null) + return; + for (int i = 0; i < pairs.size(); i++) { + Pair p = pairs.get(i); + if (regex.equals(p.regex.toString())) { + pairs.remove(i); + return; + } + } + } + } public void addAction(String action, String regex, HttpServerRequestCallback callback) { Pair p = new Pair(); diff --git a/AndroidAsync/src/com/koushikdutta/async/util/StreamUtility.java b/AndroidAsync/src/com/koushikdutta/async/util/StreamUtility.java index 4d55e2f..2955a86 100644 --- a/AndroidAsync/src/com/koushikdutta/async/util/StreamUtility.java +++ b/AndroidAsync/src/com/koushikdutta/async/util/StreamUtility.java @@ -65,7 +65,16 @@ public class StreamUtility { static public String readFile(String filename) throws IOException { return readFile(new File(filename)); } - + + static public String readFileSilent(String filename) { + try { + return readFile(new File(filename)); + } + catch (IOException e) { + return null; + } + } + static public String readFile(File file) throws IOException { byte[] buffer = new byte[(int) file.length()]; DataInputStream input = null; -- cgit v1.2.3