code
stringlengths
1
2.01M
repo_name
stringlengths
3
62
path
stringlengths
1
267
language
stringclasses
231 values
license
stringclasses
13 values
size
int64
1
2.01M
<html> <head> <!-- /* * ==================================================================== * 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 * <http://www.apache.org/>. * */ --> </head> <body> The parameterization framework for HTTP components. This package also provides core protocol and I/O parameters. </body> </html>
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/params/package.html
HTML
gpl3
1,351
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.params; import org.apache.ogt.http.HttpVersion; import org.apache.ogt.http.ProtocolVersion; import org.apache.ogt.http.protocol.HTTP; /** * Utility class for accessing protocol parameters in {@link HttpParams}. * * @since 4.0 * * @see CoreProtocolPNames */ public final class HttpProtocolParams implements CoreProtocolPNames { private HttpProtocolParams() { super(); } /** * Obtains value of the {@link CoreProtocolPNames#HTTP_ELEMENT_CHARSET} parameter. * If not set, defaults to <code>US-ASCII</code>. * * @param params HTTP parameters. * @return HTTP element charset. */ public static String getHttpElementCharset(final HttpParams params) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } String charset = (String) params.getParameter (CoreProtocolPNames.HTTP_ELEMENT_CHARSET); if (charset == null) { charset = HTTP.DEFAULT_PROTOCOL_CHARSET; } return charset; } /** * Sets value of the {@link CoreProtocolPNames#HTTP_ELEMENT_CHARSET} parameter. * * @param params HTTP parameters. * @param charset HTTP element charset. */ public static void setHttpElementCharset(final HttpParams params, final String charset) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } params.setParameter(CoreProtocolPNames.HTTP_ELEMENT_CHARSET, charset); } /** * Obtains value of the {@link CoreProtocolPNames#HTTP_CONTENT_CHARSET} parameter. * If not set, defaults to <code>ISO-8859-1</code>. * * @param params HTTP parameters. * @return HTTP content charset. */ public static String getContentCharset(final HttpParams params) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } String charset = (String) params.getParameter (CoreProtocolPNames.HTTP_CONTENT_CHARSET); if (charset == null) { charset = HTTP.DEFAULT_CONTENT_CHARSET; } return charset; } /** * Sets value of the {@link CoreProtocolPNames#HTTP_CONTENT_CHARSET} parameter. * * @param params HTTP parameters. * @param charset HTTP content charset. */ public static void setContentCharset(final HttpParams params, final String charset) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, charset); } /** * Obtains value of the {@link CoreProtocolPNames#PROTOCOL_VERSION} parameter. * If not set, defaults to {@link HttpVersion#HTTP_1_1}. * * @param params HTTP parameters. * @return HTTP protocol version. */ public static ProtocolVersion getVersion(final HttpParams params) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } Object param = params.getParameter (CoreProtocolPNames.PROTOCOL_VERSION); if (param == null) { return HttpVersion.HTTP_1_1; } return (ProtocolVersion)param; } /** * Sets value of the {@link CoreProtocolPNames#PROTOCOL_VERSION} parameter. * * @param params HTTP parameters. * @param version HTTP protocol version. */ public static void setVersion(final HttpParams params, final ProtocolVersion version) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, version); } /** * Obtains value of the {@link CoreProtocolPNames#USER_AGENT} parameter. * If not set, returns <code>null</code>. * * @param params HTTP parameters. * @return User agent string. */ public static String getUserAgent(final HttpParams params) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } return (String) params.getParameter(CoreProtocolPNames.USER_AGENT); } /** * Sets value of the {@link CoreProtocolPNames#USER_AGENT} parameter. * * @param params HTTP parameters. * @param useragent User agent string. */ public static void setUserAgent(final HttpParams params, final String useragent) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } params.setParameter(CoreProtocolPNames.USER_AGENT, useragent); } /** * Obtains value of the {@link CoreProtocolPNames#USE_EXPECT_CONTINUE} parameter. * If not set, returns <code>false</code>. * * @param params HTTP parameters. * @return User agent string. */ public static boolean useExpectContinue(final HttpParams params) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } return params.getBooleanParameter (CoreProtocolPNames.USE_EXPECT_CONTINUE, false); } /** * Sets value of the {@link CoreProtocolPNames#USE_EXPECT_CONTINUE} parameter. * * @param params HTTP parameters. * @param b expect-continue flag. */ public static void setUseExpectContinue(final HttpParams params, boolean b) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } params.setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, b); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/params/HttpProtocolParams.java
Java
gpl3
7,028
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.params; import org.apache.ogt.http.ProtocolVersion; /** * Defines parameter names for protocol execution in HttpCore. * * @since 4.0 */ public interface CoreProtocolPNames { /** * Defines the {@link ProtocolVersion} used per default. * <p> * This parameter expects a value of type {@link ProtocolVersion}. * </p> */ public static final String PROTOCOL_VERSION = "http.protocol.version"; /** * Defines the charset to be used for encoding HTTP protocol elements. * <p> * This parameter expects a value of type {@link String}. * </p> */ public static final String HTTP_ELEMENT_CHARSET = "http.protocol.element-charset"; /** * Defines the charset to be used per default for encoding content body. * <p> * This parameter expects a value of type {@link String}. * </p> */ public static final String HTTP_CONTENT_CHARSET = "http.protocol.content-charset"; /** * Defines the content of the <code>User-Agent</code> header. * <p> * This parameter expects a value of type {@link String}. * </p> */ public static final String USER_AGENT = "http.useragent"; /** * Defines the content of the <code>Server</code> header. * <p> * This parameter expects a value of type {@link String}. * </p> */ public static final String ORIGIN_SERVER = "http.origin-server"; /** * Defines whether responses with an invalid <code>Transfer-Encoding</code> * header should be rejected. * <p> * This parameter expects a value of type {@link Boolean}. * </p> */ public static final String STRICT_TRANSFER_ENCODING = "http.protocol.strict-transfer-encoding"; /** * <p> * Activates 'Expect: 100-Continue' handshake for the * entity enclosing methods. The purpose of the 'Expect: 100-Continue' * handshake is to allow a client that is sending a request message with * a request body to determine if the origin server is willing to * accept the request (based on the request headers) before the client * sends the request body. * </p> * * <p> * The use of the 'Expect: 100-continue' handshake can result in * a noticeable performance improvement for entity enclosing requests * (such as POST and PUT) that require the target server's * authentication. * </p> * * <p> * 'Expect: 100-continue' handshake should be used with * caution, as it may cause problems with HTTP servers and * proxies that do not support HTTP/1.1 protocol. * </p> * * This parameter expects a value of type {@link Boolean}. */ public static final String USE_EXPECT_CONTINUE = "http.protocol.expect-continue"; /** * <p> * Defines the maximum period of time in milliseconds the client should spend * waiting for a 100-continue response. * </p> * * This parameter expects a value of type {@link Integer}. */ public static final String WAIT_FOR_CONTINUE = "http.protocol.wait-for-continue"; }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/params/CoreProtocolPNames.java
Java
gpl3
4,323
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.params; /** * Defines parameter names for connections in HttpCore. * * @since 4.0 */ public interface CoreConnectionPNames { /** * Defines the socket timeout (<code>SO_TIMEOUT</code>) in milliseconds, * which is the timeout for waiting for data or, put differently, * a maximum period inactivity between two consecutive data packets). * A timeout value of zero is interpreted as an infinite timeout. * <p> * This parameter expects a value of type {@link Integer}. * </p> * @see java.net.SocketOptions#SO_TIMEOUT */ public static final String SO_TIMEOUT = "http.socket.timeout"; /** * Determines whether Nagle's algorithm is to be used. The Nagle's algorithm * tries to conserve bandwidth by minimizing the number of segments that are * sent. When applications wish to decrease network latency and increase * performance, they can disable Nagle's algorithm (that is enable * TCP_NODELAY). Data will be sent earlier, at the cost of an increase * in bandwidth consumption. * <p> * This parameter expects a value of type {@link Boolean}. * </p> * @see java.net.SocketOptions#TCP_NODELAY */ public static final String TCP_NODELAY = "http.tcp.nodelay"; /** * Determines the size of the internal socket buffer used to buffer data * while receiving / transmitting HTTP messages. * <p> * This parameter expects a value of type {@link Integer}. * </p> */ public static final String SOCKET_BUFFER_SIZE = "http.socket.buffer-size"; /** * Sets SO_LINGER with the specified linger time in seconds. The maximum * timeout value is platform specific. Value <code>0</code> implies that * the option is disabled. Value <code>-1</code> implies that the JRE * default is used. The setting only affects the socket close operation. * <p> * This parameter expects a value of type {@link Integer}. * </p> * @see java.net.SocketOptions#SO_LINGER */ public static final String SO_LINGER = "http.socket.linger"; /** * Defines whether the socket can be bound even though a previous connection is * still in a timeout state. * <p> * This parameter expects a value of type {@link Boolean}. * </p> * @see java.net.Socket#setReuseAddress(boolean) * * @since 4.1 */ public static final String SO_REUSEADDR = "http.socket.reuseaddr"; /** * Determines the timeout in milliseconds until a connection is established. * A timeout value of zero is interpreted as an infinite timeout. * <p> * Please note this parameter can only be applied to connections that * are bound to a particular local address. * <p> * This parameter expects a value of type {@link Integer}. * </p> */ public static final String CONNECTION_TIMEOUT = "http.connection.timeout"; /** * Determines whether stale connection check is to be used. The stale * connection check can cause up to 30 millisecond overhead per request and * should be used only when appropriate. For performance critical * operations this check should be disabled. * <p> * This parameter expects a value of type {@link Boolean}. * </p> */ public static final String STALE_CONNECTION_CHECK = "http.connection.stalecheck"; /** * Determines the maximum line length limit. If set to a positive value, * any HTTP line exceeding this limit will cause an IOException. A negative * or zero value will effectively disable the check. * <p> * This parameter expects a value of type {@link Integer}. * </p> */ public static final String MAX_LINE_LENGTH = "http.connection.max-line-length"; /** * Determines the maximum HTTP header count allowed. If set to a positive * value, the number of HTTP headers received from the data stream exceeding * this limit will cause an IOException. A negative or zero value will * effectively disable the check. * <p> * This parameter expects a value of type {@link Integer}. * </p> */ public static final String MAX_HEADER_COUNT = "http.connection.max-header-count"; /** * Defines the size limit below which data chunks should be buffered in a session I/O buffer * in order to minimize native method invocations on the underlying network socket. * The optimal value of this parameter can be platform specific and defines a trade-off * between performance of memory copy operations and that of native method invocation. * <p> * This parameter expects a value of type {@link Integer}. * </p> * * @since 4.1 */ public static final String MIN_CHUNK_LIMIT = "http.connection.min-chunk-limit"; }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/params/CoreConnectionPNames.java
Java
gpl3
6,056
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.params; /** * This is a Java Bean class that can be used to wrap an instance of * {@link HttpParams} and manipulate HTTP connection parameters using Java Beans * conventions. * * @since 4.0 */ public class HttpConnectionParamBean extends HttpAbstractParamBean { public HttpConnectionParamBean (final HttpParams params) { super(params); } public void setSoTimeout (int soTimeout) { HttpConnectionParams.setSoTimeout(params, soTimeout); } public void setTcpNoDelay (boolean tcpNoDelay) { HttpConnectionParams.setTcpNoDelay(params, tcpNoDelay); } public void setSocketBufferSize (int socketBufferSize) { HttpConnectionParams.setSocketBufferSize(params, socketBufferSize); } public void setLinger (int linger) { HttpConnectionParams.setLinger(params, linger); } public void setConnectionTimeout (int connectionTimeout) { HttpConnectionParams.setConnectionTimeout(params, connectionTimeout); } public void setStaleCheckingEnabled (boolean staleCheckingEnabled) { HttpConnectionParams.setStaleCheckingEnabled(params, staleCheckingEnabled); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/params/HttpConnectionParamBean.java
Java
gpl3
2,378
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.params; /** * HttpParams interface represents a collection of immutable values that define * a runtime behavior of a component. HTTP parameters should be simple objects: * integers, doubles, strings, collections and objects that remain immutable * at runtime. HttpParams is expected to be used in 'write once - read many' mode. * Once initialized, HTTP parameters are not expected to mutate in * the course of HTTP message processing. * <p> * The purpose of this interface is to define a behavior of other components. * Usually each complex component has its own HTTP parameter collection. * <p> * Instances of this interface can be linked together to form a hierarchy. * In the simplest form one set of parameters can use content of another one * to obtain default values of parameters not present in the local set. * * @see DefaultedHttpParams * * @since 4.0 */ public interface HttpParams { /** * Obtains the value of the given parameter. * * @param name the parent name. * * @return an object that represents the value of the parameter, * <code>null</code> if the parameter is not set or if it * is explicitly set to <code>null</code> * * @see #setParameter(String, Object) */ Object getParameter(String name); /** * Assigns the value to the parameter with the given name. * * @param name parameter name * @param value parameter value */ HttpParams setParameter(String name, Object value); /** * Creates a copy of these parameters. * * @return a new set of parameters holding the same values as this one * * @deprecated */ HttpParams copy(); /** * Removes the parameter with the specified name. * * @param name parameter name * * @return true if the parameter existed and has been removed, false else. */ boolean removeParameter(String name); /** * Returns a {@link Long} parameter value with the given name. * If the parameter is not explicitly set, the default value is returned. * * @param name the parent name. * @param defaultValue the default value. * * @return a {@link Long} that represents the value of the parameter. * * @see #setLongParameter(String, long) */ long getLongParameter(String name, long defaultValue); /** * Assigns a {@link Long} to the parameter with the given name * * @param name parameter name * @param value parameter value */ HttpParams setLongParameter(String name, long value); /** * Returns an {@link Integer} parameter value with the given name. * If the parameter is not explicitly set, the default value is returned. * * @param name the parent name. * @param defaultValue the default value. * * @return a {@link Integer} that represents the value of the parameter. * * @see #setIntParameter(String, int) */ int getIntParameter(String name, int defaultValue); /** * Assigns an {@link Integer} to the parameter with the given name * * @param name parameter name * @param value parameter value */ HttpParams setIntParameter(String name, int value); /** * Returns a {@link Double} parameter value with the given name. * If the parameter is not explicitly set, the default value is returned. * * @param name the parent name. * @param defaultValue the default value. * * @return a {@link Double} that represents the value of the parameter. * * @see #setDoubleParameter(String, double) */ double getDoubleParameter(String name, double defaultValue); /** * Assigns a {@link Double} to the parameter with the given name * * @param name parameter name * @param value parameter value */ HttpParams setDoubleParameter(String name, double value); /** * Returns a {@link Boolean} parameter value with the given name. * If the parameter is not explicitly set, the default value is returned. * * @param name the parent name. * @param defaultValue the default value. * * @return a {@link Boolean} that represents the value of the parameter. * * @see #setBooleanParameter(String, boolean) */ boolean getBooleanParameter(String name, boolean defaultValue); /** * Assigns a {@link Boolean} to the parameter with the given name * * @param name parameter name * @param value parameter value */ HttpParams setBooleanParameter(String name, boolean value); /** * Checks if a boolean parameter is set to <code>true</code>. * * @param name parameter name * * @return <tt>true</tt> if the parameter is set to value <tt>true</tt>, * <tt>false</tt> if it is not set or set to <code>false</code> */ boolean isParameterTrue(String name); /** * Checks if a boolean parameter is not set or <code>false</code>. * * @param name parameter name * * @return <tt>true</tt> if the parameter is either not set or * set to value <tt>false</tt>, * <tt>false</tt> if it is set to <code>true</code> */ boolean isParameterFalse(String name); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/params/HttpParams.java
Java
gpl3
6,551
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.params; /** * Utility class for accessing connection parameters in {@link HttpParams}. * * @since 4.0 */ public final class HttpConnectionParams implements CoreConnectionPNames { private HttpConnectionParams() { super(); } /** * Obtains value of the {@link CoreConnectionPNames#SO_TIMEOUT} parameter. * If not set, defaults to <code>0</code>. * * @param params HTTP parameters. * @return SO_TIMEOUT. */ public static int getSoTimeout(final HttpParams params) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } return params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0); } /** * Sets value of the {@link CoreConnectionPNames#SO_TIMEOUT} parameter. * * @param params HTTP parameters. * @param timeout SO_TIMEOUT. */ public static void setSoTimeout(final HttpParams params, int timeout) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, timeout); } /** * Obtains value of the {@link CoreConnectionPNames#SO_REUSEADDR} parameter. * If not set, defaults to <code>false</code>. * * @param params HTTP parameters. * @return SO_REUSEADDR. * * @since 4.1 */ public static boolean getSoReuseaddr(final HttpParams params) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } return params.getBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, false); } /** * Sets value of the {@link CoreConnectionPNames#SO_REUSEADDR} parameter. * * @param params HTTP parameters. * @param reuseaddr SO_REUSEADDR. * * @since 4.1 */ public static void setSoReuseaddr(final HttpParams params, boolean reuseaddr) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } params.setBooleanParameter(CoreConnectionPNames.SO_REUSEADDR, reuseaddr); } /** * Obtains value of the {@link CoreConnectionPNames#TCP_NODELAY} parameter. * If not set, defaults to <code>true</code>. * * @param params HTTP parameters. * @return Nagle's algorithm flag */ public static boolean getTcpNoDelay(final HttpParams params) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } return params.getBooleanParameter (CoreConnectionPNames.TCP_NODELAY, true); } /** * Sets value of the {@link CoreConnectionPNames#TCP_NODELAY} parameter. * * @param params HTTP parameters. * @param value Nagle's algorithm flag */ public static void setTcpNoDelay(final HttpParams params, boolean value) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } params.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, value); } /** * Obtains value of the {@link CoreConnectionPNames#SOCKET_BUFFER_SIZE} * parameter. If not set, defaults to <code>-1</code>. * * @param params HTTP parameters. * @return socket buffer size */ public static int getSocketBufferSize(final HttpParams params) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } return params.getIntParameter (CoreConnectionPNames.SOCKET_BUFFER_SIZE, -1); } /** * Sets value of the {@link CoreConnectionPNames#SOCKET_BUFFER_SIZE} * parameter. * * @param params HTTP parameters. * @param size socket buffer size */ public static void setSocketBufferSize(final HttpParams params, int size) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } params.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, size); } /** * Obtains value of the {@link CoreConnectionPNames#SO_LINGER} parameter. * If not set, defaults to <code>-1</code>. * * @param params HTTP parameters. * @return SO_LINGER. */ public static int getLinger(final HttpParams params) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } return params.getIntParameter(CoreConnectionPNames.SO_LINGER, -1); } /** * Sets value of the {@link CoreConnectionPNames#SO_LINGER} parameter. * * @param params HTTP parameters. * @param value SO_LINGER. */ public static void setLinger(final HttpParams params, int value) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } params.setIntParameter(CoreConnectionPNames.SO_LINGER, value); } /** * Obtains value of the {@link CoreConnectionPNames#CONNECTION_TIMEOUT} * parameter. If not set, defaults to <code>0</code>. * * @param params HTTP parameters. * @return connect timeout. */ public static int getConnectionTimeout(final HttpParams params) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } return params.getIntParameter (CoreConnectionPNames.CONNECTION_TIMEOUT, 0); } /** * Sets value of the {@link CoreConnectionPNames#CONNECTION_TIMEOUT} * parameter. * * @param params HTTP parameters. * @param timeout connect timeout. */ public static void setConnectionTimeout(final HttpParams params, int timeout) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } params.setIntParameter (CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); } /** * Obtains value of the {@link CoreConnectionPNames#STALE_CONNECTION_CHECK} * parameter. If not set, defaults to <code>true</code>. * * @param params HTTP parameters. * @return stale connection check flag. */ public static boolean isStaleCheckingEnabled(final HttpParams params) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } return params.getBooleanParameter (CoreConnectionPNames.STALE_CONNECTION_CHECK, true); } /** * Sets value of the {@link CoreConnectionPNames#STALE_CONNECTION_CHECK} * parameter. * * @param params HTTP parameters. * @param value stale connection check flag. */ public static void setStaleCheckingEnabled(final HttpParams params, boolean value) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } params.setBooleanParameter (CoreConnectionPNames.STALE_CONNECTION_CHECK, value); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/params/HttpConnectionParams.java
Java
gpl3
8,439
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.params; import org.apache.ogt.http.params.HttpParams; /** * Abstract base class for parameter collections. * Type specific setters and getters are mapped to the abstract, * generic getters and setters. * * @since 4.0 */ public abstract class AbstractHttpParams implements HttpParams { /** * Instantiates parameters. */ protected AbstractHttpParams() { super(); } public long getLongParameter(final String name, long defaultValue) { Object param = getParameter(name); if (param == null) { return defaultValue; } return ((Long)param).longValue(); } public HttpParams setLongParameter(final String name, long value) { setParameter(name, new Long(value)); return this; } public int getIntParameter(final String name, int defaultValue) { Object param = getParameter(name); if (param == null) { return defaultValue; } return ((Integer)param).intValue(); } public HttpParams setIntParameter(final String name, int value) { setParameter(name, new Integer(value)); return this; } public double getDoubleParameter(final String name, double defaultValue) { Object param = getParameter(name); if (param == null) { return defaultValue; } return ((Double)param).doubleValue(); } public HttpParams setDoubleParameter(final String name, double value) { setParameter(name, new Double(value)); return this; } public boolean getBooleanParameter(final String name, boolean defaultValue) { Object param = getParameter(name); if (param == null) { return defaultValue; } return ((Boolean)param).booleanValue(); } public HttpParams setBooleanParameter(final String name, boolean value) { setParameter(name, value ? Boolean.TRUE : Boolean.FALSE); return this; } public boolean isParameterTrue(final String name) { return getBooleanParameter(name, false); } public boolean isParameterFalse(final String name) { return !getBooleanParameter(name, false); } } // class AbstractHttpParams
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/params/AbstractHttpParams.java
Java
gpl3
3,458
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.params; /** * @since 4.0 */ public abstract class HttpAbstractParamBean { protected final HttpParams params; public HttpAbstractParamBean (final HttpParams params) { if (params == null) throw new IllegalArgumentException("HTTP parameters may not be null"); this.params = params; } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/params/HttpAbstractParamBean.java
Java
gpl3
1,542
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.params; /** * {@link HttpParams} implementation that delegates resolution of a parameter * to the given default {@link HttpParams} instance if the parameter is not * present in the local one. The state of the local collection can be mutated, * whereas the default collection is treated as read-only. * * @since 4.0 */ public final class DefaultedHttpParams extends AbstractHttpParams { private final HttpParams local; private final HttpParams defaults; /** * Create the defaulted set of HttpParams. * * @param local the mutable set of HttpParams * @param defaults the default set of HttpParams, not mutated by this class */ public DefaultedHttpParams(final HttpParams local, final HttpParams defaults) { super(); if (local == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } this.local = local; this.defaults = defaults; } /** * Creates a copy of the local collection with the same default * * @deprecated */ public HttpParams copy() { HttpParams clone = this.local.copy(); return new DefaultedHttpParams(clone, this.defaults); } /** * Retrieves the value of the parameter from the local collection and, if the * parameter is not set locally, delegates its resolution to the default * collection. */ public Object getParameter(final String name) { Object obj = this.local.getParameter(name); if (obj == null && this.defaults != null) { obj = this.defaults.getParameter(name); } return obj; } /** * Attempts to remove the parameter from the local collection. This method * <i>does not</i> modify the default collection. */ public boolean removeParameter(final String name) { return this.local.removeParameter(name); } /** * Sets the parameter in the local collection. This method <i>does not</i> * modify the default collection. */ public HttpParams setParameter(final String name, final Object value) { return this.local.setParameter(name, value); } /** * * @return the default HttpParams collection */ public HttpParams getDefaults() { return this.defaults; } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/params/DefaultedHttpParams.java
Java
gpl3
3,550
/* * ==================================================================== * 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 * <http://www.apache.org/>. */ package org.apache.ogt.http.params; /** * Thread-safe extension of the {@link BasicHttpParams}. * * @since 4.1 */ public class SyncBasicHttpParams extends BasicHttpParams { private static final long serialVersionUID = 5387834869062660642L; public SyncBasicHttpParams() { super(); } public synchronized boolean removeParameter(final String name) { return super.removeParameter(name); } public synchronized HttpParams setParameter(final String name, final Object value) { return super.setParameter(name, value); } public synchronized Object getParameter(final String name) { return super.getParameter(name); } public synchronized boolean isParameterSet(final String name) { return super.isParameterSet(name); } public synchronized boolean isParameterSetLocally(final String name) { return super.isParameterSetLocally(name); } public synchronized void setParameters(final String[] names, final Object value) { super.setParameters(names, value); } public synchronized void clear() { super.clear(); } public synchronized Object clone() throws CloneNotSupportedException { return super.clone(); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/params/SyncBasicHttpParams.java
Java
gpl3
2,439
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.params; import java.io.Serializable; import java.util.Map; import java.util.HashMap; import java.util.Iterator; import org.apache.ogt.http.params.HttpParams; /** * Default implementation of {@link HttpParams} interface. * <p> * Please note access to the internal structures of this class is not * synchronized and therefore this class may be thread-unsafe. * * @since 4.0 */ public class BasicHttpParams extends AbstractHttpParams implements Serializable, Cloneable { private static final long serialVersionUID = -7086398485908701455L; /** Map of HTTP parameters that this collection contains. */ private final HashMap parameters = new HashMap(); public BasicHttpParams() { super(); } public Object getParameter(final String name) { return this.parameters.get(name); } public HttpParams setParameter(final String name, final Object value) { this.parameters.put(name, value); return this; } public boolean removeParameter(String name) { //this is to avoid the case in which the key has a null value if (this.parameters.containsKey(name)) { this.parameters.remove(name); return true; } else { return false; } } /** * Assigns the value to all the parameter with the given names * * @param names array of parameter names * @param value parameter value */ public void setParameters(final String[] names, final Object value) { for (int i = 0; i < names.length; i++) { setParameter(names[i], value); } } /** * Is the parameter set? * <p> * Uses {@link #getParameter(String)} (which is overrideable) to * fetch the parameter value, if any. * <p> * Also @see {@link #isParameterSetLocally(String)} * * @param name parameter name * @return true if parameter is defined and non-null */ public boolean isParameterSet(final String name) { return getParameter(name) != null; } /** * Is the parameter set in this object? * <p> * The parameter value is fetched directly. * <p> * Also @see {@link #isParameterSet(String)} * * @param name parameter name * @return true if parameter is defined and non-null */ public boolean isParameterSetLocally(final String name) { return this.parameters.get(name) != null; } /** * Removes all parameters from this collection. */ public void clear() { this.parameters.clear(); } /** * Creates a copy of these parameters. * This implementation calls {@link #clone()}. * * @return a new set of params holding a copy of the * <i>local</i> parameters in this object. * * @deprecated * @throws UnsupportedOperationException if the clone() fails */ public HttpParams copy() { try { return (HttpParams) clone(); } catch (CloneNotSupportedException ex) { throw new UnsupportedOperationException("Cloning not supported"); } } /** * Clones the instance. * Uses {@link #copyParams(HttpParams)} to copy the parameters. */ public Object clone() throws CloneNotSupportedException { BasicHttpParams clone = (BasicHttpParams) super.clone(); copyParams(clone); return clone; } protected void copyParams(HttpParams target) { Iterator iter = parameters.entrySet().iterator(); while (iter.hasNext()) { Map.Entry me = (Map.Entry) iter.next(); if (me.getKey() instanceof String) target.setParameter((String)me.getKey(), me.getValue()); } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/params/BasicHttpParams.java
Java
gpl3
4,986
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.params; import org.apache.ogt.http.HttpVersion; /** * This is a Java Bean class that can be used to wrap an instance of * {@link HttpParams} and manipulate HTTP protocol parameters using Java Beans * conventions. * * @since 4.0 */ public class HttpProtocolParamBean extends HttpAbstractParamBean { public HttpProtocolParamBean (final HttpParams params) { super(params); } public void setHttpElementCharset (final String httpElementCharset) { HttpProtocolParams.setHttpElementCharset(params, httpElementCharset); } public void setContentCharset (final String contentCharset) { HttpProtocolParams.setContentCharset(params, contentCharset); } public void setVersion (final HttpVersion version) { HttpProtocolParams.setVersion(params, version); } public void setUserAgent (final String userAgent) { HttpProtocolParams.setUserAgent(params, userAgent); } public void setUseExpectContinue (boolean useExpectContinue) { HttpProtocolParams.setUseExpectContinue(params, useExpectContinue); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/params/HttpProtocolParamBean.java
Java
gpl3
2,308
<html> <head> <!-- /* * ==================================================================== * 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 * <http://www.apache.org/>. * */ --> </head> <body> The core HTTP components (HttpCore). These deal with the fundamental things required for using the HTTP protocol, such as representing a {@link org.apache.ogt.http.HttpMessage message} including it's {@link org.apache.ogt.http.Header headers} and optional {@link org.apache.ogt.http.HttpEntity entity}, and {@link org.apache.ogt.http.HttpConnection connections} over which messages are sent. In order to prepare messages before sending or after receiving, there are interceptors for {@link org.apache.ogt.http.HttpRequestInterceptor requests} and {@link org.apache.ogt.http.HttpResponseInterceptor responses}. </body> </html>
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/package.html
HTML
gpl3
1,850
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http; import java.util.Iterator; /** * An iterator for {@link String} tokens. * This interface is designed as a complement to * {@link HeaderElementIterator}, in cases where the items * are plain strings rather than full header elements. * * @since 4.0 */ public interface TokenIterator extends Iterator { /** * Indicates whether there is another token in this iteration. * * @return <code>true</code> if there is another token, * <code>false</code> otherwise */ boolean hasNext(); /** * Obtains the next token from this iteration. * This method should only be called while {@link #hasNext hasNext} * is true. * * @return the next token in this iteration */ String nextToken(); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/TokenIterator.java
Java
gpl3
1,982
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http; import java.util.Iterator; /** * A type-safe iterator for {@link HeaderElement} objects. * * @since 4.0 */ public interface HeaderElementIterator extends Iterator { /** * Indicates whether there is another header element in this * iteration. * * @return <code>true</code> if there is another header element, * <code>false</code> otherwise */ boolean hasNext(); /** * Obtains the next header element from this iteration. * This method should only be called while {@link #hasNext hasNext} * is true. * * @return the next header element in this iteration */ HeaderElement nextElement(); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/HeaderElementIterator.java
Java
gpl3
1,896
<html> <head> <!-- /* * ==================================================================== * 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 * <http://www.apache.org/>. * */ --> </head> <body> The blocking I/O abstraction of the HTTP components. <p/> This layer defines interfaces for transferring basic elements of HTTP messages over connections. </body> </html>
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/io/package.html
HTML
gpl3
1,393
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.io; /** * The point of access to the statistics of {@link SessionInputBuffer} or * {@link SessionOutputBuffer}. * * @since 4.0 */ public interface HttpTransportMetrics { /** * Returns the number of bytes transferred. */ long getBytesTransferred(); /** * Resets the counts */ void reset(); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/io/HttpTransportMetrics.java
Java
gpl3
1,549
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.io; import java.io.IOException; import org.apache.ogt.http.util.CharArrayBuffer; /** * Session input buffer for blocking connections. This interface is similar to * InputStream class, but it also provides methods for reading lines of text. * <p> * Implementing classes are also expected to manage intermediate data buffering * for optimal input performance. * * @since 4.0 */ public interface SessionInputBuffer { /** * Reads up to <code>len</code> bytes of data from the session buffer into * an array of bytes. An attempt is made to read as many as * <code>len</code> bytes, but a smaller number may be read, possibly * zero. The number of bytes actually read is returned as an integer. * * <p> This method blocks until input data is available, end of file is * detected, or an exception is thrown. * * <p> If <code>off</code> is negative, or <code>len</code> is negative, or * <code>off+len</code> is greater than the length of the array * <code>b</code>, then an <code>IndexOutOfBoundsException</code> is * thrown. * * @param b the buffer into which the data is read. * @param off the start offset in array <code>b</code> * at which the data is written. * @param len the maximum number of bytes to read. * @return the total number of bytes read into the buffer, or * <code>-1</code> if there is no more data because the end of * the stream has been reached. * @exception IOException if an I/O error occurs. */ int read(byte[] b, int off, int len) throws IOException; /** * Reads some number of bytes from the session buffer and stores them into * the buffer array <code>b</code>. The number of bytes actually read is * returned as an integer. This method blocks until input data is * available, end of file is detected, or an exception is thrown. * * @param b the buffer into which the data is read. * @return the total number of bytes read into the buffer, or * <code>-1</code> is there is no more data because the end of * the stream has been reached. * @exception IOException if an I/O error occurs. */ int read(byte[] b) throws IOException; /** * Reads the next byte of data from this session buffer. The value byte is * returned as an <code>int</code> in the range <code>0</code> to * <code>255</code>. If no byte is available because the end of the stream * has been reached, the value <code>-1</code> is returned. This method * blocks until input data is available, the end of the stream is detected, * or an exception is thrown. * * @return the next byte of data, or <code>-1</code> if the end of the * stream is reached. * @exception IOException if an I/O error occurs. */ int read() throws IOException; /** * Reads a complete line of characters up to a line delimiter from this * session buffer into the given line buffer. The number of chars actually * read is returned as an integer. The line delimiter itself is discarded. * If no char is available because the end of the stream has been reached, * the value <code>-1</code> is returned. This method blocks until input * data is available, end of file is detected, or an exception is thrown. * <p> * The choice of a char encoding and line delimiter sequence is up to the * specific implementations of this interface. * * @param buffer the line buffer. * @return one line of characters * @exception IOException if an I/O error occurs. */ int readLine(CharArrayBuffer buffer) throws IOException; /** * Reads a complete line of characters up to a line delimiter from this * session buffer. The line delimiter itself is discarded. If no char is * available because the end of the stream has been reached, * <code>null</code> is returned. This method blocks until input data is * available, end of file is detected, or an exception is thrown. * <p> * The choice of a char encoding and line delimiter sequence is up to the * specific implementations of this interface. * * @return HTTP line as a string * @exception IOException if an I/O error occurs. */ String readLine() throws IOException; /** Blocks until some data becomes available in the session buffer or the * given timeout period in milliseconds elapses. If the timeout value is * <code>0</code> this method blocks indefinitely. * * @param timeout in milliseconds. * @return <code>true</code> if some data is available in the session * buffer or <code>false</code> otherwise. * @exception IOException if an I/O error occurs. */ boolean isDataAvailable(int timeout) throws IOException; /** * Returns {@link HttpTransportMetrics} for this session buffer. * * @return transport metrics. */ HttpTransportMetrics getMetrics(); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/io/SessionInputBuffer.java
Java
gpl3
6,390
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.io; import java.io.IOException; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpMessage; /** * Abstract message writer intended to serialize HTTP messages to an arbitrary * data sink. * * @since 4.0 */ public interface HttpMessageWriter { /** * Serializes an instance of {@link HttpMessage} to the underlying data * sink. * * @param message * @throws IOException in case of an I/O error * @throws HttpException in case of HTTP protocol violation */ void write(HttpMessage message) throws IOException, HttpException; }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/io/HttpMessageWriter.java
Java
gpl3
1,817
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.io; /** * EOF sensor. * * @since 4.0 */ public interface EofSensor { boolean isEof(); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/io/EofSensor.java
Java
gpl3
1,312
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.io; import java.io.IOException; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpMessage; /** * Abstract message parser intended to build HTTP messages from an arbitrary * data source. * * @since 4.0 */ public interface HttpMessageParser { /** * Generates an instance of {@link HttpMessage} from the underlying data * source. * * @return HTTP message * @throws IOException in case of an I/O error * @throws HttpException in case of HTTP protocol violation */ HttpMessage parse() throws IOException, HttpException; }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/io/HttpMessageParser.java
Java
gpl3
1,814
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.io; import java.io.IOException; import org.apache.ogt.http.util.CharArrayBuffer; /** * Session output buffer for blocking connections. This interface is similar to * OutputStream class, but it also provides methods for writing lines of text. * <p> * Implementing classes are also expected to manage intermediate data buffering * for optimal output performance. * * @since 4.0 */ public interface SessionOutputBuffer { /** * Writes <code>len</code> bytes from the specified byte array * starting at offset <code>off</code> to this session buffer. * <p> * If <code>off</code> is negative, or <code>len</code> is negative, or * <code>off+len</code> is greater than the length of the array * <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown. * * @param b the data. * @param off the start offset in the data. * @param len the number of bytes to write. * @exception IOException if an I/O error occurs. */ void write(byte[] b, int off, int len) throws IOException; /** * Writes <code>b.length</code> bytes from the specified byte array * to this session buffer. * * @param b the data. * @exception IOException if an I/O error occurs. */ void write(byte[] b) throws IOException; /** * Writes the specified byte to this session buffer. * * @param b the <code>byte</code>. * @exception IOException if an I/O error occurs. */ void write(int b) throws IOException; /** * Writes characters from the specified string followed by a line delimiter * to this session buffer. * <p> * The choice of a char encoding and line delimiter sequence is up to the * specific implementations of this interface. * * @param s the line. * @exception IOException if an I/O error occurs. */ void writeLine(String s) throws IOException; /** * Writes characters from the specified char array followed by a line * delimiter to this session buffer. * <p> * The choice of a char encoding and line delimiter sequence is up to the * specific implementations of this interface. * * @param buffer the buffer containing chars of the line. * @exception IOException if an I/O error occurs. */ void writeLine(CharArrayBuffer buffer) throws IOException; /** * Flushes this session buffer and forces any buffered output bytes * to be written out. The general contract of <code>flush</code> is * that calling it is an indication that, if any bytes previously * written have been buffered by the implementation of the output * stream, such bytes should immediately be written to their * intended destination. * * @exception IOException if an I/O error occurs. */ void flush() throws IOException; /** * Returns {@link HttpTransportMetrics} for this session buffer. * * @return transport metrics. */ HttpTransportMetrics getMetrics(); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/io/SessionOutputBuffer.java
Java
gpl3
4,326
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.io; /** * Basic buffer properties. * * @since 4.1 */ public interface BufferInfo { /** * Return length data stored in the buffer * * @return data length */ int length(); /** * Returns total capacity of the buffer * * @return total capacity */ int capacity(); /** * Returns available space in the buffer. * * @return available space. */ int available(); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/io/BufferInfo.java
Java
gpl3
1,661
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http; /** * A name / value pair parameter used as an element of HTTP messages. * <pre> * parameter = attribute "=" value * attribute = token * value = token | quoted-string * </pre> * * * @since 4.0 */ public interface NameValuePair { String getName(); String getValue(); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/NameValuePair.java
Java
gpl3
1,550
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http; /** * Constants enumerating the HTTP status codes. * All status codes defined in RFC1945 (HTTP/1.0), RFC2616 (HTTP/1.1), and * RFC2518 (WebDAV) are listed. * * @see StatusLine * * @since 4.0 */ public interface HttpStatus { // --- 1xx Informational --- /** <tt>100 Continue</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_CONTINUE = 100; /** <tt>101 Switching Protocols</tt> (HTTP/1.1 - RFC 2616)*/ public static final int SC_SWITCHING_PROTOCOLS = 101; /** <tt>102 Processing</tt> (WebDAV - RFC 2518) */ public static final int SC_PROCESSING = 102; // --- 2xx Success --- /** <tt>200 OK</tt> (HTTP/1.0 - RFC 1945) */ public static final int SC_OK = 200; /** <tt>201 Created</tt> (HTTP/1.0 - RFC 1945) */ public static final int SC_CREATED = 201; /** <tt>202 Accepted</tt> (HTTP/1.0 - RFC 1945) */ public static final int SC_ACCEPTED = 202; /** <tt>203 Non Authoritative Information</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_NON_AUTHORITATIVE_INFORMATION = 203; /** <tt>204 No Content</tt> (HTTP/1.0 - RFC 1945) */ public static final int SC_NO_CONTENT = 204; /** <tt>205 Reset Content</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_RESET_CONTENT = 205; /** <tt>206 Partial Content</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_PARTIAL_CONTENT = 206; /** * <tt>207 Multi-Status</tt> (WebDAV - RFC 2518) or <tt>207 Partial Update * OK</tt> (HTTP/1.1 - draft-ietf-http-v11-spec-rev-01?) */ public static final int SC_MULTI_STATUS = 207; // --- 3xx Redirection --- /** <tt>300 Mutliple Choices</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_MULTIPLE_CHOICES = 300; /** <tt>301 Moved Permanently</tt> (HTTP/1.0 - RFC 1945) */ public static final int SC_MOVED_PERMANENTLY = 301; /** <tt>302 Moved Temporarily</tt> (Sometimes <tt>Found</tt>) (HTTP/1.0 - RFC 1945) */ public static final int SC_MOVED_TEMPORARILY = 302; /** <tt>303 See Other</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_SEE_OTHER = 303; /** <tt>304 Not Modified</tt> (HTTP/1.0 - RFC 1945) */ public static final int SC_NOT_MODIFIED = 304; /** <tt>305 Use Proxy</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_USE_PROXY = 305; /** <tt>307 Temporary Redirect</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_TEMPORARY_REDIRECT = 307; // --- 4xx Client Error --- /** <tt>400 Bad Request</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_BAD_REQUEST = 400; /** <tt>401 Unauthorized</tt> (HTTP/1.0 - RFC 1945) */ public static final int SC_UNAUTHORIZED = 401; /** <tt>402 Payment Required</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_PAYMENT_REQUIRED = 402; /** <tt>403 Forbidden</tt> (HTTP/1.0 - RFC 1945) */ public static final int SC_FORBIDDEN = 403; /** <tt>404 Not Found</tt> (HTTP/1.0 - RFC 1945) */ public static final int SC_NOT_FOUND = 404; /** <tt>405 Method Not Allowed</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_METHOD_NOT_ALLOWED = 405; /** <tt>406 Not Acceptable</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_NOT_ACCEPTABLE = 406; /** <tt>407 Proxy Authentication Required</tt> (HTTP/1.1 - RFC 2616)*/ public static final int SC_PROXY_AUTHENTICATION_REQUIRED = 407; /** <tt>408 Request Timeout</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_REQUEST_TIMEOUT = 408; /** <tt>409 Conflict</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_CONFLICT = 409; /** <tt>410 Gone</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_GONE = 410; /** <tt>411 Length Required</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_LENGTH_REQUIRED = 411; /** <tt>412 Precondition Failed</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_PRECONDITION_FAILED = 412; /** <tt>413 Request Entity Too Large</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_REQUEST_TOO_LONG = 413; /** <tt>414 Request-URI Too Long</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_REQUEST_URI_TOO_LONG = 414; /** <tt>415 Unsupported Media Type</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_UNSUPPORTED_MEDIA_TYPE = 415; /** <tt>416 Requested Range Not Satisfiable</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_REQUESTED_RANGE_NOT_SATISFIABLE = 416; /** <tt>417 Expectation Failed</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_EXPECTATION_FAILED = 417; /** * Static constant for a 418 error. * <tt>418 Unprocessable Entity</tt> (WebDAV drafts?) * or <tt>418 Reauthentication Required</tt> (HTTP/1.1 drafts?) */ // not used // public static final int SC_UNPROCESSABLE_ENTITY = 418; /** * Static constant for a 419 error. * <tt>419 Insufficient Space on Resource</tt> * (WebDAV - draft-ietf-webdav-protocol-05?) * or <tt>419 Proxy Reauthentication Required</tt> * (HTTP/1.1 drafts?) */ public static final int SC_INSUFFICIENT_SPACE_ON_RESOURCE = 419; /** * Static constant for a 420 error. * <tt>420 Method Failure</tt> * (WebDAV - draft-ietf-webdav-protocol-05?) */ public static final int SC_METHOD_FAILURE = 420; /** <tt>422 Unprocessable Entity</tt> (WebDAV - RFC 2518) */ public static final int SC_UNPROCESSABLE_ENTITY = 422; /** <tt>423 Locked</tt> (WebDAV - RFC 2518) */ public static final int SC_LOCKED = 423; /** <tt>424 Failed Dependency</tt> (WebDAV - RFC 2518) */ public static final int SC_FAILED_DEPENDENCY = 424; // --- 5xx Server Error --- /** <tt>500 Server Error</tt> (HTTP/1.0 - RFC 1945) */ public static final int SC_INTERNAL_SERVER_ERROR = 500; /** <tt>501 Not Implemented</tt> (HTTP/1.0 - RFC 1945) */ public static final int SC_NOT_IMPLEMENTED = 501; /** <tt>502 Bad Gateway</tt> (HTTP/1.0 - RFC 1945) */ public static final int SC_BAD_GATEWAY = 502; /** <tt>503 Service Unavailable</tt> (HTTP/1.0 - RFC 1945) */ public static final int SC_SERVICE_UNAVAILABLE = 503; /** <tt>504 Gateway Timeout</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_GATEWAY_TIMEOUT = 504; /** <tt>505 HTTP Version Not Supported</tt> (HTTP/1.1 - RFC 2616) */ public static final int SC_HTTP_VERSION_NOT_SUPPORTED = 505; /** <tt>507 Insufficient Storage</tt> (WebDAV - RFC 2518) */ public static final int SC_INSUFFICIENT_STORAGE = 507; }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/HttpStatus.java
Java
gpl3
7,818
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http; /** * Signals that an HTTP method is not supported. * * @since 4.0 */ public class MethodNotSupportedException extends HttpException { private static final long serialVersionUID = 3365359036840171201L; /** * Creates a new MethodNotSupportedException with the specified detail message. * * @param message The exception detail message */ public MethodNotSupportedException(final String message) { super(message); } /** * Creates a new MethodNotSupportedException with the specified detail message and cause. * * @param message the exception detail message * @param cause the <tt>Throwable</tt> that caused this exception, or <tt>null</tt> * if the cause is unavailable, unknown, or not a <tt>Throwable</tt> */ public MethodNotSupportedException(final String message, final Throwable cause) { super(message, cause); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/MethodNotSupportedException.java
Java
gpl3
2,134
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http; import java.io.IOException; /** * Signals that the target server failed to respond with a valid HTTP response. * * @since 4.0 */ public class NoHttpResponseException extends IOException { private static final long serialVersionUID = -7658940387386078766L; /** * Creates a new NoHttpResponseException with the specified detail message. * * @param message exception message */ public NoHttpResponseException(String message) { super(message); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/NoHttpResponseException.java
Java
gpl3
1,711
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http; /** * The first line of a Response message is the Status-Line, consisting * of the protocol version followed by a numeric status code and its * associated textual phrase, with each element separated by SP * characters. No CR or LF is allowed except in the final CRLF sequence. * <pre> * Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF * </pre> * * @see HttpStatus * @version $Id: StatusLine.java 937295 2010-04-23 13:44:00Z olegk $ * * @since 4.0 */ public interface StatusLine { ProtocolVersion getProtocolVersion(); int getStatusCode(); String getReasonPhrase(); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/StatusLine.java
Java
gpl3
1,831
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http; import java.io.IOException; /** * A generic HTTP connection, useful on client and server side. * * @since 4.0 */ public interface HttpConnection { /** * Closes this connection gracefully. * This method will attempt to flush the internal output * buffer prior to closing the underlying socket. * This method MUST NOT be called from a different thread to force * shutdown of the connection. Use {@link #shutdown shutdown} instead. */ public void close() throws IOException; /** * Checks if this connection is open. * @return true if it is open, false if it is closed. */ public boolean isOpen(); /** * Checks whether this connection has gone down. * Network connections may get closed during some time of inactivity * for several reasons. The next time a read is attempted on such a * connection it will throw an IOException. * This method tries to alleviate this inconvenience by trying to * find out if a connection is still usable. Implementations may do * that by attempting a read with a very small timeout. Thus this * method may block for a small amount of time before returning a result. * It is therefore an <i>expensive</i> operation. * * @return <code>true</code> if attempts to use this connection are * likely to succeed, or <code>false</code> if they are likely * to fail and this connection should be closed */ public boolean isStale(); /** * Sets the socket timeout value. * * @param timeout timeout value in milliseconds */ void setSocketTimeout(int timeout); /** * Returns the socket timeout value. * * @return positive value in milliseconds if a timeout is set, * <code>0</code> if timeout is disabled or <code>-1</code> if * timeout is undefined. */ int getSocketTimeout(); /** * Force-closes this connection. * This is the only method of a connection which may be called * from a different thread to terminate the connection. * This method will not attempt to flush the transmitter's * internal buffer prior to closing the underlying socket. */ public void shutdown() throws IOException; /** * Returns a collection of connection metrics. * * @return HttpConnectionMetrics */ HttpConnectionMetrics getMetrics(); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/HttpConnection.java
Java
gpl3
3,650
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import org.apache.ogt.http.HeaderElement; import org.apache.ogt.http.NameValuePair; import org.apache.ogt.http.util.CharArrayBuffer; import org.apache.ogt.http.util.LangUtils; /** * Basic implementation of {@link HeaderElement} * * @since 4.0 */ public class BasicHeaderElement implements HeaderElement, Cloneable { private final String name; private final String value; private final NameValuePair[] parameters; /** * Constructor with name, value and parameters. * * @param name header element name * @param value header element value. May be <tt>null</tt> * @param parameters header element parameters. May be <tt>null</tt>. * Parameters are copied by reference, not by value */ public BasicHeaderElement( final String name, final String value, final NameValuePair[] parameters) { super(); if (name == null) { throw new IllegalArgumentException("Name may not be null"); } this.name = name; this.value = value; if (parameters != null) { this.parameters = parameters; } else { this.parameters = new NameValuePair[] {}; } } /** * Constructor with name and value. * * @param name header element name * @param value header element value. May be <tt>null</tt> */ public BasicHeaderElement(final String name, final String value) { this(name, value, null); } public String getName() { return this.name; } public String getValue() { return this.value; } public NameValuePair[] getParameters() { return (NameValuePair[])this.parameters.clone(); } public int getParameterCount() { return this.parameters.length; } public NameValuePair getParameter(int index) { // ArrayIndexOutOfBoundsException is appropriate return this.parameters[index]; } public NameValuePair getParameterByName(final String name) { if (name == null) { throw new IllegalArgumentException("Name may not be null"); } NameValuePair found = null; for (int i = 0; i < this.parameters.length; i++) { NameValuePair current = this.parameters[ i ]; if (current.getName().equalsIgnoreCase(name)) { found = current; break; } } return found; } public boolean equals(final Object object) { if (this == object) return true; if (object instanceof HeaderElement) { BasicHeaderElement that = (BasicHeaderElement) object; return this.name.equals(that.name) && LangUtils.equals(this.value, that.value) && LangUtils.equals(this.parameters, that.parameters); } else { return false; } } public int hashCode() { int hash = LangUtils.HASH_SEED; hash = LangUtils.hashCode(hash, this.name); hash = LangUtils.hashCode(hash, this.value); for (int i = 0; i < this.parameters.length; i++) { hash = LangUtils.hashCode(hash, this.parameters[i]); } return hash; } public String toString() { CharArrayBuffer buffer = new CharArrayBuffer(64); buffer.append(this.name); if (this.value != null) { buffer.append("="); buffer.append(this.value); } for (int i = 0; i < this.parameters.length; i++) { buffer.append("; "); buffer.append(this.parameters[i]); } return buffer.toString(); } public Object clone() throws CloneNotSupportedException { // parameters array is considered immutable // no need to make a copy of it return super.clone(); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicHeaderElement.java
Java
gpl3
5,096
<html> <head> <!-- /* * ==================================================================== * 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 * <http://www.apache.org/>. * */ --> </head> <body> A selection of HTTP message implementations. There are basic implementations for HTTP requests {@link org.apache.ogt.http.message.BasicHttpEntityEnclosingRequest with} and {@link org.apache.ogt.http.message.BasicHttpRequest without} an entity, and for {@link org.apache.ogt.http.message.BasicHttpResponse responses}. </body> </html>
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/package.html
HTML
gpl3
1,558
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import org.apache.ogt.http.Header; import org.apache.ogt.http.HttpEntity; import org.apache.ogt.http.HttpEntityEnclosingRequest; import org.apache.ogt.http.ProtocolVersion; import org.apache.ogt.http.RequestLine; import org.apache.ogt.http.protocol.HTTP; /** * Basic implementation of {@link HttpEntityEnclosingRequest}. * * @since 4.0 */ public class BasicHttpEntityEnclosingRequest extends BasicHttpRequest implements HttpEntityEnclosingRequest { private HttpEntity entity; public BasicHttpEntityEnclosingRequest(final String method, final String uri) { super(method, uri); } public BasicHttpEntityEnclosingRequest(final String method, final String uri, final ProtocolVersion ver) { super(method, uri, ver); } public BasicHttpEntityEnclosingRequest(final RequestLine requestline) { super(requestline); } public HttpEntity getEntity() { return this.entity; } public void setEntity(final HttpEntity entity) { this.entity = entity; } public boolean expectContinue() { Header expect = getFirstHeader(HTTP.EXPECT_DIRECTIVE); return expect != null && HTTP.EXPECT_CONTINUE.equalsIgnoreCase(expect.getValue()); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicHttpEntityEnclosingRequest.java
Java
gpl3
2,477
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import java.util.NoSuchElementException; import org.apache.ogt.http.FormattedHeader; import org.apache.ogt.http.Header; import org.apache.ogt.http.HeaderElement; import org.apache.ogt.http.HeaderElementIterator; import org.apache.ogt.http.HeaderIterator; import org.apache.ogt.http.util.CharArrayBuffer; /** * Basic implementation of a {@link HeaderElementIterator}. * * @since 4.0 */ public class BasicHeaderElementIterator implements HeaderElementIterator { private final HeaderIterator headerIt; private final HeaderValueParser parser; private HeaderElement currentElement = null; private CharArrayBuffer buffer = null; private ParserCursor cursor = null; /** * Creates a new instance of BasicHeaderElementIterator */ public BasicHeaderElementIterator( final HeaderIterator headerIterator, final HeaderValueParser parser) { if (headerIterator == null) { throw new IllegalArgumentException("Header iterator may not be null"); } if (parser == null) { throw new IllegalArgumentException("Parser may not be null"); } this.headerIt = headerIterator; this.parser = parser; } public BasicHeaderElementIterator(final HeaderIterator headerIterator) { this(headerIterator, BasicHeaderValueParser.DEFAULT); } private void bufferHeaderValue() { this.cursor = null; this.buffer = null; while (this.headerIt.hasNext()) { Header h = this.headerIt.nextHeader(); if (h instanceof FormattedHeader) { this.buffer = ((FormattedHeader) h).getBuffer(); this.cursor = new ParserCursor(0, this.buffer.length()); this.cursor.updatePos(((FormattedHeader) h).getValuePos()); break; } else { String value = h.getValue(); if (value != null) { this.buffer = new CharArrayBuffer(value.length()); this.buffer.append(value); this.cursor = new ParserCursor(0, this.buffer.length()); break; } } } } private void parseNextElement() { // loop while there are headers left to parse while (this.headerIt.hasNext() || this.cursor != null) { if (this.cursor == null || this.cursor.atEnd()) { // get next header value bufferHeaderValue(); } // Anything buffered? if (this.cursor != null) { // loop while there is data in the buffer while (!this.cursor.atEnd()) { HeaderElement e = this.parser.parseHeaderElement(this.buffer, this.cursor); if (!(e.getName().length() == 0 && e.getValue() == null)) { // Found something this.currentElement = e; return; } } // if at the end of the buffer if (this.cursor.atEnd()) { // discard it this.cursor = null; this.buffer = null; } } } } public boolean hasNext() { if (this.currentElement == null) { parseNextElement(); } return this.currentElement != null; } public HeaderElement nextElement() throws NoSuchElementException { if (this.currentElement == null) { parseNextElement(); } if (this.currentElement == null) { throw new NoSuchElementException("No more header elements available"); } HeaderElement element = this.currentElement; this.currentElement = null; return element; } public final Object next() throws NoSuchElementException { return nextElement(); } public void remove() throws UnsupportedOperationException { throw new UnsupportedOperationException("Remove not supported"); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicHeaderElementIterator.java
Java
gpl3
5,347
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import org.apache.ogt.http.HeaderElement; import org.apache.ogt.http.NameValuePair; import org.apache.ogt.http.util.CharArrayBuffer; /** * Interface for formatting elements of a header value. * This is the complement to {@link HeaderValueParser}. * Instances of this interface are expected to be stateless and thread-safe. * * <p> * All formatting methods accept an optional buffer argument. * If a buffer is passed in, the formatted element will be appended * and the modified buffer is returned. If no buffer is passed in, * a new buffer will be created and filled with the formatted element. * In both cases, the caller is allowed to modify the returned buffer. * </p> * * @since 4.0 */ public interface HeaderValueFormatter { /** * Formats an array of header elements. * * @param buffer the buffer to append to, or * <code>null</code> to create a new buffer * @param elems the header elements to format * @param quote <code>true</code> to always format with quoted values, * <code>false</code> to use quotes only when necessary * * @return a buffer with the formatted header elements. * If the <code>buffer</code> argument was not <code>null</code>, * that buffer will be used and returned. */ CharArrayBuffer formatElements(CharArrayBuffer buffer, HeaderElement[] elems, boolean quote); /** * Formats one header element. * * @param buffer the buffer to append to, or * <code>null</code> to create a new buffer * @param elem the header element to format * @param quote <code>true</code> to always format with quoted values, * <code>false</code> to use quotes only when necessary * * @return a buffer with the formatted header element. * If the <code>buffer</code> argument was not <code>null</code>, * that buffer will be used and returned. */ CharArrayBuffer formatHeaderElement(CharArrayBuffer buffer, HeaderElement elem, boolean quote); /** * Formats the parameters of a header element. * That's a list of name-value pairs, to be separated by semicolons. * This method will <i>not</i> generate a leading semicolon. * * @param buffer the buffer to append to, or * <code>null</code> to create a new buffer * @param nvps the parameters (name-value pairs) to format * @param quote <code>true</code> to always format with quoted values, * <code>false</code> to use quotes only when necessary * * @return a buffer with the formatted parameters. * If the <code>buffer</code> argument was not <code>null</code>, * that buffer will be used and returned. */ CharArrayBuffer formatParameters(CharArrayBuffer buffer, NameValuePair[] nvps, boolean quote); /** * Formats one name-value pair, where the value is optional. * * @param buffer the buffer to append to, or * <code>null</code> to create a new buffer * @param nvp the name-value pair to format * @param quote <code>true</code> to always format with a quoted value, * <code>false</code> to use quotes only when necessary * * @return a buffer with the formatted name-value pair. * If the <code>buffer</code> argument was not <code>null</code>, * that buffer will be used and returned. */ CharArrayBuffer formatNameValuePair(CharArrayBuffer buffer, NameValuePair nvp, boolean quote); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/HeaderValueFormatter.java
Java
gpl3
5,225
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import java.util.Locale; import org.apache.ogt.http.HttpEntity; import org.apache.ogt.http.HttpResponse; import org.apache.ogt.http.ProtocolVersion; import org.apache.ogt.http.ReasonPhraseCatalog; import org.apache.ogt.http.StatusLine; /** * Basic implementation of {@link HttpResponse}. * * @since 4.0 */ public class BasicHttpResponse extends AbstractHttpMessage implements HttpResponse { private StatusLine statusline; private HttpEntity entity; private ReasonPhraseCatalog reasonCatalog; private Locale locale; /** * Creates a new response. * This is the constructor to which all others map. * * @param statusline the status line * @param catalog the reason phrase catalog, or * <code>null</code> to disable automatic * reason phrase lookup * @param locale the locale for looking up reason phrases, or * <code>null</code> for the system locale */ public BasicHttpResponse(final StatusLine statusline, final ReasonPhraseCatalog catalog, final Locale locale) { super(); if (statusline == null) { throw new IllegalArgumentException("Status line may not be null."); } this.statusline = statusline; this.reasonCatalog = catalog; this.locale = (locale != null) ? locale : Locale.getDefault(); } /** * Creates a response from a status line. * The response will not have a reason phrase catalog and * use the system default locale. * * @param statusline the status line */ public BasicHttpResponse(final StatusLine statusline) { this(statusline, null, null); } /** * Creates a response from elements of a status line. * The response will not have a reason phrase catalog and * use the system default locale. * * @param ver the protocol version of the response * @param code the status code of the response * @param reason the reason phrase to the status code, or * <code>null</code> */ public BasicHttpResponse(final ProtocolVersion ver, final int code, final String reason) { this(new BasicStatusLine(ver, code, reason), null, null); } // non-javadoc, see interface HttpMessage public ProtocolVersion getProtocolVersion() { return this.statusline.getProtocolVersion(); } // non-javadoc, see interface HttpResponse public StatusLine getStatusLine() { return this.statusline; } // non-javadoc, see interface HttpResponse public HttpEntity getEntity() { return this.entity; } // non-javadoc, see interface HttpResponse public Locale getLocale() { return this.locale; } // non-javadoc, see interface HttpResponse public void setStatusLine(final StatusLine statusline) { if (statusline == null) { throw new IllegalArgumentException("Status line may not be null"); } this.statusline = statusline; } // non-javadoc, see interface HttpResponse public void setStatusLine(final ProtocolVersion ver, final int code) { // arguments checked in BasicStatusLine constructor this.statusline = new BasicStatusLine(ver, code, getReason(code)); } // non-javadoc, see interface HttpResponse public void setStatusLine(final ProtocolVersion ver, final int code, final String reason) { // arguments checked in BasicStatusLine constructor this.statusline = new BasicStatusLine(ver, code, reason); } // non-javadoc, see interface HttpResponse public void setStatusCode(int code) { // argument checked in BasicStatusLine constructor ProtocolVersion ver = this.statusline.getProtocolVersion(); this.statusline = new BasicStatusLine(ver, code, getReason(code)); } // non-javadoc, see interface HttpResponse public void setReasonPhrase(String reason) { if ((reason != null) && ((reason.indexOf('\n') >= 0) || (reason.indexOf('\r') >= 0)) ) { throw new IllegalArgumentException("Line break in reason phrase."); } this.statusline = new BasicStatusLine(this.statusline.getProtocolVersion(), this.statusline.getStatusCode(), reason); } // non-javadoc, see interface HttpResponse public void setEntity(final HttpEntity entity) { this.entity = entity; } // non-javadoc, see interface HttpResponse public void setLocale(Locale loc) { if (loc == null) { throw new IllegalArgumentException("Locale may not be null."); } this.locale = loc; final int code = this.statusline.getStatusCode(); this.statusline = new BasicStatusLine (this.statusline.getProtocolVersion(), code, getReason(code)); } /** * Looks up a reason phrase. * This method evaluates the currently set catalog and locale. * It also handles a missing catalog. * * @param code the status code for which to look up the reason * * @return the reason phrase, or <code>null</code> if there is none */ protected String getReason(int code) { return (this.reasonCatalog == null) ? null : this.reasonCatalog.getReason(code, this.locale); } public String toString() { return this.statusline + " " + this.headergroup; } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicHttpResponse.java
Java
gpl3
7,063
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import java.util.Iterator; import org.apache.ogt.http.Header; import org.apache.ogt.http.HeaderIterator; import org.apache.ogt.http.HttpMessage; import org.apache.ogt.http.params.BasicHttpParams; import org.apache.ogt.http.params.HttpParams; /** * Basic implementation of {@link HttpMessage}. * * @since 4.0 */ public abstract class AbstractHttpMessage implements HttpMessage { protected HeaderGroup headergroup; protected HttpParams params; protected AbstractHttpMessage(final HttpParams params) { super(); this.headergroup = new HeaderGroup(); this.params = params; } protected AbstractHttpMessage() { this(null); } // non-javadoc, see interface HttpMessage public boolean containsHeader(String name) { return this.headergroup.containsHeader(name); } // non-javadoc, see interface HttpMessage public Header[] getHeaders(final String name) { return this.headergroup.getHeaders(name); } // non-javadoc, see interface HttpMessage public Header getFirstHeader(final String name) { return this.headergroup.getFirstHeader(name); } // non-javadoc, see interface HttpMessage public Header getLastHeader(final String name) { return this.headergroup.getLastHeader(name); } // non-javadoc, see interface HttpMessage public Header[] getAllHeaders() { return this.headergroup.getAllHeaders(); } // non-javadoc, see interface HttpMessage public void addHeader(final Header header) { this.headergroup.addHeader(header); } // non-javadoc, see interface HttpMessage public void addHeader(final String name, final String value) { if (name == null) { throw new IllegalArgumentException("Header name may not be null"); } this.headergroup.addHeader(new BasicHeader(name, value)); } // non-javadoc, see interface HttpMessage public void setHeader(final Header header) { this.headergroup.updateHeader(header); } // non-javadoc, see interface HttpMessage public void setHeader(final String name, final String value) { if (name == null) { throw new IllegalArgumentException("Header name may not be null"); } this.headergroup.updateHeader(new BasicHeader(name, value)); } // non-javadoc, see interface HttpMessage public void setHeaders(final Header[] headers) { this.headergroup.setHeaders(headers); } // non-javadoc, see interface HttpMessage public void removeHeader(final Header header) { this.headergroup.removeHeader(header); } // non-javadoc, see interface HttpMessage public void removeHeaders(final String name) { if (name == null) { return; } for (Iterator i = this.headergroup.iterator(); i.hasNext(); ) { Header header = (Header) i.next(); if (name.equalsIgnoreCase(header.getName())) { i.remove(); } } } // non-javadoc, see interface HttpMessage public HeaderIterator headerIterator() { return this.headergroup.iterator(); } // non-javadoc, see interface HttpMessage public HeaderIterator headerIterator(String name) { return this.headergroup.iterator(name); } // non-javadoc, see interface HttpMessage public HttpParams getParams() { if (this.params == null) { this.params = new BasicHttpParams(); } return this.params; } // non-javadoc, see interface HttpMessage public void setParams(final HttpParams params) { if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } this.params = params; } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/AbstractHttpMessage.java
Java
gpl3
5,049
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import org.apache.ogt.http.FormattedHeader; import org.apache.ogt.http.Header; import org.apache.ogt.http.ProtocolVersion; import org.apache.ogt.http.RequestLine; import org.apache.ogt.http.StatusLine; import org.apache.ogt.http.util.CharArrayBuffer; /** * Interface for formatting elements of the HEAD section of an HTTP message. * This is the complement to {@link LineParser}. * There are individual methods for formatting a request line, a * status line, or a header line. The formatting does <i>not</i> include the * trailing line break sequence CR-LF. * The formatted lines are returned in memory, the formatter does not depend * on any specific IO mechanism. * Instances of this interface are expected to be stateless and thread-safe. * * @since 4.0 */ public class BasicLineFormatter implements LineFormatter { /** * A default instance of this class, for use as default or fallback. * Note that {@link BasicLineFormatter} is not a singleton, there can * be many instances of the class itself and of derived classes. * The instance here provides non-customized, default behavior. */ public final static BasicLineFormatter DEFAULT = new BasicLineFormatter(); // public default constructor /** * Obtains a buffer for formatting. * * @param buffer a buffer already available, or <code>null</code> * * @return the cleared argument buffer if there is one, or * a new empty buffer that can be used for formatting */ protected CharArrayBuffer initBuffer(CharArrayBuffer buffer) { if (buffer != null) { buffer.clear(); } else { buffer = new CharArrayBuffer(64); } return buffer; } /** * Formats a protocol version. * * @param version the protocol version to format * @param formatter the formatter to use, or * <code>null</code> for the * {@link #DEFAULT default} * * @return the formatted protocol version */ public final static String formatProtocolVersion(final ProtocolVersion version, LineFormatter formatter) { if (formatter == null) formatter = BasicLineFormatter.DEFAULT; return formatter.appendProtocolVersion(null, version).toString(); } // non-javadoc, see interface LineFormatter public CharArrayBuffer appendProtocolVersion(final CharArrayBuffer buffer, final ProtocolVersion version) { if (version == null) { throw new IllegalArgumentException ("Protocol version may not be null"); } // can't use initBuffer, that would clear the argument! CharArrayBuffer result = buffer; final int len = estimateProtocolVersionLen(version); if (result == null) { result = new CharArrayBuffer(len); } else { result.ensureCapacity(len); } result.append(version.getProtocol()); result.append('/'); result.append(Integer.toString(version.getMajor())); result.append('.'); result.append(Integer.toString(version.getMinor())); return result; } /** * Guesses the length of a formatted protocol version. * Needed to guess the length of a formatted request or status line. * * @param version the protocol version to format, or <code>null</code> * * @return the estimated length of the formatted protocol version, * in characters */ protected int estimateProtocolVersionLen(final ProtocolVersion version) { return version.getProtocol().length() + 4; // room for "HTTP/1.1" } /** * Formats a request line. * * @param reqline the request line to format * @param formatter the formatter to use, or * <code>null</code> for the * {@link #DEFAULT default} * * @return the formatted request line */ public final static String formatRequestLine(final RequestLine reqline, LineFormatter formatter) { if (formatter == null) formatter = BasicLineFormatter.DEFAULT; return formatter.formatRequestLine(null, reqline).toString(); } // non-javadoc, see interface LineFormatter public CharArrayBuffer formatRequestLine(CharArrayBuffer buffer, RequestLine reqline) { if (reqline == null) { throw new IllegalArgumentException ("Request line may not be null"); } CharArrayBuffer result = initBuffer(buffer); doFormatRequestLine(result, reqline); return result; } /** * Actually formats a request line. * Called from {@link #formatRequestLine}. * * @param buffer the empty buffer into which to format, * never <code>null</code> * @param reqline the request line to format, never <code>null</code> */ protected void doFormatRequestLine(final CharArrayBuffer buffer, final RequestLine reqline) { final String method = reqline.getMethod(); final String uri = reqline.getUri(); // room for "GET /index.html HTTP/1.1" int len = method.length() + 1 + uri.length() + 1 + estimateProtocolVersionLen(reqline.getProtocolVersion()); buffer.ensureCapacity(len); buffer.append(method); buffer.append(' '); buffer.append(uri); buffer.append(' '); appendProtocolVersion(buffer, reqline.getProtocolVersion()); } /** * Formats a status line. * * @param statline the status line to format * @param formatter the formatter to use, or * <code>null</code> for the * {@link #DEFAULT default} * * @return the formatted status line */ public final static String formatStatusLine(final StatusLine statline, LineFormatter formatter) { if (formatter == null) formatter = BasicLineFormatter.DEFAULT; return formatter.formatStatusLine(null, statline).toString(); } // non-javadoc, see interface LineFormatter public CharArrayBuffer formatStatusLine(final CharArrayBuffer buffer, final StatusLine statline) { if (statline == null) { throw new IllegalArgumentException ("Status line may not be null"); } CharArrayBuffer result = initBuffer(buffer); doFormatStatusLine(result, statline); return result; } /** * Actually formats a status line. * Called from {@link #formatStatusLine}. * * @param buffer the empty buffer into which to format, * never <code>null</code> * @param statline the status line to format, never <code>null</code> */ protected void doFormatStatusLine(final CharArrayBuffer buffer, final StatusLine statline) { int len = estimateProtocolVersionLen(statline.getProtocolVersion()) + 1 + 3 + 1; // room for "HTTP/1.1 200 " final String reason = statline.getReasonPhrase(); if (reason != null) { len += reason.length(); } buffer.ensureCapacity(len); appendProtocolVersion(buffer, statline.getProtocolVersion()); buffer.append(' '); buffer.append(Integer.toString(statline.getStatusCode())); buffer.append(' '); // keep whitespace even if reason phrase is empty if (reason != null) { buffer.append(reason); } } /** * Formats a header. * * @param header the header to format * @param formatter the formatter to use, or * <code>null</code> for the * {@link #DEFAULT default} * * @return the formatted header */ public final static String formatHeader(final Header header, LineFormatter formatter) { if (formatter == null) formatter = BasicLineFormatter.DEFAULT; return formatter.formatHeader(null, header).toString(); } // non-javadoc, see interface LineFormatter public CharArrayBuffer formatHeader(CharArrayBuffer buffer, Header header) { if (header == null) { throw new IllegalArgumentException ("Header may not be null"); } CharArrayBuffer result = null; if (header instanceof FormattedHeader) { // If the header is backed by a buffer, re-use the buffer result = ((FormattedHeader)header).getBuffer(); } else { result = initBuffer(buffer); doFormatHeader(result, header); } return result; } // formatHeader /** * Actually formats a header. * Called from {@link #formatHeader}. * * @param buffer the empty buffer into which to format, * never <code>null</code> * @param header the header to format, never <code>null</code> */ protected void doFormatHeader(final CharArrayBuffer buffer, final Header header) { final String name = header.getName(); final String value = header.getValue(); int len = name.length() + 2; if (value != null) { len += value.length(); } buffer.ensureCapacity(len); buffer.append(name); buffer.append(": "); if (value != null) { buffer.append(value); } } } // class BasicLineFormatter
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicLineFormatter.java
Java
gpl3
11,370
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import java.util.List; import java.util.ArrayList; import org.apache.ogt.http.HeaderElement; import org.apache.ogt.http.NameValuePair; import org.apache.ogt.http.ParseException; import org.apache.ogt.http.protocol.HTTP; import org.apache.ogt.http.util.CharArrayBuffer; /** * Basic implementation for parsing header values into elements. * Instances of this class are stateless and thread-safe. * Derived classes are expected to maintain these properties. * * @since 4.0 */ public class BasicHeaderValueParser implements HeaderValueParser { /** * A default instance of this class, for use as default or fallback. * Note that {@link BasicHeaderValueParser} is not a singleton, there * can be many instances of the class itself and of derived classes. * The instance here provides non-customized, default behavior. */ public final static BasicHeaderValueParser DEFAULT = new BasicHeaderValueParser(); private final static char PARAM_DELIMITER = ';'; private final static char ELEM_DELIMITER = ','; private final static char[] ALL_DELIMITERS = new char[] { PARAM_DELIMITER, ELEM_DELIMITER }; // public default constructor /** * Parses elements with the given parser. * * @param value the header value to parse * @param parser the parser to use, or <code>null</code> for default * * @return array holding the header elements, never <code>null</code> */ public final static HeaderElement[] parseElements(final String value, HeaderValueParser parser) throws ParseException { if (value == null) { throw new IllegalArgumentException ("Value to parse may not be null"); } if (parser == null) parser = BasicHeaderValueParser.DEFAULT; CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); ParserCursor cursor = new ParserCursor(0, value.length()); return parser.parseElements(buffer, cursor); } // non-javadoc, see interface HeaderValueParser public HeaderElement[] parseElements(final CharArrayBuffer buffer, final ParserCursor cursor) { if (buffer == null) { throw new IllegalArgumentException("Char array buffer may not be null"); } if (cursor == null) { throw new IllegalArgumentException("Parser cursor may not be null"); } List elements = new ArrayList(); while (!cursor.atEnd()) { HeaderElement element = parseHeaderElement(buffer, cursor); if (!(element.getName().length() == 0 && element.getValue() == null)) { elements.add(element); } } return (HeaderElement[]) elements.toArray(new HeaderElement[elements.size()]); } /** * Parses an element with the given parser. * * @param value the header element to parse * @param parser the parser to use, or <code>null</code> for default * * @return the parsed header element */ public final static HeaderElement parseHeaderElement(final String value, HeaderValueParser parser) throws ParseException { if (value == null) { throw new IllegalArgumentException ("Value to parse may not be null"); } if (parser == null) parser = BasicHeaderValueParser.DEFAULT; CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); ParserCursor cursor = new ParserCursor(0, value.length()); return parser.parseHeaderElement(buffer, cursor); } // non-javadoc, see interface HeaderValueParser public HeaderElement parseHeaderElement(final CharArrayBuffer buffer, final ParserCursor cursor) { if (buffer == null) { throw new IllegalArgumentException("Char array buffer may not be null"); } if (cursor == null) { throw new IllegalArgumentException("Parser cursor may not be null"); } NameValuePair nvp = parseNameValuePair(buffer, cursor); NameValuePair[] params = null; if (!cursor.atEnd()) { char ch = buffer.charAt(cursor.getPos() - 1); if (ch != ELEM_DELIMITER) { params = parseParameters(buffer, cursor); } } return createHeaderElement(nvp.getName(), nvp.getValue(), params); } /** * Creates a header element. * Called from {@link #parseHeaderElement}. * * @return a header element representing the argument */ protected HeaderElement createHeaderElement( final String name, final String value, final NameValuePair[] params) { return new BasicHeaderElement(name, value, params); } /** * Parses parameters with the given parser. * * @param value the parameter list to parse * @param parser the parser to use, or <code>null</code> for default * * @return array holding the parameters, never <code>null</code> */ public final static NameValuePair[] parseParameters(final String value, HeaderValueParser parser) throws ParseException { if (value == null) { throw new IllegalArgumentException ("Value to parse may not be null"); } if (parser == null) parser = BasicHeaderValueParser.DEFAULT; CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); ParserCursor cursor = new ParserCursor(0, value.length()); return parser.parseParameters(buffer, cursor); } // non-javadoc, see interface HeaderValueParser public NameValuePair[] parseParameters(final CharArrayBuffer buffer, final ParserCursor cursor) { if (buffer == null) { throw new IllegalArgumentException("Char array buffer may not be null"); } if (cursor == null) { throw new IllegalArgumentException("Parser cursor may not be null"); } int pos = cursor.getPos(); int indexTo = cursor.getUpperBound(); while (pos < indexTo) { char ch = buffer.charAt(pos); if (HTTP.isWhitespace(ch)) { pos++; } else { break; } } cursor.updatePos(pos); if (cursor.atEnd()) { return new NameValuePair[] {}; } List params = new ArrayList(); while (!cursor.atEnd()) { NameValuePair param = parseNameValuePair(buffer, cursor); params.add(param); char ch = buffer.charAt(cursor.getPos() - 1); if (ch == ELEM_DELIMITER) { break; } } return (NameValuePair[]) params.toArray(new NameValuePair[params.size()]); } /** * Parses a name-value-pair with the given parser. * * @param value the NVP to parse * @param parser the parser to use, or <code>null</code> for default * * @return the parsed name-value pair */ public final static NameValuePair parseNameValuePair(final String value, HeaderValueParser parser) throws ParseException { if (value == null) { throw new IllegalArgumentException ("Value to parse may not be null"); } if (parser == null) parser = BasicHeaderValueParser.DEFAULT; CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); ParserCursor cursor = new ParserCursor(0, value.length()); return parser.parseNameValuePair(buffer, cursor); } // non-javadoc, see interface HeaderValueParser public NameValuePair parseNameValuePair(final CharArrayBuffer buffer, final ParserCursor cursor) { return parseNameValuePair(buffer, cursor, ALL_DELIMITERS); } private static boolean isOneOf(final char ch, final char[] chs) { if (chs != null) { for (int i = 0; i < chs.length; i++) { if (ch == chs[i]) { return true; } } } return false; } public NameValuePair parseNameValuePair(final CharArrayBuffer buffer, final ParserCursor cursor, final char[] delimiters) { if (buffer == null) { throw new IllegalArgumentException("Char array buffer may not be null"); } if (cursor == null) { throw new IllegalArgumentException("Parser cursor may not be null"); } boolean terminated = false; int pos = cursor.getPos(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); // Find name String name = null; while (pos < indexTo) { char ch = buffer.charAt(pos); if (ch == '=') { break; } if (isOneOf(ch, delimiters)) { terminated = true; break; } pos++; } if (pos == indexTo) { terminated = true; name = buffer.substringTrimmed(indexFrom, indexTo); } else { name = buffer.substringTrimmed(indexFrom, pos); pos++; } if (terminated) { cursor.updatePos(pos); return createNameValuePair(name, null); } // Find value String value = null; int i1 = pos; boolean qouted = false; boolean escaped = false; while (pos < indexTo) { char ch = buffer.charAt(pos); if (ch == '"' && !escaped) { qouted = !qouted; } if (!qouted && !escaped && isOneOf(ch, delimiters)) { terminated = true; break; } if (escaped) { escaped = false; } else { escaped = qouted && ch == '\\'; } pos++; } int i2 = pos; // Trim leading white spaces while (i1 < i2 && (HTTP.isWhitespace(buffer.charAt(i1)))) { i1++; } // Trim trailing white spaces while ((i2 > i1) && (HTTP.isWhitespace(buffer.charAt(i2 - 1)))) { i2--; } // Strip away quotes if necessary if (((i2 - i1) >= 2) && (buffer.charAt(i1) == '"') && (buffer.charAt(i2 - 1) == '"')) { i1++; i2--; } value = buffer.substring(i1, i2); if (terminated) { pos++; } cursor.updatePos(pos); return createNameValuePair(name, value); } /** * Creates a name-value pair. * Called from {@link #parseNameValuePair}. * * @param name the name * @param value the value, or <code>null</code> * * @return a name-value pair representing the arguments */ protected NameValuePair createNameValuePair(final String name, final String value) { return new BasicNameValuePair(name, value); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicHeaderValueParser.java
Java
gpl3
13,164
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import java.util.NoSuchElementException; import org.apache.ogt.http.HeaderIterator; import org.apache.ogt.http.ParseException; import org.apache.ogt.http.TokenIterator; /** * Basic implementation of a {@link TokenIterator}. * This implementation parses <tt>#token<tt> sequences as * defined by RFC 2616, section 2. * It extends that definition somewhat beyond US-ASCII. * * @since 4.0 */ public class BasicTokenIterator implements TokenIterator { /** The HTTP separator characters. Defined in RFC 2616, section 2.2. */ // the order of the characters here is adjusted to put the // most likely candidates at the beginning of the collection public final static String HTTP_SEPARATORS = " ,;=()<>@:\\\"/[]?{}\t"; /** The iterator from which to obtain the next header. */ protected final HeaderIterator headerIt; /** * The value of the current header. * This is the header value that includes {@link #currentToken}. * Undefined if the iteration is over. */ protected String currentHeader; /** * The token to be returned by the next call to {@link #currentToken}. * <code>null</code> if the iteration is over. */ protected String currentToken; /** * The position after {@link #currentToken} in {@link #currentHeader}. * Undefined if the iteration is over. */ protected int searchPos; /** * Creates a new instance of {@link BasicTokenIterator}. * * @param headerIterator the iterator for the headers to tokenize */ public BasicTokenIterator(final HeaderIterator headerIterator) { if (headerIterator == null) { throw new IllegalArgumentException ("Header iterator must not be null."); } this.headerIt = headerIterator; this.searchPos = findNext(-1); } // non-javadoc, see interface TokenIterator public boolean hasNext() { return (this.currentToken != null); } /** * Obtains the next token from this iteration. * * @return the next token in this iteration * * @throws NoSuchElementException if the iteration is already over * @throws ParseException if an invalid header value is encountered */ public String nextToken() throws NoSuchElementException, ParseException { if (this.currentToken == null) { throw new NoSuchElementException("Iteration already finished."); } final String result = this.currentToken; // updates currentToken, may trigger ParseException: this.searchPos = findNext(this.searchPos); return result; } /** * Returns the next token. * Same as {@link #nextToken}, but with generic return type. * * @return the next token in this iteration * * @throws NoSuchElementException if there are no more tokens * @throws ParseException if an invalid header value is encountered */ public final Object next() throws NoSuchElementException, ParseException { return nextToken(); } /** * Removing tokens is not supported. * * @throws UnsupportedOperationException always */ public final void remove() throws UnsupportedOperationException { throw new UnsupportedOperationException ("Removing tokens is not supported."); } /** * Determines the next token. * If found, the token is stored in {@link #currentToken}. * The return value indicates the position after the token * in {@link #currentHeader}. If necessary, the next header * will be obtained from {@link #headerIt}. * If not found, {@link #currentToken} is set to <code>null</code>. * * @param from the position in the current header at which to * start the search, -1 to search in the first header * * @return the position after the found token in the current header, or * negative if there was no next token * * @throws ParseException if an invalid header value is encountered */ protected int findNext(int from) throws ParseException { if (from < 0) { // called from the constructor, initialize the first header if (!this.headerIt.hasNext()) { return -1; } this.currentHeader = this.headerIt.nextHeader().getValue(); from = 0; } else { // called after a token, make sure there is a separator from = findTokenSeparator(from); } int start = findTokenStart(from); if (start < 0) { this.currentToken = null; return -1; // nothing found } int end = findTokenEnd(start); this.currentToken = createToken(this.currentHeader, start, end); return end; } /** * Creates a new token to be returned. * Called from {@link #findNext findNext} after the token is identified. * The default implementation simply calls * {@link java.lang.String#substring String.substring}. * <br/> * If header values are significantly longer than tokens, and some * tokens are permanently referenced by the application, there can * be problems with garbage collection. A substring will hold a * reference to the full characters of the original string and * therefore occupies more memory than might be expected. * To avoid this, override this method and create a new string * instead of a substring. * * @param value the full header value from which to create a token * @param start the index of the first token character * @param end the index after the last token character * * @return a string representing the token identified by the arguments */ protected String createToken(String value, int start, int end) { return value.substring(start, end); } /** * Determines the starting position of the next token. * This method will iterate over headers if necessary. * * @param from the position in the current header at which to * start the search * * @return the position of the token start in the current header, * negative if no token start could be found */ protected int findTokenStart(int from) { if (from < 0) { throw new IllegalArgumentException ("Search position must not be negative: " + from); } boolean found = false; while (!found && (this.currentHeader != null)) { final int to = this.currentHeader.length(); while (!found && (from < to)) { final char ch = this.currentHeader.charAt(from); if (isTokenSeparator(ch) || isWhitespace(ch)) { // whitspace and token separators are skipped from++; } else if (isTokenChar(this.currentHeader.charAt(from))) { // found the start of a token found = true; } else { throw new ParseException ("Invalid character before token (pos " + from + "): " + this.currentHeader); } } if (!found) { if (this.headerIt.hasNext()) { this.currentHeader = this.headerIt.nextHeader().getValue(); from = 0; } else { this.currentHeader = null; } } } // while headers return found ? from : -1; } /** * Determines the position of the next token separator. * Because of multi-header joining rules, the end of a * header value is a token separator. This method does * therefore not need to iterate over headers. * * @param from the position in the current header at which to * start the search * * @return the position of a token separator in the current header, * or at the end * * @throws ParseException * if a new token is found before a token separator. * RFC 2616, section 2.1 explicitly requires a comma between * tokens for <tt>#</tt>. */ protected int findTokenSeparator(int from) { if (from < 0) { throw new IllegalArgumentException ("Search position must not be negative: " + from); } boolean found = false; final int to = this.currentHeader.length(); while (!found && (from < to)) { final char ch = this.currentHeader.charAt(from); if (isTokenSeparator(ch)) { found = true; } else if (isWhitespace(ch)) { from++; } else if (isTokenChar(ch)) { throw new ParseException ("Tokens without separator (pos " + from + "): " + this.currentHeader); } else { throw new ParseException ("Invalid character after token (pos " + from + "): " + this.currentHeader); } } return from; } /** * Determines the ending position of the current token. * This method will not leave the current header value, * since the end of the header value is a token boundary. * * @param from the position of the first character of the token * * @return the position after the last character of the token. * The behavior is undefined if <code>from</code> does not * point to a token character in the current header value. */ protected int findTokenEnd(int from) { if (from < 0) { throw new IllegalArgumentException ("Token start position must not be negative: " + from); } final int to = this.currentHeader.length(); int end = from+1; while ((end < to) && isTokenChar(this.currentHeader.charAt(end))) { end++; } return end; } /** * Checks whether a character is a token separator. * RFC 2616, section 2.1 defines comma as the separator for * <tt>#token</tt> sequences. The end of a header value will * also separate tokens, but that is not a character check. * * @param ch the character to check * * @return <code>true</code> if the character is a token separator, * <code>false</code> otherwise */ protected boolean isTokenSeparator(char ch) { return (ch == ','); } /** * Checks whether a character is a whitespace character. * RFC 2616, section 2.2 defines space and horizontal tab as whitespace. * The optional preceeding line break is irrelevant, since header * continuation is handled transparently when parsing messages. * * @param ch the character to check * * @return <code>true</code> if the character is whitespace, * <code>false</code> otherwise */ protected boolean isWhitespace(char ch) { // we do not use Character.isWhitspace(ch) here, since that allows // many control characters which are not whitespace as per RFC 2616 return ((ch == '\t') || Character.isSpaceChar(ch)); } /** * Checks whether a character is a valid token character. * Whitespace, control characters, and HTTP separators are not * valid token characters. The HTTP specification (RFC 2616, section 2.2) * defines tokens only for the US-ASCII character set, this * method extends the definition to other character sets. * * @param ch the character to check * * @return <code>true</code> if the character is a valid token start, * <code>false</code> otherwise */ protected boolean isTokenChar(char ch) { // common sense extension of ALPHA + DIGIT if (Character.isLetterOrDigit(ch)) return true; // common sense extension of CTL if (Character.isISOControl(ch)) return false; // no common sense extension for this if (isHttpSeparator(ch)) return false; // RFC 2616, section 2.2 defines a token character as // "any CHAR except CTLs or separators". The controls // and separators are included in the checks above. // This will yield unexpected results for Unicode format characters. // If that is a problem, overwrite isHttpSeparator(char) to filter // out the false positives. return true; } /** * Checks whether a character is an HTTP separator. * The implementation in this class checks only for the HTTP separators * defined in RFC 2616, section 2.2. If you need to detect other * separators beyond the US-ASCII character set, override this method. * * @param ch the character to check * * @return <code>true</code> if the character is an HTTP separator */ protected boolean isHttpSeparator(char ch) { return (HTTP_SEPARATORS.indexOf(ch) >= 0); } } // class BasicTokenIterator
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicTokenIterator.java
Java
gpl3
14,680
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import org.apache.ogt.http.HeaderElement; import org.apache.ogt.http.NameValuePair; import org.apache.ogt.http.util.CharArrayBuffer; /** * Basic implementation for formatting header value elements. * Instances of this class are stateless and thread-safe. * Derived classes are expected to maintain these properties. * * @since 4.0 */ public class BasicHeaderValueFormatter implements HeaderValueFormatter { /** * A default instance of this class, for use as default or fallback. * Note that {@link BasicHeaderValueFormatter} is not a singleton, there * can be many instances of the class itself and of derived classes. * The instance here provides non-customized, default behavior. */ public final static BasicHeaderValueFormatter DEFAULT = new BasicHeaderValueFormatter(); /** * Special characters that can be used as separators in HTTP parameters. * These special characters MUST be in a quoted string to be used within * a parameter value . */ public final static String SEPARATORS = " ;,:@()<>\\\"/[]?={}\t"; /** * Unsafe special characters that must be escaped using the backslash * character */ public final static String UNSAFE_CHARS = "\"\\"; // public default constructor /** * Formats an array of header elements. * * @param elems the header elements to format * @param quote <code>true</code> to always format with quoted values, * <code>false</code> to use quotes only when necessary * @param formatter the formatter to use, or <code>null</code> * for the {@link #DEFAULT default} * * @return the formatted header elements */ public final static String formatElements(final HeaderElement[] elems, final boolean quote, HeaderValueFormatter formatter) { if (formatter == null) formatter = BasicHeaderValueFormatter.DEFAULT; return formatter.formatElements(null, elems, quote).toString(); } // non-javadoc, see interface HeaderValueFormatter public CharArrayBuffer formatElements(CharArrayBuffer buffer, final HeaderElement[] elems, final boolean quote) { if (elems == null) { throw new IllegalArgumentException ("Header element array must not be null."); } int len = estimateElementsLen(elems); if (buffer == null) { buffer = new CharArrayBuffer(len); } else { buffer.ensureCapacity(len); } for (int i=0; i<elems.length; i++) { if (i > 0) { buffer.append(", "); } formatHeaderElement(buffer, elems[i], quote); } return buffer; } /** * Estimates the length of formatted header elements. * * @param elems the header elements to format, or <code>null</code> * * @return a length estimate, in number of characters */ protected int estimateElementsLen(final HeaderElement[] elems) { if ((elems == null) || (elems.length < 1)) return 0; int result = (elems.length-1) * 2; // elements separated by ", " for (int i=0; i<elems.length; i++) { result += estimateHeaderElementLen(elems[i]); } return result; } /** * Formats a header element. * * @param elem the header element to format * @param quote <code>true</code> to always format with quoted values, * <code>false</code> to use quotes only when necessary * @param formatter the formatter to use, or <code>null</code> * for the {@link #DEFAULT default} * * @return the formatted header element */ public final static String formatHeaderElement(final HeaderElement elem, boolean quote, HeaderValueFormatter formatter) { if (formatter == null) formatter = BasicHeaderValueFormatter.DEFAULT; return formatter.formatHeaderElement(null, elem, quote).toString(); } // non-javadoc, see interface HeaderValueFormatter public CharArrayBuffer formatHeaderElement(CharArrayBuffer buffer, final HeaderElement elem, final boolean quote) { if (elem == null) { throw new IllegalArgumentException ("Header element must not be null."); } int len = estimateHeaderElementLen(elem); if (buffer == null) { buffer = new CharArrayBuffer(len); } else { buffer.ensureCapacity(len); } buffer.append(elem.getName()); final String value = elem.getValue(); if (value != null) { buffer.append('='); doFormatValue(buffer, value, quote); } final int parcnt = elem.getParameterCount(); if (parcnt > 0) { for (int i=0; i<parcnt; i++) { buffer.append("; "); formatNameValuePair(buffer, elem.getParameter(i), quote); } } return buffer; } /** * Estimates the length of a formatted header element. * * @param elem the header element to format, or <code>null</code> * * @return a length estimate, in number of characters */ protected int estimateHeaderElementLen(final HeaderElement elem) { if (elem == null) return 0; int result = elem.getName().length(); // name final String value = elem.getValue(); if (value != null) { // assume quotes, but no escaped characters result += 3 + value.length(); // ="value" } final int parcnt = elem.getParameterCount(); if (parcnt > 0) { for (int i=0; i<parcnt; i++) { result += 2 + // ; <param> estimateNameValuePairLen(elem.getParameter(i)); } } return result; } /** * Formats a set of parameters. * * @param nvps the parameters to format * @param quote <code>true</code> to always format with quoted values, * <code>false</code> to use quotes only when necessary * @param formatter the formatter to use, or <code>null</code> * for the {@link #DEFAULT default} * * @return the formatted parameters */ public final static String formatParameters(final NameValuePair[] nvps, final boolean quote, HeaderValueFormatter formatter) { if (formatter == null) formatter = BasicHeaderValueFormatter.DEFAULT; return formatter.formatParameters(null, nvps, quote).toString(); } // non-javadoc, see interface HeaderValueFormatter public CharArrayBuffer formatParameters(CharArrayBuffer buffer, NameValuePair[] nvps, boolean quote) { if (nvps == null) { throw new IllegalArgumentException ("Parameters must not be null."); } int len = estimateParametersLen(nvps); if (buffer == null) { buffer = new CharArrayBuffer(len); } else { buffer.ensureCapacity(len); } for (int i = 0; i < nvps.length; i++) { if (i > 0) { buffer.append("; "); } formatNameValuePair(buffer, nvps[i], quote); } return buffer; } /** * Estimates the length of formatted parameters. * * @param nvps the parameters to format, or <code>null</code> * * @return a length estimate, in number of characters */ protected int estimateParametersLen(final NameValuePair[] nvps) { if ((nvps == null) || (nvps.length < 1)) return 0; int result = (nvps.length-1) * 2; // "; " between the parameters for (int i=0; i<nvps.length; i++) { result += estimateNameValuePairLen(nvps[i]); } return result; } /** * Formats a name-value pair. * * @param nvp the name-value pair to format * @param quote <code>true</code> to always format with a quoted value, * <code>false</code> to use quotes only when necessary * @param formatter the formatter to use, or <code>null</code> * for the {@link #DEFAULT default} * * @return the formatted name-value pair */ public final static String formatNameValuePair(final NameValuePair nvp, final boolean quote, HeaderValueFormatter formatter) { if (formatter == null) formatter = BasicHeaderValueFormatter.DEFAULT; return formatter.formatNameValuePair(null, nvp, quote).toString(); } // non-javadoc, see interface HeaderValueFormatter public CharArrayBuffer formatNameValuePair(CharArrayBuffer buffer, final NameValuePair nvp, final boolean quote) { if (nvp == null) { throw new IllegalArgumentException ("NameValuePair must not be null."); } int len = estimateNameValuePairLen(nvp); if (buffer == null) { buffer = new CharArrayBuffer(len); } else { buffer.ensureCapacity(len); } buffer.append(nvp.getName()); final String value = nvp.getValue(); if (value != null) { buffer.append('='); doFormatValue(buffer, value, quote); } return buffer; } /** * Estimates the length of a formatted name-value pair. * * @param nvp the name-value pair to format, or <code>null</code> * * @return a length estimate, in number of characters */ protected int estimateNameValuePairLen(final NameValuePair nvp) { if (nvp == null) return 0; int result = nvp.getName().length(); // name final String value = nvp.getValue(); if (value != null) { // assume quotes, but no escaped characters result += 3 + value.length(); // ="value" } return result; } /** * Actually formats the value of a name-value pair. * This does not include a leading = character. * Called from {@link #formatNameValuePair formatNameValuePair}. * * @param buffer the buffer to append to, never <code>null</code> * @param value the value to append, never <code>null</code> * @param quote <code>true</code> to always format with quotes, * <code>false</code> to use quotes only when necessary */ protected void doFormatValue(final CharArrayBuffer buffer, final String value, boolean quote) { if (!quote) { for (int i = 0; (i < value.length()) && !quote; i++) { quote = isSeparator(value.charAt(i)); } } if (quote) { buffer.append('"'); } for (int i = 0; i < value.length(); i++) { char ch = value.charAt(i); if (isUnsafe(ch)) { buffer.append('\\'); } buffer.append(ch); } if (quote) { buffer.append('"'); } } /** * Checks whether a character is a {@link #SEPARATORS separator}. * * @param ch the character to check * * @return <code>true</code> if the character is a separator, * <code>false</code> otherwise */ protected boolean isSeparator(char ch) { return SEPARATORS.indexOf(ch) >= 0; } /** * Checks whether a character is {@link #UNSAFE_CHARS unsafe}. * * @param ch the character to check * * @return <code>true</code> if the character is unsafe, * <code>false</code> otherwise */ protected boolean isUnsafe(char ch) { return UNSAFE_CHARS.indexOf(ch) >= 0; } } // class BasicHeaderValueFormatter
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicHeaderValueFormatter.java
Java
gpl3
14,004
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import java.io.Serializable; import org.apache.ogt.http.FormattedHeader; import org.apache.ogt.http.HeaderElement; import org.apache.ogt.http.ParseException; import org.apache.ogt.http.util.CharArrayBuffer; /** * This class represents a raw HTTP header whose content is parsed 'on demand' * only when the header value needs to be consumed. * * @since 4.0 */ public class BufferedHeader implements FormattedHeader, Cloneable, Serializable { private static final long serialVersionUID = -2768352615787625448L; /** * Header name. */ private final String name; /** * The buffer containing the entire header line. */ private final CharArrayBuffer buffer; /** * The beginning of the header value in the buffer */ private final int valuePos; /** * Creates a new header from a buffer. * The name of the header will be parsed immediately, * the value only if it is accessed. * * @param buffer the buffer containing the header to represent * * @throws ParseException in case of a parse error */ public BufferedHeader(final CharArrayBuffer buffer) throws ParseException { super(); if (buffer == null) { throw new IllegalArgumentException ("Char array buffer may not be null"); } int colon = buffer.indexOf(':'); if (colon == -1) { throw new ParseException ("Invalid header: " + buffer.toString()); } String s = buffer.substringTrimmed(0, colon); if (s.length() == 0) { throw new ParseException ("Invalid header: " + buffer.toString()); } this.buffer = buffer; this.name = s; this.valuePos = colon + 1; } public String getName() { return this.name; } public String getValue() { return this.buffer.substringTrimmed(this.valuePos, this.buffer.length()); } public HeaderElement[] getElements() throws ParseException { ParserCursor cursor = new ParserCursor(0, this.buffer.length()); cursor.updatePos(this.valuePos); return BasicHeaderValueParser.DEFAULT .parseElements(this.buffer, cursor); } public int getValuePos() { return this.valuePos; } public CharArrayBuffer getBuffer() { return this.buffer; } public String toString() { return this.buffer.toString(); } public Object clone() throws CloneNotSupportedException { // buffer is considered immutable // no need to make a copy of it return super.clone(); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BufferedHeader.java
Java
gpl3
3,903
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import org.apache.ogt.http.util.CharArrayBuffer; /** * This class represents a context of a parsing operation: * <ul> * <li>the current position the parsing operation is expected to start at</li> * <li>the bounds limiting the scope of the parsing operation</li> * </ul> * * @since 4.0 */ public class ParserCursor { private final int lowerBound; private final int upperBound; private int pos; public ParserCursor(int lowerBound, int upperBound) { super(); if (lowerBound < 0) { throw new IndexOutOfBoundsException("Lower bound cannot be negative"); } if (lowerBound > upperBound) { throw new IndexOutOfBoundsException("Lower bound cannot be greater then upper bound"); } this.lowerBound = lowerBound; this.upperBound = upperBound; this.pos = lowerBound; } public int getLowerBound() { return this.lowerBound; } public int getUpperBound() { return this.upperBound; } public int getPos() { return this.pos; } public void updatePos(int pos) { if (pos < this.lowerBound) { throw new IndexOutOfBoundsException("pos: "+pos+" < lowerBound: "+this.lowerBound); } if (pos > this.upperBound) { throw new IndexOutOfBoundsException("pos: "+pos+" > upperBound: "+this.upperBound); } this.pos = pos; } public boolean atEnd() { return this.pos >= this.upperBound; } public String toString() { CharArrayBuffer buffer = new CharArrayBuffer(16); buffer.append('['); buffer.append(Integer.toString(this.lowerBound)); buffer.append('>'); buffer.append(Integer.toString(this.pos)); buffer.append('>'); buffer.append(Integer.toString(this.upperBound)); buffer.append(']'); return buffer.toString(); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/ParserCursor.java
Java
gpl3
3,148
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import java.io.Serializable; import org.apache.ogt.http.ProtocolVersion; import org.apache.ogt.http.StatusLine; /** * Basic implementation of {@link StatusLine} * * @version $Id: BasicStatusLine.java 986952 2010-08-18 21:24:55Z olegk $ * * @since 4.0 */ public class BasicStatusLine implements StatusLine, Cloneable, Serializable { private static final long serialVersionUID = -2443303766890459269L; // ----------------------------------------------------- Instance Variables /** The protocol version. */ private final ProtocolVersion protoVersion; /** The status code. */ private final int statusCode; /** The reason phrase. */ private final String reasonPhrase; // ----------------------------------------------------------- Constructors /** * Creates a new status line with the given version, status, and reason. * * @param version the protocol version of the response * @param statusCode the status code of the response * @param reasonPhrase the reason phrase to the status code, or * <code>null</code> */ public BasicStatusLine(final ProtocolVersion version, int statusCode, final String reasonPhrase) { super(); if (version == null) { throw new IllegalArgumentException ("Protocol version may not be null."); } if (statusCode < 0) { throw new IllegalArgumentException ("Status code may not be negative."); } this.protoVersion = version; this.statusCode = statusCode; this.reasonPhrase = reasonPhrase; } // --------------------------------------------------------- Public Methods public int getStatusCode() { return this.statusCode; } public ProtocolVersion getProtocolVersion() { return this.protoVersion; } public String getReasonPhrase() { return this.reasonPhrase; } public String toString() { // no need for non-default formatting in toString() return BasicLineFormatter.DEFAULT .formatStatusLine(null, this).toString(); } public Object clone() throws CloneNotSupportedException { return super.clone(); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicStatusLine.java
Java
gpl3
3,544
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import org.apache.ogt.http.Header; import org.apache.ogt.http.HttpVersion; import org.apache.ogt.http.ParseException; import org.apache.ogt.http.ProtocolVersion; import org.apache.ogt.http.RequestLine; import org.apache.ogt.http.StatusLine; import org.apache.ogt.http.protocol.HTTP; import org.apache.ogt.http.util.CharArrayBuffer; /** * Basic parser for lines in the head section of an HTTP message. * There are individual methods for parsing a request line, a * status line, or a header line. * The lines to parse are passed in memory, the parser does not depend * on any specific IO mechanism. * Instances of this class are stateless and thread-safe. * Derived classes MUST maintain these properties. * * <p> * Note: This class was created by refactoring parsing code located in * various other classes. The author tags from those other classes have * been replicated here, although the association with the parsing code * taken from there has not been traced. * </p> * * @since 4.0 */ public class BasicLineParser implements LineParser { /** * A default instance of this class, for use as default or fallback. * Note that {@link BasicLineParser} is not a singleton, there can * be many instances of the class itself and of derived classes. * The instance here provides non-customized, default behavior. */ public final static BasicLineParser DEFAULT = new BasicLineParser(); /** * A version of the protocol to parse. * The version is typically not relevant, but the protocol name. */ protected final ProtocolVersion protocol; /** * Creates a new line parser for the given HTTP-like protocol. * * @param proto a version of the protocol to parse, or * <code>null</code> for HTTP. The actual version * is not relevant, only the protocol name. */ public BasicLineParser(ProtocolVersion proto) { if (proto == null) { proto = HttpVersion.HTTP_1_1; } this.protocol = proto; } /** * Creates a new line parser for HTTP. */ public BasicLineParser() { this(null); } public final static ProtocolVersion parseProtocolVersion(String value, LineParser parser) throws ParseException { if (value == null) { throw new IllegalArgumentException ("Value to parse may not be null."); } if (parser == null) parser = BasicLineParser.DEFAULT; CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); ParserCursor cursor = new ParserCursor(0, value.length()); return parser.parseProtocolVersion(buffer, cursor); } // non-javadoc, see interface LineParser public ProtocolVersion parseProtocolVersion(final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException { if (buffer == null) { throw new IllegalArgumentException("Char array buffer may not be null"); } if (cursor == null) { throw new IllegalArgumentException("Parser cursor may not be null"); } final String protoname = this.protocol.getProtocol(); final int protolength = protoname.length(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); skipWhitespace(buffer, cursor); int i = cursor.getPos(); // long enough for "HTTP/1.1"? if (i + protolength + 4 > indexTo) { throw new ParseException ("Not a valid protocol version: " + buffer.substring(indexFrom, indexTo)); } // check the protocol name and slash boolean ok = true; for (int j=0; ok && (j<protolength); j++) { ok = (buffer.charAt(i+j) == protoname.charAt(j)); } if (ok) { ok = (buffer.charAt(i+protolength) == '/'); } if (!ok) { throw new ParseException ("Not a valid protocol version: " + buffer.substring(indexFrom, indexTo)); } i += protolength+1; int period = buffer.indexOf('.', i, indexTo); if (period == -1) { throw new ParseException ("Invalid protocol version number: " + buffer.substring(indexFrom, indexTo)); } int major; try { major = Integer.parseInt(buffer.substringTrimmed(i, period)); } catch (NumberFormatException e) { throw new ParseException ("Invalid protocol major version number: " + buffer.substring(indexFrom, indexTo)); } i = period + 1; int blank = buffer.indexOf(' ', i, indexTo); if (blank == -1) { blank = indexTo; } int minor; try { minor = Integer.parseInt(buffer.substringTrimmed(i, blank)); } catch (NumberFormatException e) { throw new ParseException( "Invalid protocol minor version number: " + buffer.substring(indexFrom, indexTo)); } cursor.updatePos(blank); return createProtocolVersion(major, minor); } // parseProtocolVersion /** * Creates a protocol version. * Called from {@link #parseProtocolVersion}. * * @param major the major version number, for example 1 in HTTP/1.0 * @param minor the minor version number, for example 0 in HTTP/1.0 * * @return the protocol version */ protected ProtocolVersion createProtocolVersion(int major, int minor) { return protocol.forVersion(major, minor); } // non-javadoc, see interface LineParser public boolean hasProtocolVersion(final CharArrayBuffer buffer, final ParserCursor cursor) { if (buffer == null) { throw new IllegalArgumentException("Char array buffer may not be null"); } if (cursor == null) { throw new IllegalArgumentException("Parser cursor may not be null"); } int index = cursor.getPos(); final String protoname = this.protocol.getProtocol(); final int protolength = protoname.length(); if (buffer.length() < protolength+4) return false; // not long enough for "HTTP/1.1" if (index < 0) { // end of line, no tolerance for trailing whitespace // this works only for single-digit major and minor version index = buffer.length() -4 -protolength; } else if (index == 0) { // beginning of line, tolerate leading whitespace while ((index < buffer.length()) && HTTP.isWhitespace(buffer.charAt(index))) { index++; } } // else within line, don't tolerate whitespace if (index + protolength + 4 > buffer.length()) return false; // just check protocol name and slash, no need to analyse the version boolean ok = true; for (int j=0; ok && (j<protolength); j++) { ok = (buffer.charAt(index+j) == protoname.charAt(j)); } if (ok) { ok = (buffer.charAt(index+protolength) == '/'); } return ok; } public final static RequestLine parseRequestLine(final String value, LineParser parser) throws ParseException { if (value == null) { throw new IllegalArgumentException ("Value to parse may not be null."); } if (parser == null) parser = BasicLineParser.DEFAULT; CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); ParserCursor cursor = new ParserCursor(0, value.length()); return parser.parseRequestLine(buffer, cursor); } /** * Parses a request line. * * @param buffer a buffer holding the line to parse * * @return the parsed request line * * @throws ParseException in case of a parse error */ public RequestLine parseRequestLine(final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException { if (buffer == null) { throw new IllegalArgumentException("Char array buffer may not be null"); } if (cursor == null) { throw new IllegalArgumentException("Parser cursor may not be null"); } int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); try { skipWhitespace(buffer, cursor); int i = cursor.getPos(); int blank = buffer.indexOf(' ', i, indexTo); if (blank < 0) { throw new ParseException("Invalid request line: " + buffer.substring(indexFrom, indexTo)); } String method = buffer.substringTrimmed(i, blank); cursor.updatePos(blank); skipWhitespace(buffer, cursor); i = cursor.getPos(); blank = buffer.indexOf(' ', i, indexTo); if (blank < 0) { throw new ParseException("Invalid request line: " + buffer.substring(indexFrom, indexTo)); } String uri = buffer.substringTrimmed(i, blank); cursor.updatePos(blank); ProtocolVersion ver = parseProtocolVersion(buffer, cursor); skipWhitespace(buffer, cursor); if (!cursor.atEnd()) { throw new ParseException("Invalid request line: " + buffer.substring(indexFrom, indexTo)); } return createRequestLine(method, uri, ver); } catch (IndexOutOfBoundsException e) { throw new ParseException("Invalid request line: " + buffer.substring(indexFrom, indexTo)); } } // parseRequestLine /** * Instantiates a new request line. * Called from {@link #parseRequestLine}. * * @param method the request method * @param uri the requested URI * @param ver the protocol version * * @return a new status line with the given data */ protected RequestLine createRequestLine(final String method, final String uri, final ProtocolVersion ver) { return new BasicRequestLine(method, uri, ver); } public final static StatusLine parseStatusLine(final String value, LineParser parser) throws ParseException { if (value == null) { throw new IllegalArgumentException ("Value to parse may not be null."); } if (parser == null) parser = BasicLineParser.DEFAULT; CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); ParserCursor cursor = new ParserCursor(0, value.length()); return parser.parseStatusLine(buffer, cursor); } // non-javadoc, see interface LineParser public StatusLine parseStatusLine(final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException { if (buffer == null) { throw new IllegalArgumentException("Char array buffer may not be null"); } if (cursor == null) { throw new IllegalArgumentException("Parser cursor may not be null"); } int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); try { // handle the HTTP-Version ProtocolVersion ver = parseProtocolVersion(buffer, cursor); // handle the Status-Code skipWhitespace(buffer, cursor); int i = cursor.getPos(); int blank = buffer.indexOf(' ', i, indexTo); if (blank < 0) { blank = indexTo; } int statusCode = 0; String s = buffer.substringTrimmed(i, blank); for (int j = 0; j < s.length(); j++) { if (!Character.isDigit(s.charAt(j))) { throw new ParseException( "Status line contains invalid status code: " + buffer.substring(indexFrom, indexTo)); } } try { statusCode = Integer.parseInt(s); } catch (NumberFormatException e) { throw new ParseException( "Status line contains invalid status code: " + buffer.substring(indexFrom, indexTo)); } //handle the Reason-Phrase i = blank; String reasonPhrase = null; if (i < indexTo) { reasonPhrase = buffer.substringTrimmed(i, indexTo); } else { reasonPhrase = ""; } return createStatusLine(ver, statusCode, reasonPhrase); } catch (IndexOutOfBoundsException e) { throw new ParseException("Invalid status line: " + buffer.substring(indexFrom, indexTo)); } } // parseStatusLine /** * Instantiates a new status line. * Called from {@link #parseStatusLine}. * * @param ver the protocol version * @param status the status code * @param reason the reason phrase * * @return a new status line with the given data */ protected StatusLine createStatusLine(final ProtocolVersion ver, final int status, final String reason) { return new BasicStatusLine(ver, status, reason); } public final static Header parseHeader(final String value, LineParser parser) throws ParseException { if (value == null) { throw new IllegalArgumentException ("Value to parse may not be null"); } if (parser == null) parser = BasicLineParser.DEFAULT; CharArrayBuffer buffer = new CharArrayBuffer(value.length()); buffer.append(value); return parser.parseHeader(buffer); } // non-javadoc, see interface LineParser public Header parseHeader(CharArrayBuffer buffer) throws ParseException { // the actual parser code is in the constructor of BufferedHeader return new BufferedHeader(buffer); } /** * Helper to skip whitespace. */ protected void skipWhitespace(final CharArrayBuffer buffer, final ParserCursor cursor) { int pos = cursor.getPos(); int indexTo = cursor.getUpperBound(); while ((pos < indexTo) && HTTP.isWhitespace(buffer.charAt(pos))) { pos++; } cursor.updatePos(pos); } } // class BasicLineParser
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicLineParser.java
Java
gpl3
16,615
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import java.util.List; import java.util.NoSuchElementException; import org.apache.ogt.http.Header; import org.apache.ogt.http.HeaderIterator; /** * Implementation of a {@link HeaderIterator} based on a {@link List}. * For use by {@link HeaderGroup}. * * @since 4.0 */ public class BasicListHeaderIterator implements HeaderIterator { /** * A list of headers to iterate over. * Not all elements of this array are necessarily part of the iteration. */ protected final List allHeaders; /** * The position of the next header in {@link #allHeaders allHeaders}. * Negative if the iteration is over. */ protected int currentIndex; /** * The position of the last returned header. * Negative if none has been returned so far. */ protected int lastIndex; /** * The header name to filter by. * <code>null</code> to iterate over all headers in the array. */ protected String headerName; /** * Creates a new header iterator. * * @param headers a list of headers over which to iterate * @param name the name of the headers over which to iterate, or * <code>null</code> for any */ public BasicListHeaderIterator(List headers, String name) { if (headers == null) { throw new IllegalArgumentException ("Header list must not be null."); } this.allHeaders = headers; this.headerName = name; this.currentIndex = findNext(-1); this.lastIndex = -1; } /** * Determines the index of the next header. * * @param from one less than the index to consider first, * -1 to search for the first header * * @return the index of the next header that matches the filter name, * or negative if there are no more headers */ protected int findNext(int from) { if (from < -1) return -1; final int to = this.allHeaders.size()-1; boolean found = false; while (!found && (from < to)) { from++; found = filterHeader(from); } return found ? from : -1; } /** * Checks whether a header is part of the iteration. * * @param index the index of the header to check * * @return <code>true</code> if the header should be part of the * iteration, <code>false</code> to skip */ protected boolean filterHeader(int index) { if (this.headerName == null) return true; // non-header elements, including null, will trigger exceptions final String name = ((Header)this.allHeaders.get(index)).getName(); return this.headerName.equalsIgnoreCase(name); } // non-javadoc, see interface HeaderIterator public boolean hasNext() { return (this.currentIndex >= 0); } /** * Obtains the next header from this iteration. * * @return the next header in this iteration * * @throws NoSuchElementException if there are no more headers */ public Header nextHeader() throws NoSuchElementException { final int current = this.currentIndex; if (current < 0) { throw new NoSuchElementException("Iteration already finished."); } this.lastIndex = current; this.currentIndex = findNext(current); return (Header) this.allHeaders.get(current); } /** * Returns the next header. * Same as {@link #nextHeader nextHeader}, but not type-safe. * * @return the next header in this iteration * * @throws NoSuchElementException if there are no more headers */ public final Object next() throws NoSuchElementException { return nextHeader(); } /** * Removes the header that was returned last. */ public void remove() throws UnsupportedOperationException { if (this.lastIndex < 0) { throw new IllegalStateException("No header to remove."); } this.allHeaders.remove(this.lastIndex); this.lastIndex = -1; this.currentIndex--; // adjust for the removed element } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicListHeaderIterator.java
Java
gpl3
5,515
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import java.util.NoSuchElementException; import org.apache.ogt.http.Header; import org.apache.ogt.http.HeaderIterator; /** * Basic implementation of a {@link HeaderIterator}. * * @since 4.0 */ public class BasicHeaderIterator implements HeaderIterator { /** * An array of headers to iterate over. * Not all elements of this array are necessarily part of the iteration. * This array will never be modified by the iterator. * Derived implementations are expected to adhere to this restriction. */ protected final Header[] allHeaders; /** * The position of the next header in {@link #allHeaders allHeaders}. * Negative if the iteration is over. */ protected int currentIndex; /** * The header name to filter by. * <code>null</code> to iterate over all headers in the array. */ protected String headerName; /** * Creates a new header iterator. * * @param headers an array of headers over which to iterate * @param name the name of the headers over which to iterate, or * <code>null</code> for any */ public BasicHeaderIterator(Header[] headers, String name) { if (headers == null) { throw new IllegalArgumentException ("Header array must not be null."); } this.allHeaders = headers; this.headerName = name; this.currentIndex = findNext(-1); } /** * Determines the index of the next header. * * @param from one less than the index to consider first, * -1 to search for the first header * * @return the index of the next header that matches the filter name, * or negative if there are no more headers */ protected int findNext(int from) { if (from < -1) return -1; final int to = this.allHeaders.length-1; boolean found = false; while (!found && (from < to)) { from++; found = filterHeader(from); } return found ? from : -1; } /** * Checks whether a header is part of the iteration. * * @param index the index of the header to check * * @return <code>true</code> if the header should be part of the * iteration, <code>false</code> to skip */ protected boolean filterHeader(int index) { return (this.headerName == null) || this.headerName.equalsIgnoreCase(this.allHeaders[index].getName()); } // non-javadoc, see interface HeaderIterator public boolean hasNext() { return (this.currentIndex >= 0); } /** * Obtains the next header from this iteration. * * @return the next header in this iteration * * @throws NoSuchElementException if there are no more headers */ public Header nextHeader() throws NoSuchElementException { final int current = this.currentIndex; if (current < 0) { throw new NoSuchElementException("Iteration already finished."); } this.currentIndex = findNext(current); return this.allHeaders[current]; } /** * Returns the next header. * Same as {@link #nextHeader nextHeader}, but not type-safe. * * @return the next header in this iteration * * @throws NoSuchElementException if there are no more headers */ public final Object next() throws NoSuchElementException { return nextHeader(); } /** * Removing headers is not supported. * * @throws UnsupportedOperationException always */ public void remove() throws UnsupportedOperationException { throw new UnsupportedOperationException ("Removing headers is not supported."); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicHeaderIterator.java
Java
gpl3
5,110
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import java.io.Serializable; import org.apache.ogt.http.Header; import org.apache.ogt.http.HeaderElement; import org.apache.ogt.http.ParseException; /** * Basic implementation of {@link Header}. * * @since 4.0 */ public class BasicHeader implements Header, Cloneable, Serializable { private static final long serialVersionUID = -5427236326487562174L; private final String name; private final String value; /** * Constructor with name and value * * @param name the header name * @param value the header value */ public BasicHeader(final String name, final String value) { super(); if (name == null) { throw new IllegalArgumentException("Name may not be null"); } this.name = name; this.value = value; } public String getName() { return this.name; } public String getValue() { return this.value; } public String toString() { // no need for non-default formatting in toString() return BasicLineFormatter.DEFAULT.formatHeader(null, this).toString(); } public HeaderElement[] getElements() throws ParseException { if (this.value != null) { // result intentionally not cached, it's probably not used again return BasicHeaderValueParser.parseElements(this.value, null); } else { return new HeaderElement[] {}; } } public Object clone() throws CloneNotSupportedException { return super.clone(); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicHeader.java
Java
gpl3
2,770
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import java.io.Serializable; import org.apache.ogt.http.NameValuePair; import org.apache.ogt.http.util.CharArrayBuffer; import org.apache.ogt.http.util.LangUtils; /** * Basic implementation of {@link NameValuePair}. * * @since 4.0 */ public class BasicNameValuePair implements NameValuePair, Cloneable, Serializable { private static final long serialVersionUID = -6437800749411518984L; 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; } public String getName() { return this.name; } public String getValue() { return this.value; } public String toString() { // don't call complex default formatting for a simple toString if (this.value == null) { return name; } else { int len = this.name.length() + 1 + this.value.length(); CharArrayBuffer buffer = new CharArrayBuffer(len); buffer.append(this.name); buffer.append("="); buffer.append(this.value); return buffer.toString(); } } public boolean equals(final Object object) { if (this == object) return true; if (object instanceof NameValuePair) { BasicNameValuePair that = (BasicNameValuePair) object; return this.name.equals(that.name) && LangUtils.equals(this.value, that.value); } else { return false; } } public int hashCode() { int hash = LangUtils.HASH_SEED; hash = LangUtils.hashCode(hash, this.name); hash = LangUtils.hashCode(hash, this.value); return hash; } public Object clone() throws CloneNotSupportedException { return super.clone(); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicNameValuePair.java
Java
gpl3
3,382
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import org.apache.ogt.http.HeaderElement; import org.apache.ogt.http.NameValuePair; import org.apache.ogt.http.ParseException; import org.apache.ogt.http.util.CharArrayBuffer; /** * Interface for parsing header values into elements. * Instances of this interface are expected to be stateless and thread-safe. * * @since 4.0 */ public interface HeaderValueParser { /** * Parses a header value into elements. * Parse errors are indicated as <code>RuntimeException</code>. * <p> * Some HTTP headers (such as the set-cookie header) have values that * can be decomposed into multiple elements. In order to be processed * by this parser, such headers must be in the following form: * </p> * <pre> * header = [ element ] *( "," [ element ] ) * element = name [ "=" [ value ] ] *( ";" [ param ] ) * param = name [ "=" [ value ] ] * * name = token * value = ( token | quoted-string ) * * token = 1*&lt;any char except "=", ",", ";", &lt;"&gt; and * white space&gt; * quoted-string = &lt;"&gt; *( text | quoted-char ) &lt;"&gt; * text = any char except &lt;"&gt; * quoted-char = "\" char * </pre> * <p> * Any amount of white space is allowed between any part of the * header, element or param and is ignored. A missing value in any * element or param will be stored as the empty {@link String}; * if the "=" is also missing <var>null</var> will be stored instead. * </p> * * @param buffer buffer holding the header value to parse * @param cursor the parser cursor containing the current position and * the bounds within the buffer for the parsing operation * * @return an array holding all elements of the header value * * @throws ParseException in case of a parse error */ HeaderElement[] parseElements( CharArrayBuffer buffer, ParserCursor cursor) throws ParseException; /** * Parses a single header element. * A header element consist of a semicolon-separate list * of name=value definitions. * * @param buffer buffer holding the element to parse * @param cursor the parser cursor containing the current position and * the bounds within the buffer for the parsing operation * * @return the parsed element * * @throws ParseException in case of a parse error */ HeaderElement parseHeaderElement( CharArrayBuffer buffer, ParserCursor cursor) throws ParseException; /** * Parses a list of name-value pairs. * These lists are used to specify parameters to a header element. * Parse errors are indicated as <code>ParseException</code>. * * @param buffer buffer holding the name-value list to parse * @param cursor the parser cursor containing the current position and * the bounds within the buffer for the parsing operation * * @return an array holding all items of the name-value list * * @throws ParseException in case of a parse error */ NameValuePair[] parseParameters( CharArrayBuffer buffer, ParserCursor cursor) throws ParseException; /** * Parses a name=value specification, where the = and value are optional. * * @param buffer the buffer holding the name-value pair to parse * @param cursor the parser cursor containing the current position and * the bounds within the buffer for the parsing operation * * @return the name-value pair, where the value is <code>null</code> * if no value is specified */ NameValuePair parseNameValuePair( CharArrayBuffer buffer, ParserCursor cursor) throws ParseException; }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/HeaderValueParser.java
Java
gpl3
5,188
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import org.apache.ogt.http.HttpRequest; import org.apache.ogt.http.ProtocolVersion; import org.apache.ogt.http.RequestLine; import org.apache.ogt.http.params.HttpParams; import org.apache.ogt.http.params.HttpProtocolParams; /** * Basic implementation of {@link HttpRequest}. * <p> * The following parameters can be used to customize the behavior of this class: * <ul> * <li>{@link org.apache.ogt.http.params.CoreProtocolPNames#PROTOCOL_VERSION}</li> * </ul> * * @since 4.0 */ public class BasicHttpRequest extends AbstractHttpMessage implements HttpRequest { private final String method; private final String uri; private RequestLine requestline; /** * Creates an instance of this class using the given request method * and URI. The HTTP protocol version will be obtained from the * {@link HttpParams} instance associated with the object. * The initialization will be deferred * until {@link #getRequestLine()} is accessed for the first time. * * @param method request method. * @param uri request URI. */ public BasicHttpRequest(final String method, final String uri) { super(); if (method == null) { throw new IllegalArgumentException("Method name may not be null"); } if (uri == null) { throw new IllegalArgumentException("Request URI may not be null"); } this.method = method; this.uri = uri; this.requestline = null; } /** * Creates an instance of this class using the given request method, URI * and the HTTP protocol version. * * @param method request method. * @param uri request URI. * @param ver HTTP protocol version. */ public BasicHttpRequest(final String method, final String uri, final ProtocolVersion ver) { this(new BasicRequestLine(method, uri, ver)); } /** * Creates an instance of this class using the given request line. * * @param requestline request line. */ public BasicHttpRequest(final RequestLine requestline) { super(); if (requestline == null) { throw new IllegalArgumentException("Request line may not be null"); } this.requestline = requestline; this.method = requestline.getMethod(); this.uri = requestline.getUri(); } /** * Returns the HTTP protocol version to be used for this request. If an * HTTP protocol version was not explicitly set at the construction time, * this method will obtain it from the {@link HttpParams} instance * associated with the object. * * @see #BasicHttpRequest(String, String) */ public ProtocolVersion getProtocolVersion() { return getRequestLine().getProtocolVersion(); } /** * Returns the request line of this request. If an HTTP protocol version * was not explicitly set at the construction time, this method will obtain * it from the {@link HttpParams} instance associated with the object. * * @see #BasicHttpRequest(String, String) */ public RequestLine getRequestLine() { if (this.requestline == null) { ProtocolVersion ver = HttpProtocolParams.getVersion(getParams()); this.requestline = new BasicRequestLine(this.method, this.uri, ver); } return this.requestline; } public String toString() { return this.method + " " + this.uri + " " + this.headergroup; } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicHttpRequest.java
Java
gpl3
4,737
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import org.apache.ogt.http.Header; import org.apache.ogt.http.ParseException; import org.apache.ogt.http.ProtocolVersion; import org.apache.ogt.http.RequestLine; import org.apache.ogt.http.StatusLine; import org.apache.ogt.http.util.CharArrayBuffer; /** * Interface for parsing lines in the HEAD section of an HTTP message. * There are individual methods for parsing a request line, a * status line, or a header line. * The lines to parse are passed in memory, the parser does not depend * on any specific IO mechanism. * Instances of this interface are expected to be stateless and thread-safe. * * @since 4.0 */ public interface LineParser { /** * Parses the textual representation of a protocol version. * This is needed for parsing request lines (last element) * as well as status lines (first element). * * @param buffer a buffer holding the protocol version to parse * @param cursor the parser cursor containing the current position and * the bounds within the buffer for the parsing operation * * @return the parsed protocol version * * @throws ParseException in case of a parse error */ ProtocolVersion parseProtocolVersion( CharArrayBuffer buffer, ParserCursor cursor) throws ParseException; /** * Checks whether there likely is a protocol version in a line. * This method implements a <i>heuristic</i> to check for a * likely protocol version specification. It does <i>not</i> * guarantee that {@link #parseProtocolVersion} would not * detect a parse error. * This can be used to detect garbage lines before a request * or status line. * * @param buffer a buffer holding the line to inspect * @param cursor the cursor at which to check for a protocol version, or * negative for "end of line". Whether the check tolerates * whitespace before or after the protocol version is * implementation dependent. * * @return <code>true</code> if there is a protocol version at the * argument index (possibly ignoring whitespace), * <code>false</code> otherwise */ boolean hasProtocolVersion( CharArrayBuffer buffer, ParserCursor cursor); /** * Parses a request line. * * @param buffer a buffer holding the line to parse * @param cursor the parser cursor containing the current position and * the bounds within the buffer for the parsing operation * * @return the parsed request line * * @throws ParseException in case of a parse error */ RequestLine parseRequestLine( CharArrayBuffer buffer, ParserCursor cursor) throws ParseException; /** * Parses a status line. * * @param buffer a buffer holding the line to parse * @param cursor the parser cursor containing the current position and * the bounds within the buffer for the parsing operation * * @return the parsed status line * * @throws ParseException in case of a parse error */ StatusLine parseStatusLine( CharArrayBuffer buffer, ParserCursor cursor) throws ParseException; /** * Creates a header from a line. * The full header line is expected here. Header continuation lines * must be joined by the caller before invoking this method. * * @param buffer a buffer holding the full header line. * This buffer MUST NOT be re-used afterwards, since * the returned object may reference the contents later. * * @return the header in the argument buffer. * The returned object MAY be a wrapper for the argument buffer. * The argument buffer MUST NOT be re-used or changed afterwards. * * @throws ParseException in case of a parse error */ Header parseHeader(CharArrayBuffer buffer) throws ParseException; }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/LineParser.java
Java
gpl3
5,391
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import java.io.Serializable; import org.apache.ogt.http.ProtocolVersion; import org.apache.ogt.http.RequestLine; /** * Basic implementation of {@link RequestLine}. * * @since 4.0 */ public class BasicRequestLine implements RequestLine, Cloneable, Serializable { private static final long serialVersionUID = 2810581718468737193L; private final ProtocolVersion protoversion; private final String method; private final String uri; public BasicRequestLine(final String method, final String uri, final ProtocolVersion version) { super(); if (method == null) { throw new IllegalArgumentException ("Method must not be null."); } if (uri == null) { throw new IllegalArgumentException ("URI must not be null."); } if (version == null) { throw new IllegalArgumentException ("Protocol version must not be null."); } this.method = method; this.uri = uri; this.protoversion = version; } public String getMethod() { return this.method; } public ProtocolVersion getProtocolVersion() { return this.protoversion; } public String getUri() { return this.uri; } public String toString() { // no need for non-default formatting in toString() return BasicLineFormatter.DEFAULT .formatRequestLine(null, this).toString(); } public Object clone() throws CloneNotSupportedException { return super.clone(); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/BasicRequestLine.java
Java
gpl3
2,866
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import org.apache.ogt.http.Header; import org.apache.ogt.http.ProtocolVersion; import org.apache.ogt.http.RequestLine; import org.apache.ogt.http.StatusLine; import org.apache.ogt.http.util.CharArrayBuffer; /** * Interface for formatting elements of the HEAD section of an HTTP message. * This is the complement to {@link LineParser}. * There are individual methods for formatting a request line, a * status line, or a header line. The formatting does <i>not</i> include the * trailing line break sequence CR-LF. * Instances of this interface are expected to be stateless and thread-safe. * * <p> * The formatted lines are returned in memory, the formatter does not depend * on any specific IO mechanism. * In order to avoid unnecessary creation of temporary objects, * a buffer can be passed as argument to all formatting methods. * The implementation may or may not actually use that buffer for formatting. * If it is used, the buffer will first be cleared by the * <code>formatXXX</code> methods. * The argument buffer can always be re-used after the call. The buffer * returned as the result, if it is different from the argument buffer, * MUST NOT be modified. * </p> * * @since 4.0 */ public interface LineFormatter { /** * Formats a protocol version. * This method does <i>not</i> follow the general contract for * <code>buffer</code> arguments. * It does <i>not</i> clear the argument buffer, but appends instead. * The returned buffer can always be modified by the caller. * Because of these differing conventions, it is not named * <code>formatProtocolVersion</code>. * * @param buffer a buffer to which to append, or <code>null</code> * @param version the protocol version to format * * @return a buffer with the formatted protocol version appended. * The caller is allowed to modify the result buffer. * If the <code>buffer</code> argument is not <code>null</code>, * the returned buffer is the argument buffer. */ CharArrayBuffer appendProtocolVersion(CharArrayBuffer buffer, ProtocolVersion version); /** * Formats a request line. * * @param buffer a buffer available for formatting, or * <code>null</code>. * The buffer will be cleared before use. * @param reqline the request line to format * * @return the formatted request line */ CharArrayBuffer formatRequestLine(CharArrayBuffer buffer, RequestLine reqline); /** * Formats a status line. * * @param buffer a buffer available for formatting, or * <code>null</code>. * The buffer will be cleared before use. * @param statline the status line to format * * @return the formatted status line * * @throws org.apache.ogt.http.ParseException in case of a parse error */ CharArrayBuffer formatStatusLine(CharArrayBuffer buffer, StatusLine statline); /** * Formats a header. * Due to header continuation, the result may be multiple lines. * In order to generate well-formed HTTP, the lines in the result * must be separated by the HTTP line break sequence CR-LF. * There is <i>no</i> trailing CR-LF in the result. * <br/> * See the class comment for details about the buffer argument. * * @param buffer a buffer available for formatting, or * <code>null</code>. * The buffer will be cleared before use. * @param header the header to format * * @return a buffer holding the formatted header, never <code>null</code>. * The returned buffer may be different from the argument buffer. * * @throws org.apache.ogt.http.ParseException in case of a parse error */ CharArrayBuffer formatHeader(CharArrayBuffer buffer, Header header); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/LineFormatter.java
Java
gpl3
5,367
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.message; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Locale; import org.apache.ogt.http.Header; import org.apache.ogt.http.HeaderIterator; import org.apache.ogt.http.util.CharArrayBuffer; /** * A class for combining a set of headers. * This class allows for multiple headers with the same name and * keeps track of the order in which headers were added. * * * @since 4.0 */ public class HeaderGroup implements Cloneable, Serializable { private static final long serialVersionUID = 2608834160639271617L; /** The list of headers for this group, in the order in which they were added */ private final List headers; /** * Constructor for HeaderGroup. */ public HeaderGroup() { this.headers = new ArrayList(16); } /** * Removes any contained headers. */ public void clear() { headers.clear(); } /** * Adds the given header to the group. The order in which this header was * added is preserved. * * @param header the header to add */ public void addHeader(Header header) { if (header == null) { return; } headers.add(header); } /** * Removes the given header. * * @param header the header to remove */ public void removeHeader(Header header) { if (header == null) { return; } headers.remove(header); } /** * Replaces the first occurence of the header with the same name. If no header with * the same name is found the given header is added to the end of the list. * * @param header the new header that should replace the first header with the same * name if present in the list. */ public void updateHeader(Header header) { if (header == null) { return; } for (int i = 0; i < this.headers.size(); i++) { Header current = (Header) this.headers.get(i); if (current.getName().equalsIgnoreCase(header.getName())) { this.headers.set(i, header); return; } } this.headers.add(header); } /** * Sets all of the headers contained within this group overriding any * existing headers. The headers are added in the order in which they appear * in the array. * * @param headers the headers to set */ public void setHeaders(Header[] headers) { clear(); if (headers == null) { return; } for (int i = 0; i < headers.length; i++) { this.headers.add(headers[i]); } } /** * Gets a header representing all of the header values with the given name. * If more that one header with the given name exists the values will be * combined with a "," as per RFC 2616. * * <p>Header name comparison is case insensitive. * * @param name the name of the header(s) to get * @return a header with a condensed value or <code>null</code> if no * headers by the given name are present */ public Header getCondensedHeader(String name) { Header[] headers = getHeaders(name); if (headers.length == 0) { return null; } else if (headers.length == 1) { return headers[0]; } else { CharArrayBuffer valueBuffer = new CharArrayBuffer(128); valueBuffer.append(headers[0].getValue()); for (int i = 1; i < headers.length; i++) { valueBuffer.append(", "); valueBuffer.append(headers[i].getValue()); } return new BasicHeader(name.toLowerCase(Locale.ENGLISH), valueBuffer.toString()); } } /** * Gets all of the headers with the given name. The returned array * maintains the relative order in which the headers were added. * * <p>Header name comparison is case insensitive. * * @param name the name of the header(s) to get * * @return an array of length >= 0 */ public Header[] getHeaders(String name) { ArrayList headersFound = new ArrayList(); for (int i = 0; i < headers.size(); i++) { Header header = (Header) headers.get(i); if (header.getName().equalsIgnoreCase(name)) { headersFound.add(header); } } return (Header[]) headersFound.toArray(new Header[headersFound.size()]); } /** * Gets the first header with the given name. * * <p>Header name comparison is case insensitive. * * @param name the name of the header to get * @return the first header or <code>null</code> */ public Header getFirstHeader(String name) { for (int i = 0; i < headers.size(); i++) { Header header = (Header) headers.get(i); if (header.getName().equalsIgnoreCase(name)) { return header; } } return null; } /** * Gets the last header with the given name. * * <p>Header name comparison is case insensitive. * * @param name the name of the header to get * @return the last header or <code>null</code> */ public Header getLastHeader(String name) { // start at the end of the list and work backwards for (int i = headers.size() - 1; i >= 0; i--) { Header header = (Header) headers.get(i); if (header.getName().equalsIgnoreCase(name)) { return header; } } return null; } /** * Gets all of the headers contained within this group. * * @return an array of length >= 0 */ public Header[] getAllHeaders() { return (Header[]) headers.toArray(new Header[headers.size()]); } /** * Tests if headers with the given name are contained within this group. * * <p>Header name comparison is case insensitive. * * @param name the header name to test for * @return <code>true</code> if at least one header with the name is * contained, <code>false</code> otherwise */ public boolean containsHeader(String name) { for (int i = 0; i < headers.size(); i++) { Header header = (Header) headers.get(i); if (header.getName().equalsIgnoreCase(name)) { return true; } } return false; } /** * Returns an iterator over this group of headers. * * @return iterator over this group of headers. * * @since 4.0 */ public HeaderIterator iterator() { return new BasicListHeaderIterator(this.headers, null); } /** * Returns an iterator over the headers with a given name in this group. * * @param name the name of the headers over which to iterate, or * <code>null</code> for all headers * * @return iterator over some headers in this group. * * @since 4.0 */ public HeaderIterator iterator(final String name) { return new BasicListHeaderIterator(this.headers, name); } /** * Returns a copy of this object * * @return copy of this object * * @since 4.0 */ public HeaderGroup copy() { HeaderGroup clone = new HeaderGroup(); clone.headers.addAll(this.headers); return clone; } public Object clone() throws CloneNotSupportedException { HeaderGroup clone = (HeaderGroup) super.clone(); clone.headers.clear(); clone.headers.addAll(this.headers); return clone; } public String toString() { return this.headers.toString(); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/message/HeaderGroup.java
Java
gpl3
9,027
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http; import java.io.IOException; import org.apache.ogt.http.protocol.HttpContext; /** * HTTP protocol interceptor is a routine that implements a specific aspect of * the HTTP protocol. Usually protocol interceptors are expected to act upon * one specific header or a group of related headers of the incoming message * or populate the outgoing message with one specific header or a group of * related headers. Protocol * <p> * Interceptors can also manipulate content entities enclosed with messages. * Usually this is accomplished by using the 'Decorator' pattern where a wrapper * entity class is used to decorate the original entity. * <p> * Protocol interceptors must be implemented as thread-safe. Similarly to * servlets, protocol interceptors should not use instance variables unless * access to those variables is synchronized. * * @since 4.0 */ public interface HttpResponseInterceptor { /** * Processes a response. * On the server side, this step is performed before the response is * sent to the client. On the client side, this step is performed * on incoming messages before the message body is evaluated. * * @param response the response to postprocess * @param context the context for the request * * @throws HttpException in case of an HTTP protocol violation * @throws IOException in case of an I/O error */ void process(HttpResponse response, HttpContext context) throws HttpException, IOException; }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/HttpResponseInterceptor.java
Java
gpl3
2,722
<html> <head> <!-- /* * ==================================================================== * 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 * <http://www.apache.org/>. * */ --> </head> <body> HTTP protocol execution framework. This package contains common protocol aspects implemented as protocol interceptors as well as protocol handler implementations based on classic (blocking) I/O model. </body> </html>
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/package.html
HTML
gpl3
1,440
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; /** * Generates a date in the format required by the HTTP protocol. * * @since 4.0 */ public class HttpDateGenerator { /** Date format pattern used to generate the header in RFC 1123 format. */ public static final String PATTERN_RFC1123 = "EEE, dd MMM yyyy HH:mm:ss zzz"; /** The time zone to use in the date header. */ public static final TimeZone GMT = TimeZone.getTimeZone("GMT"); private final DateFormat dateformat; private long dateAsLong = 0L; private String dateAsText = null; public HttpDateGenerator() { super(); this.dateformat = new SimpleDateFormat(PATTERN_RFC1123, Locale.US); this.dateformat.setTimeZone(GMT); } public synchronized String getCurrentDate() { long now = System.currentTimeMillis(); if (now - this.dateAsLong > 1000) { // Generate new date string this.dateAsText = this.dateformat.format(new Date(now)); this.dateAsLong = now; } return this.dateAsText; } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/HttpDateGenerator.java
Java
gpl3
2,407
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpRequest; import org.apache.ogt.http.HttpRequestInterceptor; import org.apache.ogt.http.HttpResponse; import org.apache.ogt.http.HttpResponseInterceptor; /** * Default implementation of {@link HttpProcessor}. * <p> * Please note access to the internal structures of this class is not * synchronized and therefore this class may be thread-unsafe. * * @since 4.0 */ //@NotThreadSafe // Lists are not synchronized public final class BasicHttpProcessor implements HttpProcessor, HttpRequestInterceptorList, HttpResponseInterceptorList, Cloneable { // Don't allow direct access, as nulls are not allowed protected final List requestInterceptors = new ArrayList(); protected final List responseInterceptors = new ArrayList(); public void addRequestInterceptor(final HttpRequestInterceptor itcp) { if (itcp == null) { return; } this.requestInterceptors.add(itcp); } public void addRequestInterceptor( final HttpRequestInterceptor itcp, int index) { if (itcp == null) { return; } this.requestInterceptors.add(index, itcp); } public void addResponseInterceptor( final HttpResponseInterceptor itcp, int index) { if (itcp == null) { return; } this.responseInterceptors.add(index, itcp); } public void removeRequestInterceptorByClass(final Class clazz) { for (Iterator it = this.requestInterceptors.iterator(); it.hasNext(); ) { Object request = it.next(); if (request.getClass().equals(clazz)) { it.remove(); } } } public void removeResponseInterceptorByClass(final Class clazz) { for (Iterator it = this.responseInterceptors.iterator(); it.hasNext(); ) { Object request = it.next(); if (request.getClass().equals(clazz)) { it.remove(); } } } public final void addInterceptor(final HttpRequestInterceptor interceptor) { addRequestInterceptor(interceptor); } public final void addInterceptor(final HttpRequestInterceptor interceptor, int index) { addRequestInterceptor(interceptor, index); } public int getRequestInterceptorCount() { return this.requestInterceptors.size(); } public HttpRequestInterceptor getRequestInterceptor(int index) { if ((index < 0) || (index >= this.requestInterceptors.size())) return null; return (HttpRequestInterceptor) this.requestInterceptors.get(index); } public void clearRequestInterceptors() { this.requestInterceptors.clear(); } public void addResponseInterceptor(final HttpResponseInterceptor itcp) { if (itcp == null) { return; } this.responseInterceptors.add(itcp); } public final void addInterceptor(final HttpResponseInterceptor interceptor) { addResponseInterceptor(interceptor); } public final void addInterceptor(final HttpResponseInterceptor interceptor, int index) { addResponseInterceptor(interceptor, index); } public int getResponseInterceptorCount() { return this.responseInterceptors.size(); } public HttpResponseInterceptor getResponseInterceptor(int index) { if ((index < 0) || (index >= this.responseInterceptors.size())) return null; return (HttpResponseInterceptor) this.responseInterceptors.get(index); } public void clearResponseInterceptors() { this.responseInterceptors.clear(); } /** * Sets the interceptor lists. * First, both interceptor lists maintained by this processor * will be cleared. * Subsequently, * elements of the argument list that are request interceptors will be * added to the request interceptor list. * Elements that are response interceptors will be * added to the response interceptor list. * Elements that are both request and response interceptor will be * added to both lists. * Elements that are neither request nor response interceptor * will be ignored. * * @param list the list of request and response interceptors * from which to initialize */ public void setInterceptors(final List list) { if (list == null) { throw new IllegalArgumentException("List must not be null."); } this.requestInterceptors.clear(); this.responseInterceptors.clear(); for (int i = 0; i < list.size(); i++) { Object obj = list.get(i); if (obj instanceof HttpRequestInterceptor) { addInterceptor((HttpRequestInterceptor)obj); } if (obj instanceof HttpResponseInterceptor) { addInterceptor((HttpResponseInterceptor)obj); } } } /** * Clears both interceptor lists maintained by this processor. */ public void clearInterceptors() { clearRequestInterceptors(); clearResponseInterceptors(); } public void process( final HttpRequest request, final HttpContext context) throws IOException, HttpException { for (int i = 0; i < this.requestInterceptors.size(); i++) { HttpRequestInterceptor interceptor = (HttpRequestInterceptor) this.requestInterceptors.get(i); interceptor.process(request, context); } } public void process( final HttpResponse response, final HttpContext context) throws IOException, HttpException { for (int i = 0; i < this.responseInterceptors.size(); i++) { HttpResponseInterceptor interceptor = (HttpResponseInterceptor) this.responseInterceptors.get(i); interceptor.process(response, context); } } /** * Sets up the target to have the same list of interceptors * as the current instance. * * @param target object to be initialised */ protected void copyInterceptors(final BasicHttpProcessor target) { target.requestInterceptors.clear(); target.requestInterceptors.addAll(this.requestInterceptors); target.responseInterceptors.clear(); target.responseInterceptors.addAll(this.responseInterceptors); } /** * Creates a copy of this instance * * @return new instance of the BasicHttpProcessor */ public BasicHttpProcessor copy() { BasicHttpProcessor clone = new BasicHttpProcessor(); copyInterceptors(clone); return clone; } public Object clone() throws CloneNotSupportedException { BasicHttpProcessor clone = (BasicHttpProcessor) super.clone(); copyInterceptors(clone); return clone; } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/BasicHttpProcessor.java
Java
gpl3
8,345
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.io.IOException; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpRequest; import org.apache.ogt.http.HttpResponse; /** * HttpRequestHandler represents a routine for processing of a specific group * of HTTP requests. Protocol handlers are designed to take care of protocol * specific aspects, whereas individual request handlers are expected to take * care of application specific HTTP processing. The main purpose of a request * handler is to generate a response object with a content entity to be sent * back to the client in response to the given request * * @since 4.0 */ public interface HttpRequestHandler { /** * Handles the request and produces a response to be sent back to * the client. * * @param request the HTTP request. * @param response the HTTP response. * @param context the HTTP execution context. * @throws IOException in case of an I/O error. * @throws HttpException in case of HTTP protocol violation or a processing * problem. */ void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException; }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/HttpRequestHandler.java
Java
gpl3
2,410
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.io.IOException; import org.apache.ogt.http.ConnectionReuseStrategy; import org.apache.ogt.http.HttpEntity; import org.apache.ogt.http.HttpEntityEnclosingRequest; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpRequest; import org.apache.ogt.http.HttpResponse; import org.apache.ogt.http.HttpResponseFactory; import org.apache.ogt.http.HttpServerConnection; import org.apache.ogt.http.HttpStatus; import org.apache.ogt.http.HttpVersion; import org.apache.ogt.http.MethodNotSupportedException; import org.apache.ogt.http.ProtocolException; import org.apache.ogt.http.ProtocolVersion; import org.apache.ogt.http.UnsupportedHttpVersionException; import org.apache.ogt.http.entity.ByteArrayEntity; import org.apache.ogt.http.params.DefaultedHttpParams; import org.apache.ogt.http.params.HttpParams; import org.apache.ogt.http.util.EncodingUtils; import org.apache.ogt.http.util.EntityUtils; /** * HttpService is a server side HTTP protocol handler based in the blocking * I/O model that implements the essential requirements of the HTTP protocol * for the server side message processing as described by RFC 2616. * <br> * HttpService relies on {@link HttpProcessor} to generate mandatory protocol * headers for all outgoing messages and apply common, cross-cutting message * transformations to all incoming and outgoing messages, whereas individual * {@link HttpRequestHandler}s are expected to take care of application specific * content generation and processing. * <br> * HttpService relies on {@link HttpRequestHandler} to resolve matching request * handler for a particular request URI of an incoming HTTP request. * <br> * HttpService can use optional {@link HttpExpectationVerifier} to ensure that * incoming requests meet server's expectations. * * @since 4.0 */ public class HttpService { /** * TODO: make all variables final in the next major version */ private volatile HttpParams params = null; private volatile HttpProcessor processor = null; private volatile HttpRequestHandlerResolver handlerResolver = null; private volatile ConnectionReuseStrategy connStrategy = null; private volatile HttpResponseFactory responseFactory = null; private volatile HttpExpectationVerifier expectationVerifier = null; /** * Create a new HTTP service. * * @param processor the processor to use on requests and responses * @param connStrategy the connection reuse strategy * @param responseFactory the response factory * @param handlerResolver the handler resolver. May be null. * @param expectationVerifier the expectation verifier. May be null. * @param params the HTTP parameters * * @since 4.1 */ public HttpService( final HttpProcessor processor, final ConnectionReuseStrategy connStrategy, final HttpResponseFactory responseFactory, final HttpRequestHandlerResolver handlerResolver, final HttpExpectationVerifier expectationVerifier, final HttpParams params) { super(); if (processor == null) { throw new IllegalArgumentException("HTTP processor may not be null"); } if (connStrategy == null) { throw new IllegalArgumentException("Connection reuse strategy may not be null"); } if (responseFactory == null) { throw new IllegalArgumentException("Response factory may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } this.processor = processor; this.connStrategy = connStrategy; this.responseFactory = responseFactory; this.handlerResolver = handlerResolver; this.expectationVerifier = expectationVerifier; this.params = params; } /** * Create a new HTTP service. * * @param processor the processor to use on requests and responses * @param connStrategy the connection reuse strategy * @param responseFactory the response factory * @param handlerResolver the handler resolver. May be null. * @param params the HTTP parameters * * @since 4.1 */ public HttpService( final HttpProcessor processor, final ConnectionReuseStrategy connStrategy, final HttpResponseFactory responseFactory, final HttpRequestHandlerResolver handlerResolver, final HttpParams params) { this(processor, connStrategy, responseFactory, handlerResolver, null, params); } /** * Create a new HTTP service. * * @param proc the processor to use on requests and responses * @param connStrategy the connection reuse strategy * @param responseFactory the response factory * * @deprecated use {@link HttpService#HttpService(HttpProcessor, * ConnectionReuseStrategy, HttpResponseFactory, HttpRequestHandlerResolver, HttpParams)} */ public HttpService( final HttpProcessor proc, final ConnectionReuseStrategy connStrategy, final HttpResponseFactory responseFactory) { super(); setHttpProcessor(proc); setConnReuseStrategy(connStrategy); setResponseFactory(responseFactory); } /** * @deprecated set {@link HttpProcessor} using constructor */ public void setHttpProcessor(final HttpProcessor processor) { if (processor == null) { throw new IllegalArgumentException("HTTP processor may not be null"); } this.processor = processor; } /** * @deprecated set {@link ConnectionReuseStrategy} using constructor */ public void setConnReuseStrategy(final ConnectionReuseStrategy connStrategy) { if (connStrategy == null) { throw new IllegalArgumentException("Connection reuse strategy may not be null"); } this.connStrategy = connStrategy; } /** * @deprecated set {@link HttpResponseFactory} using constructor */ public void setResponseFactory(final HttpResponseFactory responseFactory) { if (responseFactory == null) { throw new IllegalArgumentException("Response factory may not be null"); } this.responseFactory = responseFactory; } /** * @deprecated set {@link HttpResponseFactory} using constructor */ public void setParams(final HttpParams params) { this.params = params; } /** * @deprecated set {@link HttpRequestHandlerResolver} using constructor */ public void setHandlerResolver(final HttpRequestHandlerResolver handlerResolver) { this.handlerResolver = handlerResolver; } /** * @deprecated set {@link HttpExpectationVerifier} using constructor */ public void setExpectationVerifier(final HttpExpectationVerifier expectationVerifier) { this.expectationVerifier = expectationVerifier; } public HttpParams getParams() { return this.params; } /** * Handles receives one HTTP request over the given connection within the * given execution context and sends a response back to the client. * * @param conn the active connection to the client * @param context the actual execution context. * @throws IOException in case of an I/O error. * @throws HttpException in case of HTTP protocol violation or a processing * problem. */ public void handleRequest( final HttpServerConnection conn, final HttpContext context) throws IOException, HttpException { context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn); HttpResponse response = null; try { HttpRequest request = conn.receiveRequestHeader(); request.setParams( new DefaultedHttpParams(request.getParams(), this.params)); ProtocolVersion ver = request.getRequestLine().getProtocolVersion(); if (!ver.lessEquals(HttpVersion.HTTP_1_1)) { // Downgrade protocol version if greater than HTTP/1.1 ver = HttpVersion.HTTP_1_1; } if (request instanceof HttpEntityEnclosingRequest) { if (((HttpEntityEnclosingRequest) request).expectContinue()) { response = this.responseFactory.newHttpResponse(ver, HttpStatus.SC_CONTINUE, context); response.setParams( new DefaultedHttpParams(response.getParams(), this.params)); if (this.expectationVerifier != null) { try { this.expectationVerifier.verify(request, response, context); } catch (HttpException ex) { response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_0, HttpStatus.SC_INTERNAL_SERVER_ERROR, context); response.setParams( new DefaultedHttpParams(response.getParams(), this.params)); handleException(ex, response); } } if (response.getStatusLine().getStatusCode() < 200) { // Send 1xx response indicating the server expections // have been met conn.sendResponseHeader(response); conn.flush(); response = null; conn.receiveRequestEntity((HttpEntityEnclosingRequest) request); } } else { conn.receiveRequestEntity((HttpEntityEnclosingRequest) request); } } if (response == null) { response = this.responseFactory.newHttpResponse(ver, HttpStatus.SC_OK, context); response.setParams( new DefaultedHttpParams(response.getParams(), this.params)); context.setAttribute(ExecutionContext.HTTP_REQUEST, request); context.setAttribute(ExecutionContext.HTTP_RESPONSE, response); this.processor.process(request, context); doService(request, response, context); } // Make sure the request content is fully consumed if (request instanceof HttpEntityEnclosingRequest) { HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity(); EntityUtils.consume(entity); } } catch (HttpException ex) { response = this.responseFactory.newHttpResponse (HttpVersion.HTTP_1_0, HttpStatus.SC_INTERNAL_SERVER_ERROR, context); response.setParams( new DefaultedHttpParams(response.getParams(), this.params)); handleException(ex, response); } this.processor.process(response, context); conn.sendResponseHeader(response); conn.sendResponseEntity(response); conn.flush(); if (!this.connStrategy.keepAlive(response, context)) { conn.close(); } } /** * Handles the given exception and generates an HTTP response to be sent * back to the client to inform about the exceptional condition encountered * in the course of the request processing. * * @param ex the exception. * @param response the HTTP response. */ protected void handleException(final HttpException ex, final HttpResponse response) { if (ex instanceof MethodNotSupportedException) { response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED); } else if (ex instanceof UnsupportedHttpVersionException) { response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED); } else if (ex instanceof ProtocolException) { response.setStatusCode(HttpStatus.SC_BAD_REQUEST); } else { response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR); } byte[] msg = EncodingUtils.getAsciiBytes(ex.getMessage()); ByteArrayEntity entity = new ByteArrayEntity(msg); entity.setContentType("text/plain; charset=US-ASCII"); response.setEntity(entity); } /** * The default implementation of this method attempts to resolve an * {@link HttpRequestHandler} for the request URI of the given request * and, if found, executes its * {@link HttpRequestHandler#handle(HttpRequest, HttpResponse, HttpContext)} * method. * <p> * Super-classes can override this method in order to provide a custom * implementation of the request processing logic. * * @param request the HTTP request. * @param response the HTTP response. * @param context the execution context. * @throws IOException in case of an I/O error. * @throws HttpException in case of HTTP protocol violation or a processing * problem. */ protected void doService( final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException { HttpRequestHandler handler = null; if (this.handlerResolver != null) { String requestURI = request.getRequestLine().getUri(); handler = this.handlerResolver.lookup(requestURI); } if (handler != null) { handler.handle(request, response, context); } else { response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED); } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/HttpService.java
Java
gpl3
15,142
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.io.IOException; import org.apache.ogt.http.HttpEntityEnclosingRequest; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpRequest; import org.apache.ogt.http.HttpRequestInterceptor; /** * RequestDate interceptor is responsible for adding <code>Date</code> header * to the outgoing requests This interceptor is optional for client side * protocol processors. * * @since 4.0 */ public class RequestDate implements HttpRequestInterceptor { private static final HttpDateGenerator DATE_GENERATOR = new HttpDateGenerator(); public RequestDate() { super(); } public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (request == null) { throw new IllegalArgumentException ("HTTP request may not be null."); } if ((request instanceof HttpEntityEnclosingRequest) && !request.containsHeader(HTTP.DATE_HEADER)) { String httpdate = DATE_GENERATOR.getCurrentDate(); request.setHeader(HTTP.DATE_HEADER, httpdate); } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/RequestDate.java
Java
gpl3
2,367
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.util.List; import org.apache.ogt.http.HttpRequestInterceptor; /** * Provides access to an ordered list of request interceptors. * Lists are expected to be built upfront and used read-only afterwards * for {@link HttpProcessor processing}. * * @since 4.0 */ public interface HttpRequestInterceptorList { /** * Appends a request interceptor to this list. * * @param interceptor the request interceptor to add */ void addRequestInterceptor(HttpRequestInterceptor interceptor); /** * Inserts a request interceptor at the specified index. * * @param interceptor the request interceptor to add * @param index the index to insert the interceptor at */ void addRequestInterceptor(HttpRequestInterceptor interceptor, int index); /** * Obtains the current size of this list. * * @return the number of request interceptors in this list */ int getRequestInterceptorCount(); /** * Obtains a request interceptor from this list. * * @param index the index of the interceptor to obtain, * 0 for first * * @return the interceptor at the given index, or * <code>null</code> if the index is out of range */ HttpRequestInterceptor getRequestInterceptor(int index); /** * Removes all request interceptors from this list. */ void clearRequestInterceptors(); /** * Removes all request interceptor of the specified class * * @param clazz the class of the instances to be removed. */ void removeRequestInterceptorByClass(Class clazz); /** * Sets the request interceptors in this list. * This list will be cleared and re-initialized to contain * all request interceptors from the argument list. * If the argument list includes elements that are not request * interceptors, the behavior is implementation dependent. * * @param list the list of request interceptors */ void setInterceptors(List list); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/HttpRequestInterceptorList.java
Java
gpl3
3,297
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; /** * HttpRequestHandlerResolver can be used to resolve an instance of * {@link HttpRequestHandler} matching a particular request URI. Usually the * resolved request handler will be used to process the request with the * specified request URI. * * @since 4.0 */ public interface HttpRequestHandlerResolver { /** * Looks up a handler matching the given request URI. * * @param requestURI the request URI * @return HTTP request handler or <code>null</code> if no match * is found. */ HttpRequestHandler lookup(String requestURI); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/HttpRequestHandlerResolver.java
Java
gpl3
1,801
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.io.IOException; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpRequest; import org.apache.ogt.http.HttpRequestInterceptor; /** * RequestConnControl is responsible for adding <code>Connection</code> header * to the outgoing requests, which is essential for managing persistence of * <code>HTTP/1.0</code> connections. This interceptor is recommended for * client side protocol processors. * * @since 4.0 */ public class RequestConnControl implements HttpRequestInterceptor { public RequestConnControl() { super(); } public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (request == null) { throw new IllegalArgumentException("HTTP request may not be null"); } String method = request.getRequestLine().getMethod(); if (method.equalsIgnoreCase("CONNECT")) { return; } if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) { // Default policy is to keep connection alive // whenever possible request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE); } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/RequestConnControl.java
Java
gpl3
2,439
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.io.IOException; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpResponse; import org.apache.ogt.http.HttpResponseInterceptor; import org.apache.ogt.http.params.CoreProtocolPNames; /** * ResponseServer is responsible for adding <code>Server</code> header. This * interceptor is recommended for server side protocol processors. * <p> * The following parameters can be used to customize the behavior of this * class: * <ul> * <li>{@link org.apache.ogt.http.params.CoreProtocolPNames#ORIGIN_SERVER}</li> * </ul> * * @since 4.0 */ public class ResponseServer implements HttpResponseInterceptor { public ResponseServer() { super(); } public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { if (response == null) { throw new IllegalArgumentException("HTTP request may not be null"); } if (!response.containsHeader(HTTP.SERVER_HEADER)) { String s = (String) response.getParams().getParameter( CoreProtocolPNames.ORIGIN_SERVER); if (s != null) { response.addHeader(HTTP.SERVER_HEADER, s); } } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/ResponseServer.java
Java
gpl3
2,474
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.io.IOException; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpResponse; import org.apache.ogt.http.HttpResponseInterceptor; import org.apache.ogt.http.HttpStatus; /** * ResponseDate is responsible for adding <code>Date<c/ode> header to the * outgoing responses. This interceptor is recommended for server side protocol * processors. * * @since 4.0 */ public class ResponseDate implements HttpResponseInterceptor { private static final HttpDateGenerator DATE_GENERATOR = new HttpDateGenerator(); public ResponseDate() { super(); } public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { if (response == null) { throw new IllegalArgumentException ("HTTP response may not be null."); } int status = response.getStatusLine().getStatusCode(); if ((status >= HttpStatus.SC_OK) && !response.containsHeader(HTTP.DATE_HEADER)) { String httpdate = DATE_GENERATOR.getCurrentDate(); response.setHeader(HTTP.DATE_HEADER, httpdate); } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/ResponseDate.java
Java
gpl3
2,400
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; /** * {@link HttpContext} implementation that delegates resolution of an attribute * to the given default {@link HttpContext} instance if the attribute is not * present in the local one. The state of the local context can be mutated, * whereas the default context is treated as read-only. * * @since 4.0 */ public final class DefaultedHttpContext implements HttpContext { private final HttpContext local; private final HttpContext defaults; public DefaultedHttpContext(final HttpContext local, final HttpContext defaults) { super(); if (local == null) { throw new IllegalArgumentException("HTTP context may not be null"); } this.local = local; this.defaults = defaults; } public Object getAttribute(final String id) { Object obj = this.local.getAttribute(id); if (obj == null) { return this.defaults.getAttribute(id); } else { return obj; } } public Object removeAttribute(final String id) { return this.local.removeAttribute(id); } public void setAttribute(final String id, final Object obj) { this.local.setAttribute(id, obj); } public HttpContext getDefaults() { return this.defaults; } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/DefaultedHttpContext.java
Java
gpl3
2,510
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import org.apache.ogt.http.HttpRequestInterceptor; import org.apache.ogt.http.HttpResponseInterceptor; /** * HTTP protocol processor is a collection of protocol interceptors that * implements the 'Chain of Responsibility' pattern, where each individual * protocol interceptor is expected to work on a particular aspect of the HTTP * protocol the interceptor is responsible for. * <p> * Usually the order in which interceptors are executed should not matter as * long as they do not depend on a particular state of the execution context. * If protocol interceptors have interdependencies and therefore must be * executed in a particular order, they should be added to the protocol * processor in the same sequence as their expected execution order. * <p> * Protocol interceptors must be implemented as thread-safe. Similarly to * servlets, protocol interceptors should not use instance variables unless * access to those variables is synchronized. * * @since 4.0 */ public interface HttpProcessor extends HttpRequestInterceptor, HttpResponseInterceptor { // no additional methods }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/HttpProcessor.java
Java
gpl3
2,332
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.io.IOException; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpRequest; import org.apache.ogt.http.HttpRequestInterceptor; import org.apache.ogt.http.params.HttpProtocolParams; /** * RequestUserAgent is responsible for adding <code>User-Agent</code> header. * This interceptor is recommended for client side protocol processors. * <p> * The following parameters can be used to customize the behavior of this * class: * <ul> * <li>{@link org.apache.ogt.http.params.CoreProtocolPNames#USER_AGENT}</li> * </ul> * * @since 4.0 */ public class RequestUserAgent implements HttpRequestInterceptor { public RequestUserAgent() { super(); } public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (request == null) { throw new IllegalArgumentException("HTTP request may not be null"); } if (!request.containsHeader(HTTP.USER_AGENT)) { String useragent = HttpProtocolParams.getUserAgent(request.getParams()); if (useragent != null) { request.addHeader(HTTP.USER_AGENT, useragent); } } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/RequestUserAgent.java
Java
gpl3
2,442
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.util.HashMap; /** * HttpContext represents execution state of an HTTP process. It is a structure * that can be used to map an attribute name to an attribute value. Internally * HTTP context implementations are usually backed by a {@link HashMap}. * <p> * The primary purpose of the HTTP context is to facilitate information sharing * among various logically related components. HTTP context can be used * to store a processing state for one message or several consecutive messages. * Multiple logically related messages can participate in a logical session * if the same context is reused between consecutive messages. * * @since 4.0 */ public interface HttpContext { /** The prefix reserved for use by HTTP components. "http." */ public static final String RESERVED_PREFIX = "http."; /** * Obtains attribute with the given name. * * @param id the attribute name. * @return attribute value, or <code>null</code> if not set. */ Object getAttribute(String id); /** * Sets value of the attribute with the given name. * * @param id the attribute name. * @param obj the attribute value. */ void setAttribute(String id, Object obj); /** * Removes attribute with the given name from the context. * * @param id the attribute name. * @return attribute value, or <code>null</code> if not set. */ Object removeAttribute(String id); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/HttpContext.java
Java
gpl3
2,686
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.io.IOException; import org.apache.ogt.http.HttpEntity; import org.apache.ogt.http.HttpEntityEnclosingRequest; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpRequest; import org.apache.ogt.http.HttpRequestInterceptor; import org.apache.ogt.http.HttpVersion; import org.apache.ogt.http.ProtocolVersion; import org.apache.ogt.http.params.HttpProtocolParams; /** * RequestExpectContinue is responsible for enabling the 'expect-continue' * handshake by adding <code>Expect</code> header. This interceptor is * recommended for client side protocol processors. * <p> * The following parameters can be used to customize the behavior of this * class: * <ul> * <li>{@link org.apache.ogt.http.params.CoreProtocolPNames#USE_EXPECT_CONTINUE}</li> * </ul> * * @since 4.0 */ public class RequestExpectContinue implements HttpRequestInterceptor { public RequestExpectContinue() { super(); } public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (request == null) { throw new IllegalArgumentException("HTTP request may not be null"); } if (request instanceof HttpEntityEnclosingRequest) { HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity(); // Do not send the expect header if request body is known to be empty if (entity != null && entity.getContentLength() != 0) { ProtocolVersion ver = request.getRequestLine().getProtocolVersion(); if (HttpProtocolParams.useExpectContinue(request.getParams()) && !ver.lessEquals(HttpVersion.HTTP_1_0)) { request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE); } } } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/RequestExpectContinue.java
Java
gpl3
3,077
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.io.IOException; import java.net.ProtocolException; import org.apache.ogt.http.HttpClientConnection; import org.apache.ogt.http.HttpEntity; import org.apache.ogt.http.HttpEntityEnclosingRequest; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpRequest; import org.apache.ogt.http.HttpResponse; import org.apache.ogt.http.HttpStatus; import org.apache.ogt.http.HttpVersion; import org.apache.ogt.http.ProtocolVersion; import org.apache.ogt.http.params.CoreProtocolPNames; /** * HttpRequestExecutor is a client side HTTP protocol handler based on the * blocking I/O model that implements the essential requirements of the HTTP * protocol for the client side message processing, as described by RFC 2616. * <br> * HttpRequestExecutor relies on {@link HttpProcessor} to generate mandatory * protocol headers for all outgoing messages and apply common, cross-cutting * message transformations to all incoming and outgoing messages. Application * specific processing can be implemented outside HttpRequestExecutor once the * request has been executed and a response has been received. * <p> * The following parameters can be used to customize the behavior of this * class: * <ul> * <li>{@link org.apache.ogt.http.params.CoreProtocolPNames#WAIT_FOR_CONTINUE}</li> * </ul> * * @since 4.0 */ public class HttpRequestExecutor { /** * Create a new request executor. */ public HttpRequestExecutor() { super(); } /** * Decide whether a response comes with an entity. * The implementation in this class is based on RFC 2616. * <br/> * Derived executors can override this method to handle * methods and response codes not specified in RFC 2616. * * @param request the request, to obtain the executed method * @param response the response, to obtain the status code */ protected boolean canResponseHaveBody(final HttpRequest request, final HttpResponse response) { if ("HEAD".equalsIgnoreCase(request.getRequestLine().getMethod())) { return false; } int status = response.getStatusLine().getStatusCode(); return status >= HttpStatus.SC_OK && status != HttpStatus.SC_NO_CONTENT && status != HttpStatus.SC_NOT_MODIFIED && status != HttpStatus.SC_RESET_CONTENT; } /** * Sends the request and obtain a response. * * @param request the request to execute. * @param conn the connection over which to execute the request. * * @return the response to the request. * * @throws IOException in case of an I/O error. * @throws HttpException in case of HTTP protocol violation or a processing * problem. */ public HttpResponse execute( final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws IOException, HttpException { if (request == null) { throw new IllegalArgumentException("HTTP request may not be null"); } if (conn == null) { throw new IllegalArgumentException("Client connection may not be null"); } if (context == null) { throw new IllegalArgumentException("HTTP context may not be null"); } try { HttpResponse response = doSendRequest(request, conn, context); if (response == null) { response = doReceiveResponse(request, conn, context); } return response; } catch (IOException ex) { closeConnection(conn); throw ex; } catch (HttpException ex) { closeConnection(conn); throw ex; } catch (RuntimeException ex) { closeConnection(conn); throw ex; } } private final static void closeConnection(final HttpClientConnection conn) { try { conn.close(); } catch (IOException ignore) { } } /** * Pre-process the given request using the given protocol processor and * initiates the process of request execution. * * @param request the request to prepare * @param processor the processor to use * @param context the context for sending the request * * @throws IOException in case of an I/O error. * @throws HttpException in case of HTTP protocol violation or a processing * problem. */ public void preProcess( final HttpRequest request, final HttpProcessor processor, final HttpContext context) throws HttpException, IOException { if (request == null) { throw new IllegalArgumentException("HTTP request may not be null"); } if (processor == null) { throw new IllegalArgumentException("HTTP processor may not be null"); } if (context == null) { throw new IllegalArgumentException("HTTP context may not be null"); } context.setAttribute(ExecutionContext.HTTP_REQUEST, request); processor.process(request, context); } /** * Send the given request over the given connection. * <p> * This method also handles the expect-continue handshake if necessary. * If it does not have to handle an expect-continue handshake, it will * not use the connection for reading or anything else that depends on * data coming in over the connection. * * @param request the request to send, already * {@link #preProcess preprocessed} * @param conn the connection over which to send the request, * already established * @param context the context for sending the request * * @return a terminal response received as part of an expect-continue * handshake, or * <code>null</code> if the expect-continue handshake is not used * * @throws IOException in case of an I/O error. * @throws HttpException in case of HTTP protocol violation or a processing * problem. */ protected HttpResponse doSendRequest( final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws IOException, HttpException { if (request == null) { throw new IllegalArgumentException("HTTP request may not be null"); } if (conn == null) { throw new IllegalArgumentException("HTTP connection may not be null"); } if (context == null) { throw new IllegalArgumentException("HTTP context may not be null"); } HttpResponse response = null; context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn); context.setAttribute(ExecutionContext.HTTP_REQ_SENT, Boolean.FALSE); conn.sendRequestHeader(request); if (request instanceof HttpEntityEnclosingRequest) { // Check for expect-continue handshake. We have to flush the // headers and wait for an 100-continue response to handle it. // If we get a different response, we must not send the entity. boolean sendentity = true; final ProtocolVersion ver = request.getRequestLine().getProtocolVersion(); if (((HttpEntityEnclosingRequest) request).expectContinue() && !ver.lessEquals(HttpVersion.HTTP_1_0)) { conn.flush(); // As suggested by RFC 2616 section 8.2.3, we don't wait for a // 100-continue response forever. On timeout, send the entity. int tms = request.getParams().getIntParameter( CoreProtocolPNames.WAIT_FOR_CONTINUE, 2000); if (conn.isResponseAvailable(tms)) { response = conn.receiveResponseHeader(); if (canResponseHaveBody(request, response)) { conn.receiveResponseEntity(response); } int status = response.getStatusLine().getStatusCode(); if (status < 200) { if (status != HttpStatus.SC_CONTINUE) { throw new ProtocolException( "Unexpected response: " + response.getStatusLine()); } // discard 100-continue response = null; } else { sendentity = false; } } } if (sendentity) { conn.sendRequestEntity((HttpEntityEnclosingRequest) request); } } conn.flush(); context.setAttribute(ExecutionContext.HTTP_REQ_SENT, Boolean.TRUE); return response; } /** * Waits for and receives a response. * This method will automatically ignore intermediate responses * with status code 1xx. * * @param request the request for which to obtain the response * @param conn the connection over which the request was sent * @param context the context for receiving the response * * @return the terminal response, not yet post-processed * * @throws IOException in case of an I/O error. * @throws HttpException in case of HTTP protocol violation or a processing * problem. */ protected HttpResponse doReceiveResponse( final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws HttpException, IOException { if (request == null) { throw new IllegalArgumentException("HTTP request may not be null"); } if (conn == null) { throw new IllegalArgumentException("HTTP connection may not be null"); } if (context == null) { throw new IllegalArgumentException("HTTP context may not be null"); } HttpResponse response = null; int statuscode = 0; while (response == null || statuscode < HttpStatus.SC_OK) { response = conn.receiveResponseHeader(); if (canResponseHaveBody(request, response)) { conn.receiveResponseEntity(response); } statuscode = response.getStatusLine().getStatusCode(); } // while intermediate response return response; } /** * Post-processes the given response using the given protocol processor and * completes the process of request execution. * <p> * This method does <i>not</i> read the response entity, if any. * The connection over which content of the response entity is being * streamed from cannot be reused until {@link HttpEntity#consumeContent()} * has been invoked. * * @param response the response object to post-process * @param processor the processor to use * @param context the context for post-processing the response * * @throws IOException in case of an I/O error. * @throws HttpException in case of HTTP protocol violation or a processing * problem. */ public void postProcess( final HttpResponse response, final HttpProcessor processor, final HttpContext context) throws HttpException, IOException { if (response == null) { throw new IllegalArgumentException("HTTP response may not be null"); } if (processor == null) { throw new IllegalArgumentException("HTTP processor may not be null"); } if (context == null) { throw new IllegalArgumentException("HTTP context may not be null"); } context.setAttribute(ExecutionContext.HTTP_RESPONSE, response); processor.process(response, context); } } // class HttpRequestExecutor
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/HttpRequestExecutor.java
Java
gpl3
13,382
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.util.HashMap; import java.util.Iterator; import java.util.Map; /** * Maintains a map of objects keyed by a request URI pattern. * <br> * Patterns may have three formats: * <ul> * <li><code>*</code></li> * <li><code>*&lt;uri&gt;</code></li> * <li><code>&lt;uri&gt;*</code></li> * </ul> * <br> * This class can be used to resolve an object matching a particular request * URI. * * @since 4.0 */ public class UriPatternMatcher { /** * TODO: Replace with ConcurrentHashMap */ private final Map map; public UriPatternMatcher() { super(); this.map = new HashMap(); } /** * Registers the given object for URIs matching the given pattern. * * @param pattern the pattern to register the handler for. * @param obj the object. */ public synchronized void register(final String pattern, final Object obj) { if (pattern == null) { throw new IllegalArgumentException("URI request pattern may not be null"); } this.map.put(pattern, obj); } /** * Removes registered object, if exists, for the given pattern. * * @param pattern the pattern to unregister. */ public synchronized void unregister(final String pattern) { if (pattern == null) { return; } this.map.remove(pattern); } /** * @deprecated use {@link #setObjects(Map)} */ public synchronized void setHandlers(final Map map) { if (map == null) { throw new IllegalArgumentException("Map of handlers may not be null"); } this.map.clear(); this.map.putAll(map); } /** * Sets objects from the given map. * @param map the map containing objects keyed by their URI patterns. */ public synchronized void setObjects(final Map map) { if (map == null) { throw new IllegalArgumentException("Map of handlers may not be null"); } this.map.clear(); this.map.putAll(map); } /** * Looks up an object matching the given request URI. * * @param requestURI the request URI * @return object or <code>null</code> if no match is found. */ public synchronized Object lookup(String requestURI) { if (requestURI == null) { throw new IllegalArgumentException("Request URI may not be null"); } //Strip away the query part part if found int index = requestURI.indexOf("?"); if (index != -1) { requestURI = requestURI.substring(0, index); } // direct match? Object obj = this.map.get(requestURI); if (obj == null) { // pattern match? String bestMatch = null; for (Iterator it = this.map.keySet().iterator(); it.hasNext();) { String pattern = (String) it.next(); if (matchUriRequestPattern(pattern, requestURI)) { // we have a match. is it any better? if (bestMatch == null || (bestMatch.length() < pattern.length()) || (bestMatch.length() == pattern.length() && pattern.endsWith("*"))) { obj = this.map.get(pattern); bestMatch = pattern; } } } } return obj; } /** * Tests if the given request URI matches the given pattern. * * @param pattern the pattern * @param requestUri the request URI * @return <code>true</code> if the request URI matches the pattern, * <code>false</code> otherwise. */ protected boolean matchUriRequestPattern(final String pattern, final String requestUri) { if (pattern.equals("*")) { return true; } else { return (pattern.endsWith("*") && requestUri.startsWith(pattern.substring(0, pattern.length() - 1))) || (pattern.startsWith("*") && requestUri.endsWith(pattern.substring(1, pattern.length()))); } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/UriPatternMatcher.java
Java
gpl3
5,359
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.util.Map; /** * Maintains a map of HTTP request handlers keyed by a request URI pattern. * <br> * Patterns may have three formats: * <ul> * <li><code>*</code></li> * <li><code>*&lt;uri&gt;</code></li> * <li><code>&lt;uri&gt;*</code></li> * </ul> * <br> * This class can be used to resolve an instance of * {@link HttpRequestHandler} matching a particular request URI. Usually the * resolved request handler will be used to process the request with the * specified request URI. * * @since 4.0 */ public class HttpRequestHandlerRegistry implements HttpRequestHandlerResolver { private final UriPatternMatcher matcher; public HttpRequestHandlerRegistry() { matcher = new UriPatternMatcher(); } /** * Registers the given {@link HttpRequestHandler} as a handler for URIs * matching the given pattern. * * @param pattern the pattern to register the handler for. * @param handler the handler. */ public void register(final String pattern, final HttpRequestHandler handler) { if (pattern == null) { throw new IllegalArgumentException("URI request pattern may not be null"); } if (handler == null) { throw new IllegalArgumentException("Request handler may not be null"); } matcher.register(pattern, handler); } /** * Removes registered handler, if exists, for the given pattern. * * @param pattern the pattern to unregister the handler for. */ public void unregister(final String pattern) { matcher.unregister(pattern); } /** * Sets handlers from the given map. * @param map the map containing handlers keyed by their URI patterns. */ public void setHandlers(final Map map) { matcher.setObjects(map); } public HttpRequestHandler lookup(final String requestURI) { return (HttpRequestHandler) matcher.lookup(requestURI); } /** * @deprecated */ protected boolean matchUriRequestPattern(final String pattern, final String requestUri) { return matcher.matchUriRequestPattern(pattern, requestUri); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/HttpRequestHandlerRegistry.java
Java
gpl3
3,401
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; /** * {@link HttpContext} attribute names for protocol execution. * * @since 4.0 */ public interface ExecutionContext { /** * Attribute name of a {@link org.apache.ogt.http.HttpConnection} object that * represents the actual HTTP connection. */ public static final String HTTP_CONNECTION = "http.connection"; /** * Attribute name of a {@link org.apache.ogt.http.HttpRequest} object that * represents the actual HTTP request. */ public static final String HTTP_REQUEST = "http.request"; /** * Attribute name of a {@link org.apache.ogt.http.HttpResponse} object that * represents the actual HTTP response. */ public static final String HTTP_RESPONSE = "http.response"; /** * Attribute name of a {@link org.apache.ogt.http.HttpHost} object that * represents the connection target. */ public static final String HTTP_TARGET_HOST = "http.target_host"; /** * Attribute name of a {@link org.apache.ogt.http.HttpHost} object that * represents the connection proxy. */ public static final String HTTP_PROXY_HOST = "http.proxy_host"; /** * Attribute name of a {@link Boolean} object that represents the * the flag indicating whether the actual request has been fully transmitted * to the target host. */ public static final String HTTP_REQ_SENT = "http.request_sent"; }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/ExecutionContext.java
Java
gpl3
2,650
/* * ==================================================================== * 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 * <http://www.apache.org/>. */ package org.apache.ogt.http.protocol; import java.io.IOException; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpRequest; import org.apache.ogt.http.HttpRequestInterceptor; import org.apache.ogt.http.HttpResponse; import org.apache.ogt.http.HttpResponseInterceptor; /** * Immutable {@link HttpProcessor}. * * @since 4.1 */ //@ThreadSafe public final class ImmutableHttpProcessor implements HttpProcessor { private final HttpRequestInterceptor[] requestInterceptors; private final HttpResponseInterceptor[] responseInterceptors; public ImmutableHttpProcessor( final HttpRequestInterceptor[] requestInterceptors, final HttpResponseInterceptor[] responseInterceptors) { super(); if (requestInterceptors != null) { int count = requestInterceptors.length; this.requestInterceptors = new HttpRequestInterceptor[count]; for (int i = 0; i < count; i++) { this.requestInterceptors[i] = requestInterceptors[i]; } } else { this.requestInterceptors = new HttpRequestInterceptor[0]; } if (responseInterceptors != null) { int count = responseInterceptors.length; this.responseInterceptors = new HttpResponseInterceptor[count]; for (int i = 0; i < count; i++) { this.responseInterceptors[i] = responseInterceptors[i]; } } else { this.responseInterceptors = new HttpResponseInterceptor[0]; } } public ImmutableHttpProcessor( final HttpRequestInterceptorList requestInterceptors, final HttpResponseInterceptorList responseInterceptors) { super(); if (requestInterceptors != null) { int count = requestInterceptors.getRequestInterceptorCount(); this.requestInterceptors = new HttpRequestInterceptor[count]; for (int i = 0; i < count; i++) { this.requestInterceptors[i] = requestInterceptors.getRequestInterceptor(i); } } else { this.requestInterceptors = new HttpRequestInterceptor[0]; } if (responseInterceptors != null) { int count = responseInterceptors.getResponseInterceptorCount(); this.responseInterceptors = new HttpResponseInterceptor[count]; for (int i = 0; i < count; i++) { this.responseInterceptors[i] = responseInterceptors.getResponseInterceptor(i); } } else { this.responseInterceptors = new HttpResponseInterceptor[0]; } } public ImmutableHttpProcessor(final HttpRequestInterceptor[] requestInterceptors) { this(requestInterceptors, null); } public ImmutableHttpProcessor(final HttpResponseInterceptor[] responseInterceptors) { this(null, responseInterceptors); } public void process( final HttpRequest request, final HttpContext context) throws IOException, HttpException { for (int i = 0; i < this.requestInterceptors.length; i++) { this.requestInterceptors[i].process(request, context); } } public void process( final HttpResponse response, final HttpContext context) throws IOException, HttpException { for (int i = 0; i < this.responseInterceptors.length; i++) { this.responseInterceptors[i].process(response, context); } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/ImmutableHttpProcessor.java
Java
gpl3
4,693
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; /** * Constants and static helpers related to the HTTP protocol. * * @since 4.0 */ public final class HTTP { public static final int CR = 13; // <US-ASCII CR, carriage return (13)> public static final int LF = 10; // <US-ASCII LF, linefeed (10)> public static final int SP = 32; // <US-ASCII SP, space (32)> public static final int HT = 9; // <US-ASCII HT, horizontal-tab (9)> /** HTTP header definitions */ public static final String TRANSFER_ENCODING = "Transfer-Encoding"; public static final String CONTENT_LEN = "Content-Length"; public static final String CONTENT_TYPE = "Content-Type"; public static final String CONTENT_ENCODING = "Content-Encoding"; public static final String EXPECT_DIRECTIVE = "Expect"; public static final String CONN_DIRECTIVE = "Connection"; public static final String TARGET_HOST = "Host"; public static final String USER_AGENT = "User-Agent"; public static final String DATE_HEADER = "Date"; public static final String SERVER_HEADER = "Server"; /** HTTP expectations */ public static final String EXPECT_CONTINUE = "100-continue"; /** HTTP connection control */ public static final String CONN_CLOSE = "Close"; public static final String CONN_KEEP_ALIVE = "Keep-Alive"; /** Transfer encoding definitions */ public static final String CHUNK_CODING = "chunked"; public static final String IDENTITY_CODING = "identity"; /** Common charset definitions */ public static final String UTF_8 = "UTF-8"; public static final String UTF_16 = "UTF-16"; public static final String US_ASCII = "US-ASCII"; public static final String ASCII = "ASCII"; public static final String ISO_8859_1 = "ISO-8859-1"; /** Default charsets */ public static final String DEFAULT_CONTENT_CHARSET = ISO_8859_1; public static final String DEFAULT_PROTOCOL_CHARSET = US_ASCII; /** Content type definitions */ public final static String OCTET_STREAM_TYPE = "application/octet-stream"; public final static String PLAIN_TEXT_TYPE = "text/plain"; public final static String CHARSET_PARAM = "; charset="; /** Default content type */ public final static String DEFAULT_CONTENT_TYPE = OCTET_STREAM_TYPE; public static boolean isWhitespace(char ch) { return ch == SP || ch == HT || ch == CR || ch == LF; } private HTTP() { } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/HTTP.java
Java
gpl3
3,635
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.io.IOException; import org.apache.ogt.http.Header; import org.apache.ogt.http.HttpEntity; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpRequest; import org.apache.ogt.http.HttpResponse; import org.apache.ogt.http.HttpResponseInterceptor; import org.apache.ogt.http.HttpStatus; import org.apache.ogt.http.HttpVersion; import org.apache.ogt.http.ProtocolVersion; /** * ResponseConnControl is responsible for adding <code>Connection</code> header * to the outgoing responses, which is essential for managing persistence of * <code>HTTP/1.0</code> connections. This interceptor is recommended for * server side protocol processors. * * @since 4.0 */ public class ResponseConnControl implements HttpResponseInterceptor { public ResponseConnControl() { super(); } public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { if (response == null) { throw new IllegalArgumentException("HTTP response may not be null"); } if (context == null) { throw new IllegalArgumentException("HTTP context may not be null"); } // Always drop connection after certain type of responses int status = response.getStatusLine().getStatusCode(); if (status == HttpStatus.SC_BAD_REQUEST || status == HttpStatus.SC_REQUEST_TIMEOUT || status == HttpStatus.SC_LENGTH_REQUIRED || status == HttpStatus.SC_REQUEST_TOO_LONG || status == HttpStatus.SC_REQUEST_URI_TOO_LONG || status == HttpStatus.SC_SERVICE_UNAVAILABLE || status == HttpStatus.SC_NOT_IMPLEMENTED) { response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE); return; } // Always drop connection for HTTP/1.0 responses and below // if the content body cannot be correctly delimited HttpEntity entity = response.getEntity(); if (entity != null) { ProtocolVersion ver = response.getStatusLine().getProtocolVersion(); if (entity.getContentLength() < 0 && (!entity.isChunked() || ver.lessEquals(HttpVersion.HTTP_1_0))) { response.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE); return; } } // Drop connection if requested by the client HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); if (request != null) { Header header = request.getFirstHeader(HTTP.CONN_DIRECTIVE); if (header != null) { response.setHeader(HTTP.CONN_DIRECTIVE, header.getValue()); } } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/ResponseConnControl.java
Java
gpl3
4,019
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.io.IOException; import java.net.InetAddress; import org.apache.ogt.http.HttpConnection; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpHost; import org.apache.ogt.http.HttpInetConnection; import org.apache.ogt.http.HttpRequest; import org.apache.ogt.http.HttpRequestInterceptor; import org.apache.ogt.http.HttpVersion; import org.apache.ogt.http.ProtocolException; import org.apache.ogt.http.ProtocolVersion; /** * RequestTargetHost is responsible for adding <code>Host</code> header. This * interceptor is required for client side protocol processors. * * @since 4.0 */ public class RequestTargetHost implements HttpRequestInterceptor { public RequestTargetHost() { super(); } public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (request == null) { throw new IllegalArgumentException("HTTP request may not be null"); } if (context == null) { throw new IllegalArgumentException("HTTP context may not be null"); } ProtocolVersion ver = request.getRequestLine().getProtocolVersion(); String method = request.getRequestLine().getMethod(); if (method.equalsIgnoreCase("CONNECT") && ver.lessEquals(HttpVersion.HTTP_1_0)) { return; } if (!request.containsHeader(HTTP.TARGET_HOST)) { HttpHost targethost = (HttpHost) context .getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (targethost == null) { HttpConnection conn = (HttpConnection) context .getAttribute(ExecutionContext.HTTP_CONNECTION); if (conn instanceof HttpInetConnection) { // Populate the context with a default HTTP host based on the // inet address of the target host InetAddress address = ((HttpInetConnection) conn).getRemoteAddress(); int port = ((HttpInetConnection) conn).getRemotePort(); if (address != null) { targethost = new HttpHost(address.getHostName(), port); } } if (targethost == null) { if (ver.lessEquals(HttpVersion.HTTP_1_0)) { return; } else { throw new ProtocolException("Target host missing"); } } } request.addHeader(HTTP.TARGET_HOST, targethost.toHostString()); } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/RequestTargetHost.java
Java
gpl3
3,856
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.io.IOException; import org.apache.ogt.http.HttpEntity; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpResponse; import org.apache.ogt.http.HttpResponseInterceptor; import org.apache.ogt.http.HttpStatus; import org.apache.ogt.http.HttpVersion; import org.apache.ogt.http.ProtocolException; import org.apache.ogt.http.ProtocolVersion; /** * ResponseContent is the most important interceptor for outgoing responses. * It is responsible for delimiting content length by adding * <code>Content-Length</code> or <code>Transfer-Content</code> headers based * on the properties of the enclosed entity and the protocol version. * This interceptor is required for correct functioning of server side protocol * processors. * * @since 4.0 */ public class ResponseContent implements HttpResponseInterceptor { public ResponseContent() { super(); } public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { if (response == null) { throw new IllegalArgumentException("HTTP request may not be null"); } if (response.containsHeader(HTTP.TRANSFER_ENCODING)) { throw new ProtocolException("Transfer-encoding header already present"); } if (response.containsHeader(HTTP.CONTENT_LEN)) { throw new ProtocolException("Content-Length header already present"); } ProtocolVersion ver = response.getStatusLine().getProtocolVersion(); HttpEntity entity = response.getEntity(); if (entity != null) { long len = entity.getContentLength(); if (entity.isChunked() && !ver.lessEquals(HttpVersion.HTTP_1_0)) { response.addHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING); } else if (len >= 0) { response.addHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength())); } // Specify a content type if known if (entity.getContentType() != null && !response.containsHeader( HTTP.CONTENT_TYPE )) { response.addHeader(entity.getContentType()); } // Specify a content encoding if known if (entity.getContentEncoding() != null && !response.containsHeader( HTTP.CONTENT_ENCODING)) { response.addHeader(entity.getContentEncoding()); } } else { int status = response.getStatusLine().getStatusCode(); if (status != HttpStatus.SC_NO_CONTENT && status != HttpStatus.SC_NOT_MODIFIED && status != HttpStatus.SC_RESET_CONTENT) { response.addHeader(HTTP.CONTENT_LEN, "0"); } } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/ResponseContent.java
Java
gpl3
4,042
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.util.List; import org.apache.ogt.http.HttpResponseInterceptor; /** * Provides access to an ordered list of response interceptors. * Lists are expected to be built upfront and used read-only afterwards * for {@link HttpProcessor processing}. * * @since 4.0 */ public interface HttpResponseInterceptorList { /** * Appends a response interceptor to this list. * * @param interceptor the response interceptor to add */ void addResponseInterceptor(HttpResponseInterceptor interceptor); /** * Inserts a response interceptor at the specified index. * * @param interceptor the response interceptor to add * @param index the index to insert the interceptor at */ void addResponseInterceptor(HttpResponseInterceptor interceptor, int index); /** * Obtains the current size of this list. * * @return the number of response interceptors in this list */ int getResponseInterceptorCount(); /** * Obtains a response interceptor from this list. * * @param index the index of the interceptor to obtain, * 0 for first * * @return the interceptor at the given index, or * <code>null</code> if the index is out of range */ HttpResponseInterceptor getResponseInterceptor(int index); /** * Removes all response interceptors from this list. */ void clearResponseInterceptors(); /** * Removes all response interceptor of the specified class * * @param clazz the class of the instances to be removed. */ void removeResponseInterceptorByClass(Class clazz); /** * Sets the response interceptors in this list. * This list will be cleared and re-initialized to contain * all response interceptors from the argument list. * If the argument list includes elements that are not response * interceptors, the behavior is implementation dependent. * * @param list the list of response interceptors */ void setInterceptors(List list); }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/HttpResponseInterceptorList.java
Java
gpl3
3,321
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; /** * Thread-safe extension of the {@link BasicHttpContext}. * * @since 4.0 */ public class SyncBasicHttpContext extends BasicHttpContext { public SyncBasicHttpContext(final HttpContext parentContext) { super(parentContext); } public synchronized Object getAttribute(final String id) { return super.getAttribute(id); } public synchronized void setAttribute(final String id, final Object obj) { super.setAttribute(id, obj); } public synchronized Object removeAttribute(final String id) { return super.removeAttribute(id); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/SyncBasicHttpContext.java
Java
gpl3
1,822
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.io.IOException; import org.apache.ogt.http.HttpEntity; import org.apache.ogt.http.HttpEntityEnclosingRequest; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpRequest; import org.apache.ogt.http.HttpRequestInterceptor; import org.apache.ogt.http.HttpVersion; import org.apache.ogt.http.ProtocolException; import org.apache.ogt.http.ProtocolVersion; /** * RequestContent is the most important interceptor for outgoing requests. * It is responsible for delimiting content length by adding * <code>Content-Length</code> or <code>Transfer-Content</code> headers based * on the properties of the enclosed entity and the protocol version. * This interceptor is required for correct functioning of client side protocol * processors. * * @since 4.0 */ public class RequestContent implements HttpRequestInterceptor { public RequestContent() { super(); } public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (request == null) { throw new IllegalArgumentException("HTTP request may not be null"); } if (request instanceof HttpEntityEnclosingRequest) { if (request.containsHeader(HTTP.TRANSFER_ENCODING)) { throw new ProtocolException("Transfer-encoding header already present"); } if (request.containsHeader(HTTP.CONTENT_LEN)) { throw new ProtocolException("Content-Length header already present"); } ProtocolVersion ver = request.getRequestLine().getProtocolVersion(); HttpEntity entity = ((HttpEntityEnclosingRequest)request).getEntity(); if (entity == null) { request.addHeader(HTTP.CONTENT_LEN, "0"); return; } // Must specify a transfer encoding or a content length if (entity.isChunked() || entity.getContentLength() < 0) { if (ver.lessEquals(HttpVersion.HTTP_1_0)) { throw new ProtocolException( "Chunked transfer encoding not allowed for " + ver); } request.addHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING); } else { request.addHeader(HTTP.CONTENT_LEN, Long.toString(entity.getContentLength())); } // Specify a content type if known if (entity.getContentType() != null && !request.containsHeader( HTTP.CONTENT_TYPE )) { request.addHeader(entity.getContentType()); } // Specify a content encoding if known if (entity.getContentEncoding() != null && !request.containsHeader( HTTP.CONTENT_ENCODING)) { request.addHeader(entity.getContentEncoding()); } } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/RequestContent.java
Java
gpl3
4,134
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import java.util.HashMap; import java.util.Map; /** * Default implementation of {@link HttpContext}. * <p> * Please note methods of this class are not synchronized and therefore may * be threading unsafe. * * @since 4.0 */ public class BasicHttpContext implements HttpContext { private final HttpContext parentContext; private Map map = null; public BasicHttpContext() { this(null); } public BasicHttpContext(final HttpContext parentContext) { super(); this.parentContext = parentContext; } public Object getAttribute(final String id) { if (id == null) { throw new IllegalArgumentException("Id may not be null"); } Object obj = null; if (this.map != null) { obj = this.map.get(id); } if (obj == null && this.parentContext != null) { obj = this.parentContext.getAttribute(id); } return obj; } public void setAttribute(final String id, final Object obj) { if (id == null) { throw new IllegalArgumentException("Id may not be null"); } if (this.map == null) { this.map = new HashMap(); } this.map.put(id, obj); } public Object removeAttribute(final String id) { if (id == null) { throw new IllegalArgumentException("Id may not be null"); } if (this.map != null) { return this.map.remove(id); } else { return null; } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/BasicHttpContext.java
Java
gpl3
2,767
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.protocol; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpRequest; import org.apache.ogt.http.HttpResponse; /** * Defines an interface to verify whether an incoming HTTP request meets * the target server's expectations. *<p> * The Expect request-header field is used to indicate that particular * server behaviors are required by the client. *</p> *<pre> * Expect = "Expect" ":" 1#expectation * * expectation = "100-continue" | expectation-extension * expectation-extension = token [ "=" ( token | quoted-string ) * *expect-params ] * expect-params = ";" token [ "=" ( token | quoted-string ) ] *</pre> *<p> * A server that does not understand or is unable to comply with any of * the expectation values in the Expect field of a request MUST respond * with appropriate error status. The server MUST respond with a 417 * (Expectation Failed) status if any of the expectations cannot be met * or, if there are other problems with the request, some other 4xx * status. *</p> * * @since 4.0 */ public interface HttpExpectationVerifier { /** * Verifies whether the given request meets the server's expectations. * <p> * If the request fails to meet particular criteria, this method can * trigger a terminal response back to the client by setting the status * code of the response object to a value greater or equal to * <code>200</code>. In this case the client will not have to transmit * the request body. If the request meets expectations this method can * terminate without modifying the response object. Per default the status * code of the response object will be set to <code>100</code>. * * @param request the HTTP request. * @param response the HTTP response. * @param context the HTTP context. * @throws HttpException in case of an HTTP protocol violation. */ void verify(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException; }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/protocol/HttpExpectationVerifier.java
Java
gpl3
3,279
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http; /** * Constants enumerating the HTTP headers. All headers defined in RFC1945 (HTTP/1.0), RFC2616 (HTTP/1.1), and RFC2518 * (WebDAV) are listed. * * @since 4.1 */ public final class HttpHeaders { private HttpHeaders() { } /** RFC 2616 (HTTP/1.1) Section 14.1 */ public static final String ACCEPT = "Accept"; /** RFC 2616 (HTTP/1.1) Section 14.2 */ public static final String ACCEPT_CHARSET = "Accept-Charset"; /** RFC 2616 (HTTP/1.1) Section 14.3 */ public static final String ACCEPT_ENCODING = "Accept-Encoding"; /** RFC 2616 (HTTP/1.1) Section 14.4 */ public static final String ACCEPT_LANGUAGE = "Accept-Language"; /** RFC 2616 (HTTP/1.1) Section 14.5 */ public static final String ACCEPT_RANGES = "Accept-Ranges"; /** RFC 2616 (HTTP/1.1) Section 14.6 */ public static final String AGE = "Age"; /** RFC 1945 (HTTP/1.0) Section 10.1, RFC 2616 (HTTP/1.1) Section 14.7 */ public static final String ALLOW = "Allow"; /** RFC 1945 (HTTP/1.0) Section 10.2, RFC 2616 (HTTP/1.1) Section 14.8 */ public static final String AUTHORIZATION = "Authorization"; /** RFC 2616 (HTTP/1.1) Section 14.9 */ public static final String CACHE_CONTROL = "Cache-Control"; /** RFC 2616 (HTTP/1.1) Section 14.10 */ public static final String CONNECTION = "Connection"; /** RFC 1945 (HTTP/1.0) Section 10.3, RFC 2616 (HTTP/1.1) Section 14.11 */ public static final String CONTENT_ENCODING = "Content-Encoding"; /** RFC 2616 (HTTP/1.1) Section 14.12 */ public static final String CONTENT_LANGUAGE = "Content-Language"; /** RFC 1945 (HTTP/1.0) Section 10.4, RFC 2616 (HTTP/1.1) Section 14.13 */ public static final String CONTENT_LENGTH = "Content-Length"; /** RFC 2616 (HTTP/1.1) Section 14.14 */ public static final String CONTENT_LOCATION = "Content-Location"; /** RFC 2616 (HTTP/1.1) Section 14.15 */ public static final String CONTENT_MD5 = "Content-MD5"; /** RFC 2616 (HTTP/1.1) Section 14.16 */ public static final String CONTENT_RANGE = "Content-Range"; /** RFC 1945 (HTTP/1.0) Section 10.5, RFC 2616 (HTTP/1.1) Section 14.17 */ public static final String CONTENT_TYPE = "Content-Type"; /** RFC 1945 (HTTP/1.0) Section 10.6, RFC 2616 (HTTP/1.1) Section 14.18 */ public static final String DATE = "Date"; /** RFC 2518 (WevDAV) Section 9.1 */ public static final String DAV = "Dav"; /** RFC 2518 (WevDAV) Section 9.2 */ public static final String DEPTH = "Depth"; /** RFC 2518 (WevDAV) Section 9.3 */ public static final String DESTINATION = "Destination"; /** RFC 2616 (HTTP/1.1) Section 14.19 */ public static final String ETAG = "ETag"; /** RFC 2616 (HTTP/1.1) Section 14.20 */ public static final String EXPECT = "Expect"; /** RFC 1945 (HTTP/1.0) Section 10.7, RFC 2616 (HTTP/1.1) Section 14.21 */ public static final String EXPIRES = "Expires"; /** RFC 1945 (HTTP/1.0) Section 10.8, RFC 2616 (HTTP/1.1) Section 14.22 */ public static final String FROM = "From"; /** RFC 2616 (HTTP/1.1) Section 14.23 */ public static final String HOST = "Host"; /** RFC 2518 (WevDAV) Section 9.4 */ public static final String IF = "If"; /** RFC 2616 (HTTP/1.1) Section 14.24 */ public static final String IF_MATCH = "If-Match"; /** RFC 1945 (HTTP/1.0) Section 10.9, RFC 2616 (HTTP/1.1) Section 14.25 */ public static final String IF_MODIFIED_SINCE = "If-Modified-Since"; /** RFC 2616 (HTTP/1.1) Section 14.26 */ public static final String IF_NONE_MATCH = "If-None-Match"; /** RFC 2616 (HTTP/1.1) Section 14.27 */ public static final String IF_RANGE = "If-Range"; /** RFC 2616 (HTTP/1.1) Section 14.28 */ public static final String IF_UNMODIFIED_SINCE = "If-Unmodified-Since"; /** RFC 1945 (HTTP/1.0) Section 10.10, RFC 2616 (HTTP/1.1) Section 14.29 */ public static final String LAST_MODIFIED = "Last-Modified"; /** RFC 1945 (HTTP/1.0) Section 10.11, RFC 2616 (HTTP/1.1) Section 14.30 */ public static final String LOCATION = "Location"; /** RFC 2518 (WevDAV) Section 9.5 */ public static final String LOCK_TOKEN = "Lock-Token"; /** RFC 2616 (HTTP/1.1) Section 14.31 */ public static final String MAX_FORWARDS = "Max-Forwards"; /** RFC 2518 (WevDAV) Section 9.6 */ public static final String OVERWRITE = "Overwrite"; /** RFC 1945 (HTTP/1.0) Section 10.12, RFC 2616 (HTTP/1.1) Section 14.32 */ public static final String PRAGMA = "Pragma"; /** RFC 2616 (HTTP/1.1) Section 14.33 */ public static final String PROXY_AUTHENTICATE = "Proxy-Authenticate"; /** RFC 2616 (HTTP/1.1) Section 14.34 */ public static final String PROXY_AUTHORIZATION = "Proxy-Authorization"; /** RFC 2616 (HTTP/1.1) Section 14.35 */ public static final String RANGE = "Range"; /** RFC 1945 (HTTP/1.0) Section 10.13, RFC 2616 (HTTP/1.1) Section 14.36 */ public static final String REFERER = "Referer"; /** RFC 2616 (HTTP/1.1) Section 14.37 */ public static final String RETRY_AFTER = "Retry-After"; /** RFC 1945 (HTTP/1.0) Section 10.14, RFC 2616 (HTTP/1.1) Section 14.38 */ public static final String SERVER = "Server"; /** RFC 2518 (WevDAV) Section 9.7 */ public static final String STATUS_URI = "Status-URI"; /** RFC 2616 (HTTP/1.1) Section 14.39 */ public static final String TE = "TE"; /** RFC 2518 (WevDAV) Section 9.8 */ public static final String TIMEOUT = "Timeout"; /** RFC 2616 (HTTP/1.1) Section 14.40 */ public static final String TRAILER = "Trailer"; /** RFC 2616 (HTTP/1.1) Section 14.41 */ public static final String TRANSFER_ENCODING = "Transfer-Encoding"; /** RFC 2616 (HTTP/1.1) Section 14.42 */ public static final String UPGRADE = "Upgrade"; /** RFC 1945 (HTTP/1.0) Section 10.15, RFC 2616 (HTTP/1.1) Section 14.43 */ public static final String USER_AGENT = "User-Agent"; /** RFC 2616 (HTTP/1.1) Section 14.44 */ public static final String VARY = "Vary"; /** RFC 2616 (HTTP/1.1) Section 14.45 */ public static final String VIA = "Via"; /** RFC 2616 (HTTP/1.1) Section 14.46 */ public static final String WARNING = "Warning"; /** RFC 1945 (HTTP/1.0) Section 10.16, RFC 2616 (HTTP/1.1) Section 14.47 */ public static final String WWW_AUTHENTICATE = "WWW-Authenticate"; }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/HttpHeaders.java
Java
gpl3
7,651
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.impl; import java.io.IOException; import java.net.Socket; import org.apache.ogt.http.params.HttpConnectionParams; import org.apache.ogt.http.params.HttpParams; /** * Default implementation of a server-side HTTP connection. * <p> * The following parameters can be used to customize the behavior of this * class: * <ul> * <li>{@link org.apache.ogt.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#TCP_NODELAY}</li> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#SO_TIMEOUT}</li> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#SO_LINGER}</li> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li> * </ul> * * @since 4.0 */ public class DefaultHttpServerConnection extends SocketHttpServerConnection { public DefaultHttpServerConnection() { super(); } public void bind(final Socket socket, final HttpParams params) throws IOException { if (socket == null) { throw new IllegalArgumentException("Socket may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } assertNotOpen(); socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params)); socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params)); int linger = HttpConnectionParams.getLinger(params); if (linger >= 0) { socket.setSoLinger(linger > 0, linger); } super.bind(socket, params); } public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("["); if (isOpen()) { buffer.append(getRemotePort()); } else { buffer.append("closed"); } buffer.append("]"); return buffer.toString(); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/impl/DefaultHttpServerConnection.java
Java
gpl3
3,218
<html> <head> <!-- /* * ==================================================================== * 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 * <http://www.apache.org/>. * */ --> </head> <body> Default implementations for interfaces in {@link org.apache.ogt.http org.apache.ogt.http}. </body> </html>
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/impl/package.html
HTML
gpl3
1,330
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.impl; import java.io.IOException; import java.net.Socket; import org.apache.ogt.http.params.HttpConnectionParams; import org.apache.ogt.http.params.HttpParams; /** * Default implementation of a client-side HTTP connection. * <p> * The following parameters can be used to customize the behavior of this * class: * <ul> * <li>{@link org.apache.ogt.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#TCP_NODELAY}</li> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#SO_TIMEOUT}</li> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#SO_LINGER}</li> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#SOCKET_BUFFER_SIZE}</li> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li> * </ul> * * @since 4.0 */ public class DefaultHttpClientConnection extends SocketHttpClientConnection { public DefaultHttpClientConnection() { super(); } public void bind( final Socket socket, final HttpParams params) throws IOException { if (socket == null) { throw new IllegalArgumentException("Socket may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } assertNotOpen(); socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params)); socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params)); int linger = HttpConnectionParams.getLinger(params); if (linger >= 0) { socket.setSoLinger(linger > 0, linger); } super.bind(socket, params); } public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("["); if (isOpen()) { buffer.append(getRemotePort()); } else { buffer.append("closed"); } buffer.append("]"); return buffer.toString(); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/impl/DefaultHttpClientConnection.java
Java
gpl3
3,243
<html> <head> <!-- /* * ==================================================================== * 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 * <http://www.apache.org/>. * */ --> </head> <body> Default implementations for interfaces in {@link org.apache.ogt.http.io org.apache.ogt.http.io}. <br/> There are implementations of the transport encodings used by HTTP, in particular the chunked coding for {@link org.apache.ogt.http.impl.io.ChunkedOutputStream sending} and {@link org.apache.ogt.http.impl.io.ChunkedInputStream receiving} entities. </body> </html>
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/impl/io/package.html
HTML
gpl3
1,591
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.impl.io; import java.io.IOException; import java.io.OutputStream; import org.apache.ogt.http.io.SessionOutputBuffer; /** * Output stream that cuts off after a defined number of bytes. This class * is used to send content of HTTP messages where the end of the content entity * is determined by the value of the <code>Content-Length header</code>. * Entities transferred using this stream can be maximum {@link Long#MAX_VALUE} * long. * <p> * Note that this class NEVER closes the underlying stream, even when close * gets called. Instead, the stream will be marked as closed and no further * output will be permitted. * * @since 4.0 */ public class ContentLengthOutputStream extends OutputStream { /** * Wrapped session output buffer. */ private final SessionOutputBuffer out; /** * The maximum number of bytes that can be written the stream. Subsequent * write operations will be ignored. */ private final long contentLength; /** Total bytes written */ private long total = 0; /** True if the stream is closed. */ private boolean closed = false; /** * Wraps a session output buffer and cuts off output after a defined number * of bytes. * * @param out The session output buffer * @param contentLength The maximum number of bytes that can be written to * the stream. Subsequent write operations will be ignored. * * @since 4.0 */ public ContentLengthOutputStream(final SessionOutputBuffer out, long contentLength) { super(); if (out == null) { throw new IllegalArgumentException("Session output buffer may not be null"); } if (contentLength < 0) { throw new IllegalArgumentException("Content length may not be negative"); } this.out = out; this.contentLength = contentLength; } /** * <p>Does not close the underlying socket output.</p> * * @throws IOException If an I/O problem occurs. */ public void close() throws IOException { if (!this.closed) { this.closed = true; this.out.flush(); } } public void flush() throws IOException { this.out.flush(); } public void write(byte[] b, int off, int len) throws IOException { if (this.closed) { throw new IOException("Attempted write to closed stream."); } if (this.total < this.contentLength) { long max = this.contentLength - this.total; if (len > max) { len = (int) max; } this.out.write(b, off, len); this.total += len; } } public void write(byte[] b) throws IOException { write(b, 0, b.length); } public void write(int b) throws IOException { if (this.closed) { throw new IOException("Attempted write to closed stream."); } if (this.total < this.contentLength) { this.out.write(b); this.total++; } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/impl/io/ContentLengthOutputStream.java
Java
gpl3
4,292
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.impl.io; import java.io.IOException; import java.io.InputStream; import org.apache.ogt.http.io.BufferInfo; import org.apache.ogt.http.io.SessionInputBuffer; /** * Input stream that reads data without any transformation. The end of the * content entity is demarcated by closing the underlying connection * (EOF condition). Entities transferred using this input stream can be of * unlimited length. * <p> * Note that this class NEVER closes the underlying stream, even when close * gets called. Instead, it will read until the end of the stream (until * <code>-1</code> is returned). * * @since 4.0 */ public class IdentityInputStream extends InputStream { private final SessionInputBuffer in; private boolean closed = false; /** * Wraps session input stream and reads input until the the end of stream. * * @param in The session input buffer */ public IdentityInputStream(final SessionInputBuffer in) { super(); if (in == null) { throw new IllegalArgumentException("Session input buffer may not be null"); } this.in = in; } public int available() throws IOException { if (this.in instanceof BufferInfo) { return ((BufferInfo) this.in).length(); } else { return 0; } } public void close() throws IOException { this.closed = true; } public int read() throws IOException { if (this.closed) { return -1; } else { return this.in.read(); } } public int read(final byte[] b, int off, int len) throws IOException { if (this.closed) { return -1; } else { return this.in.read(b, off, len); } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/impl/io/IdentityInputStream.java
Java
gpl3
2,989
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.impl.io; import java.io.IOException; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpMessage; import org.apache.ogt.http.HttpResponse; import org.apache.ogt.http.HttpResponseFactory; import org.apache.ogt.http.NoHttpResponseException; import org.apache.ogt.http.ParseException; import org.apache.ogt.http.StatusLine; import org.apache.ogt.http.io.SessionInputBuffer; import org.apache.ogt.http.message.LineParser; import org.apache.ogt.http.message.ParserCursor; import org.apache.ogt.http.params.HttpParams; import org.apache.ogt.http.util.CharArrayBuffer; /** * HTTP response parser that obtain its input from an instance * of {@link SessionInputBuffer}. * <p> * The following parameters can be used to customize the behavior of this * class: * <ul> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li> * </ul> * * @since 4.0 */ public class HttpResponseParser extends AbstractMessageParser { private final HttpResponseFactory responseFactory; private final CharArrayBuffer lineBuf; /** * Creates an instance of this class. * * @param buffer the session input buffer. * @param parser the line parser. * @param responseFactory the factory to use to create * {@link HttpResponse}s. * @param params HTTP parameters. */ public HttpResponseParser( final SessionInputBuffer buffer, final LineParser parser, final HttpResponseFactory responseFactory, final HttpParams params) { super(buffer, parser, params); if (responseFactory == null) { throw new IllegalArgumentException("Response factory may not be null"); } this.responseFactory = responseFactory; this.lineBuf = new CharArrayBuffer(128); } protected HttpMessage parseHead( final SessionInputBuffer sessionBuffer) throws IOException, HttpException, ParseException { this.lineBuf.clear(); int i = sessionBuffer.readLine(this.lineBuf); if (i == -1) { throw new NoHttpResponseException("The target server failed to respond"); } //create the status line from the status string ParserCursor cursor = new ParserCursor(0, this.lineBuf.length()); StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor); return this.responseFactory.newHttpResponse(statusline, null); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/impl/io/HttpResponseParser.java
Java
gpl3
3,772
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.impl.io; import java.io.IOException; import java.util.Iterator; import org.apache.ogt.http.Header; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpMessage; import org.apache.ogt.http.io.HttpMessageWriter; import org.apache.ogt.http.io.SessionOutputBuffer; import org.apache.ogt.http.message.BasicLineFormatter; import org.apache.ogt.http.message.LineFormatter; import org.apache.ogt.http.params.HttpParams; import org.apache.ogt.http.util.CharArrayBuffer; /** * Abstract base class for HTTP message writers that serialize output to * an instance of {@link SessionOutputBuffer}. * * @since 4.0 */ public abstract class AbstractMessageWriter implements HttpMessageWriter { protected final SessionOutputBuffer sessionBuffer; protected final CharArrayBuffer lineBuf; protected final LineFormatter lineFormatter; /** * Creates an instance of AbstractMessageWriter. * * @param buffer the session output buffer. * @param formatter the line formatter. * @param params HTTP parameters. */ public AbstractMessageWriter(final SessionOutputBuffer buffer, final LineFormatter formatter, final HttpParams params) { super(); if (buffer == null) { throw new IllegalArgumentException("Session input buffer may not be null"); } this.sessionBuffer = buffer; this.lineBuf = new CharArrayBuffer(128); this.lineFormatter = (formatter != null) ? formatter : BasicLineFormatter.DEFAULT; } /** * Subclasses must override this method to write out the first header line * based on the {@link HttpMessage} passed as a parameter. * * @param message the message whose first line is to be written out. * @throws IOException in case of an I/O error. */ protected abstract void writeHeadLine(HttpMessage message) throws IOException; public void write( final HttpMessage message) throws IOException, HttpException { if (message == null) { throw new IllegalArgumentException("HTTP message may not be null"); } writeHeadLine(message); for (Iterator it = message.headerIterator(); it.hasNext(); ) { Header header = (Header) it.next(); this.sessionBuffer.writeLine (lineFormatter.formatHeader(this.lineBuf, header)); } this.lineBuf.clear(); this.sessionBuffer.writeLine(this.lineBuf); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/impl/io/AbstractMessageWriter.java
Java
gpl3
3,760
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.impl.io; import java.io.IOException; import java.io.InputStream; import org.apache.ogt.http.io.BufferInfo; import org.apache.ogt.http.io.HttpTransportMetrics; import org.apache.ogt.http.io.SessionInputBuffer; import org.apache.ogt.http.params.CoreConnectionPNames; import org.apache.ogt.http.params.HttpParams; import org.apache.ogt.http.params.HttpProtocolParams; import org.apache.ogt.http.protocol.HTTP; import org.apache.ogt.http.util.ByteArrayBuffer; import org.apache.ogt.http.util.CharArrayBuffer; /** * Abstract base class for session input buffers that stream data from * an arbitrary {@link InputStream}. This class buffers input data in * an internal byte array for optimal input performance. * <p> * {@link #readLine(CharArrayBuffer)} and {@link #readLine()} methods of this * class treat a lone LF as valid line delimiters in addition to CR-LF required * by the HTTP specification. * * <p> * The following parameters can be used to customize the behavior of this * class: * <ul> * <li>{@link org.apache.ogt.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#MIN_CHUNK_LIMIT}</li> * </ul> * @since 4.0 */ public abstract class AbstractSessionInputBuffer implements SessionInputBuffer, BufferInfo { private InputStream instream; private byte[] buffer; private int bufferpos; private int bufferlen; private ByteArrayBuffer linebuffer = null; private String charset = HTTP.US_ASCII; private boolean ascii = true; private int maxLineLen = -1; private int minChunkLimit = 512; private HttpTransportMetricsImpl metrics; /** * Initializes this session input buffer. * * @param instream the source input stream. * @param buffersize the size of the internal buffer. * @param params HTTP parameters. */ protected void init(final InputStream instream, int buffersize, final HttpParams params) { if (instream == null) { throw new IllegalArgumentException("Input stream may not be null"); } if (buffersize <= 0) { throw new IllegalArgumentException("Buffer size may not be negative or zero"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } this.instream = instream; this.buffer = new byte[buffersize]; this.bufferpos = 0; this.bufferlen = 0; this.linebuffer = new ByteArrayBuffer(buffersize); this.charset = HttpProtocolParams.getHttpElementCharset(params); this.ascii = this.charset.equalsIgnoreCase(HTTP.US_ASCII) || this.charset.equalsIgnoreCase(HTTP.ASCII); this.maxLineLen = params.getIntParameter(CoreConnectionPNames.MAX_LINE_LENGTH, -1); this.minChunkLimit = params.getIntParameter(CoreConnectionPNames.MIN_CHUNK_LIMIT, 512); this.metrics = createTransportMetrics(); } /** * @since 4.1 */ protected HttpTransportMetricsImpl createTransportMetrics() { return new HttpTransportMetricsImpl(); } /** * @since 4.1 */ public int capacity() { return this.buffer.length; } /** * @since 4.1 */ public int length() { return this.bufferlen - this.bufferpos; } /** * @since 4.1 */ public int available() { return capacity() - length(); } protected int fillBuffer() throws IOException { // compact the buffer if necessary if (this.bufferpos > 0) { int len = this.bufferlen - this.bufferpos; if (len > 0) { System.arraycopy(this.buffer, this.bufferpos, this.buffer, 0, len); } this.bufferpos = 0; this.bufferlen = len; } int l; int off = this.bufferlen; int len = this.buffer.length - off; l = this.instream.read(this.buffer, off, len); if (l == -1) { return -1; } else { this.bufferlen = off + l; this.metrics.incrementBytesTransferred(l); return l; } } protected boolean hasBufferedData() { return this.bufferpos < this.bufferlen; } public int read() throws IOException { int noRead = 0; while (!hasBufferedData()) { noRead = fillBuffer(); if (noRead == -1) { return -1; } } return this.buffer[this.bufferpos++] & 0xff; } public int read(final byte[] b, int off, int len) throws IOException { if (b == null) { return 0; } if (hasBufferedData()) { int chunk = Math.min(len, this.bufferlen - this.bufferpos); System.arraycopy(this.buffer, this.bufferpos, b, off, chunk); this.bufferpos += chunk; return chunk; } // If the remaining capacity is big enough, read directly from the // underlying input stream bypassing the buffer. if (len > this.minChunkLimit) { int read = this.instream.read(b, off, len); if (read > 0) { this.metrics.incrementBytesTransferred(read); } return read; } else { // otherwise read to the buffer first while (!hasBufferedData()) { int noRead = fillBuffer(); if (noRead == -1) { return -1; } } int chunk = Math.min(len, this.bufferlen - this.bufferpos); System.arraycopy(this.buffer, this.bufferpos, b, off, chunk); this.bufferpos += chunk; return chunk; } } public int read(final byte[] b) throws IOException { if (b == null) { return 0; } return read(b, 0, b.length); } private int locateLF() { for (int i = this.bufferpos; i < this.bufferlen; i++) { if (this.buffer[i] == HTTP.LF) { return i; } } return -1; } /** * Reads a complete line of characters up to a line delimiter from this * session buffer into the given line buffer. The number of chars actually * read is returned as an integer. The line delimiter itself is discarded. * If no char is available because the end of the stream has been reached, * the value <code>-1</code> is returned. This method blocks until input * data is available, end of file is detected, or an exception is thrown. * <p> * This method treats a lone LF as a valid line delimiters in addition * to CR-LF required by the HTTP specification. * * @param charbuffer the line buffer. * @return one line of characters * @exception IOException if an I/O error occurs. */ public int readLine(final CharArrayBuffer charbuffer) throws IOException { if (charbuffer == null) { throw new IllegalArgumentException("Char array buffer may not be null"); } int noRead = 0; boolean retry = true; while (retry) { // attempt to find end of line (LF) int i = locateLF(); if (i != -1) { // end of line found. if (this.linebuffer.isEmpty()) { // the entire line is preset in the read buffer return lineFromReadBuffer(charbuffer, i); } retry = false; int len = i + 1 - this.bufferpos; this.linebuffer.append(this.buffer, this.bufferpos, len); this.bufferpos = i + 1; } else { // end of line not found if (hasBufferedData()) { int len = this.bufferlen - this.bufferpos; this.linebuffer.append(this.buffer, this.bufferpos, len); this.bufferpos = this.bufferlen; } noRead = fillBuffer(); if (noRead == -1) { retry = false; } } if (this.maxLineLen > 0 && this.linebuffer.length() >= this.maxLineLen) { throw new IOException("Maximum line length limit exceeded"); } } if (noRead == -1 && this.linebuffer.isEmpty()) { // indicate the end of stream return -1; } return lineFromLineBuffer(charbuffer); } /** * Reads a complete line of characters up to a line delimiter from this * session buffer. The line delimiter itself is discarded. If no char is * available because the end of the stream has been reached, * <code>null</code> is returned. This method blocks until input data is * available, end of file is detected, or an exception is thrown. * <p> * This method treats a lone LF as a valid line delimiters in addition * to CR-LF required by the HTTP specification. * * @return HTTP line as a string * @exception IOException if an I/O error occurs. */ private int lineFromLineBuffer(final CharArrayBuffer charbuffer) throws IOException { // discard LF if found int l = this.linebuffer.length(); if (l > 0) { if (this.linebuffer.byteAt(l - 1) == HTTP.LF) { l--; this.linebuffer.setLength(l); } // discard CR if found if (l > 0) { if (this.linebuffer.byteAt(l - 1) == HTTP.CR) { l--; this.linebuffer.setLength(l); } } } l = this.linebuffer.length(); if (this.ascii) { charbuffer.append(this.linebuffer, 0, l); } else { // This is VERY memory inefficient, BUT since non-ASCII charsets are // NOT meant to be used anyway, there's no point optimizing it String s = new String(this.linebuffer.buffer(), 0, l, this.charset); l = s.length(); charbuffer.append(s); } this.linebuffer.clear(); return l; } private int lineFromReadBuffer(final CharArrayBuffer charbuffer, int pos) throws IOException { int off = this.bufferpos; int len; this.bufferpos = pos + 1; if (pos > 0 && this.buffer[pos - 1] == HTTP.CR) { // skip CR if found pos--; } len = pos - off; if (this.ascii) { charbuffer.append(this.buffer, off, len); } else { // This is VERY memory inefficient, BUT since non-ASCII charsets are // NOT meant to be used anyway, there's no point optimizing it String s = new String(this.buffer, off, len, this.charset); charbuffer.append(s); len = s.length(); } return len; } public String readLine() throws IOException { CharArrayBuffer charbuffer = new CharArrayBuffer(64); int l = readLine(charbuffer); if (l != -1) { return charbuffer.toString(); } else { return null; } } public HttpTransportMetrics getMetrics() { return this.metrics; } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/impl/io/AbstractSessionInputBuffer.java
Java
gpl3
12,717
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.impl.io; import java.io.IOException; import java.io.OutputStream; import org.apache.ogt.http.io.SessionOutputBuffer; /** * Implements chunked transfer coding. The content is sent in small chunks. * Entities transferred using this output stream can be of unlimited length. * Writes are buffered to an internal buffer (2048 default size). * <p> * Note that this class NEVER closes the underlying stream, even when close * gets called. Instead, the stream will be marked as closed and no further * output will be permitted. * * * @since 4.0 */ public class ChunkedOutputStream extends OutputStream { // ----------------------------------------------------- Instance Variables private final SessionOutputBuffer out; private byte[] cache; private int cachePosition = 0; private boolean wroteLastChunk = false; /** True if the stream is closed. */ private boolean closed = false; // ----------------------------------------------------------- Constructors /** * Wraps a session output buffer and chunk-encodes the output. * * @param out The session output buffer * @param bufferSize The minimum chunk size (excluding last chunk) * @throws IOException in case of an I/O error */ public ChunkedOutputStream(final SessionOutputBuffer out, int bufferSize) throws IOException { super(); this.cache = new byte[bufferSize]; this.out = out; } /** * Wraps a session output buffer and chunks the output. The default buffer * size of 2048 was chosen because the chunk overhead is less than 0.5% * * @param out the output buffer to wrap * @throws IOException in case of an I/O error */ public ChunkedOutputStream(final SessionOutputBuffer out) throws IOException { this(out, 2048); } // ----------------------------------------------------------- Internal methods /** * Writes the cache out onto the underlying stream */ protected void flushCache() throws IOException { if (this.cachePosition > 0) { this.out.writeLine(Integer.toHexString(this.cachePosition)); this.out.write(this.cache, 0, this.cachePosition); this.out.writeLine(""); this.cachePosition = 0; } } /** * Writes the cache and bufferToAppend to the underlying stream * as one large chunk */ protected void flushCacheWithAppend(byte bufferToAppend[], int off, int len) throws IOException { this.out.writeLine(Integer.toHexString(this.cachePosition + len)); this.out.write(this.cache, 0, this.cachePosition); this.out.write(bufferToAppend, off, len); this.out.writeLine(""); this.cachePosition = 0; } protected void writeClosingChunk() throws IOException { // Write the final chunk. this.out.writeLine("0"); this.out.writeLine(""); } // ----------------------------------------------------------- Public Methods /** * Must be called to ensure the internal cache is flushed and the closing * chunk is written. * @throws IOException in case of an I/O error */ public void finish() throws IOException { if (!this.wroteLastChunk) { flushCache(); writeClosingChunk(); this.wroteLastChunk = true; } } // -------------------------------------------- OutputStream Methods public void write(int b) throws IOException { if (this.closed) { throw new IOException("Attempted write to closed stream."); } this.cache[this.cachePosition] = (byte) b; this.cachePosition++; if (this.cachePosition == this.cache.length) flushCache(); } /** * Writes the array. If the array does not fit within the buffer, it is * not split, but rather written out as one large chunk. */ public void write(byte b[]) throws IOException { write(b, 0, b.length); } /** * Writes the array. If the array does not fit within the buffer, it is * not split, but rather written out as one large chunk. */ public void write(byte src[], int off, int len) throws IOException { if (this.closed) { throw new IOException("Attempted write to closed stream."); } if (len >= this.cache.length - this.cachePosition) { flushCacheWithAppend(src, off, len); } else { System.arraycopy(src, off, cache, this.cachePosition, len); this.cachePosition += len; } } /** * Flushes the content buffer and the underlying stream. */ public void flush() throws IOException { flushCache(); this.out.flush(); } /** * Finishes writing to the underlying stream, but does NOT close the underlying stream. */ public void close() throws IOException { if (!this.closed) { this.closed = true; finish(); this.out.flush(); } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/impl/io/ChunkedOutputStream.java
Java
gpl3
6,315
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.impl.io; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.ogt.http.Header; import org.apache.ogt.http.HttpException; import org.apache.ogt.http.HttpMessage; import org.apache.ogt.http.ParseException; import org.apache.ogt.http.ProtocolException; import org.apache.ogt.http.io.HttpMessageParser; import org.apache.ogt.http.io.SessionInputBuffer; import org.apache.ogt.http.message.BasicLineParser; import org.apache.ogt.http.message.LineParser; import org.apache.ogt.http.params.CoreConnectionPNames; import org.apache.ogt.http.params.HttpParams; import org.apache.ogt.http.util.CharArrayBuffer; /** * Abstract base class for HTTP message parsers that obtain input from * an instance of {@link SessionInputBuffer}. * <p> * The following parameters can be used to customize the behavior of this * class: * <ul> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#MAX_HEADER_COUNT}</li> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li> * </ul> * * @since 4.0 */ public abstract class AbstractMessageParser implements HttpMessageParser { private static final int HEAD_LINE = 0; private static final int HEADERS = 1; private final SessionInputBuffer sessionBuffer; private final int maxHeaderCount; private final int maxLineLen; private final List headerLines; protected final LineParser lineParser; private int state; private HttpMessage message; /** * Creates an instance of this class. * * @param buffer the session input buffer. * @param parser the line parser. * @param params HTTP parameters. */ public AbstractMessageParser( final SessionInputBuffer buffer, final LineParser parser, final HttpParams params) { super(); if (buffer == null) { throw new IllegalArgumentException("Session input buffer may not be null"); } if (params == null) { throw new IllegalArgumentException("HTTP parameters may not be null"); } this.sessionBuffer = buffer; this.maxHeaderCount = params.getIntParameter( CoreConnectionPNames.MAX_HEADER_COUNT, -1); this.maxLineLen = params.getIntParameter( CoreConnectionPNames.MAX_LINE_LENGTH, -1); this.lineParser = (parser != null) ? parser : BasicLineParser.DEFAULT; this.headerLines = new ArrayList(); this.state = HEAD_LINE; } /** * Parses HTTP headers from the data receiver stream according to the generic * format as given in Section 3.1 of RFC 822, RFC-2616 Section 4 and 19.3. * * @param inbuffer Session input buffer * @param maxHeaderCount maximum number of headers allowed. If the number * of headers received from the data stream exceeds maxCount value, an * IOException will be thrown. Setting this parameter to a negative value * or zero will disable the check. * @param maxLineLen maximum number of characters for a header line, * including the continuation lines. Setting this parameter to a negative * value or zero will disable the check. * @return array of HTTP headers * @param parser line parser to use. Can be <code>null</code>, in which case * the default implementation of this interface will be used. * * @throws IOException in case of an I/O error * @throws HttpException in case of HTTP protocol violation */ public static Header[] parseHeaders( final SessionInputBuffer inbuffer, int maxHeaderCount, int maxLineLen, LineParser parser) throws HttpException, IOException { if (parser == null) { parser = BasicLineParser.DEFAULT; } List headerLines = new ArrayList(); return parseHeaders(inbuffer, maxHeaderCount, maxLineLen, parser, headerLines); } /** * Parses HTTP headers from the data receiver stream according to the generic * format as given in Section 3.1 of RFC 822, RFC-2616 Section 4 and 19.3. * * @param inbuffer Session input buffer * @param maxHeaderCount maximum number of headers allowed. If the number * of headers received from the data stream exceeds maxCount value, an * IOException will be thrown. Setting this parameter to a negative value * or zero will disable the check. * @param maxLineLen maximum number of characters for a header line, * including the continuation lines. Setting this parameter to a negative * value or zero will disable the check. * @param parser line parser to use. * @param headerLines List of header lines. This list will be used to store * intermediate results. This makes it possible to resume parsing of * headers in case of a {@link java.io.InterruptedIOException}. * * @return array of HTTP headers * * @throws IOException in case of an I/O error * @throws HttpException in case of HTTP protocol violation * * @since 4.1 */ public static Header[] parseHeaders( final SessionInputBuffer inbuffer, int maxHeaderCount, int maxLineLen, final LineParser parser, final List headerLines) throws HttpException, IOException { if (inbuffer == null) { throw new IllegalArgumentException("Session input buffer may not be null"); } if (parser == null) { throw new IllegalArgumentException("Line parser may not be null"); } if (headerLines == null) { throw new IllegalArgumentException("Header line list may not be null"); } CharArrayBuffer current = null; CharArrayBuffer previous = null; for (;;) { if (current == null) { current = new CharArrayBuffer(64); } else { current.clear(); } int l = inbuffer.readLine(current); if (l == -1 || current.length() < 1) { break; } // Parse the header name and value // Check for folded headers first // Detect LWS-char see HTTP/1.0 or HTTP/1.1 Section 2.2 // discussion on folded headers if ((current.charAt(0) == ' ' || current.charAt(0) == '\t') && previous != null) { // we have continuation folded header // so append value int i = 0; while (i < current.length()) { char ch = current.charAt(i); if (ch != ' ' && ch != '\t') { break; } i++; } if (maxLineLen > 0 && previous.length() + 1 + current.length() - i > maxLineLen) { throw new IOException("Maximum line length limit exceeded"); } previous.append(' '); previous.append(current, i, current.length() - i); } else { headerLines.add(current); previous = current; current = null; } if (maxHeaderCount > 0 && headerLines.size() >= maxHeaderCount) { throw new IOException("Maximum header count exceeded"); } } Header[] headers = new Header[headerLines.size()]; for (int i = 0; i < headerLines.size(); i++) { CharArrayBuffer buffer = (CharArrayBuffer) headerLines.get(i); try { headers[i] = parser.parseHeader(buffer); } catch (ParseException ex) { throw new ProtocolException(ex.getMessage()); } } return headers; } /** * Subclasses must override this method to generate an instance of * {@link HttpMessage} based on the initial input from the session buffer. * <p> * Usually this method is expected to read just the very first line or * the very first valid from the data stream and based on the input generate * an appropriate instance of {@link HttpMessage}. * * @param sessionBuffer the session input buffer. * @return HTTP message based on the input from the session buffer. * @throws IOException in case of an I/O error. * @throws HttpException in case of HTTP protocol violation. * @throws ParseException in case of a parse error. */ protected abstract HttpMessage parseHead(SessionInputBuffer sessionBuffer) throws IOException, HttpException, ParseException; public HttpMessage parse() throws IOException, HttpException { int st = this.state; switch (st) { case HEAD_LINE: try { this.message = parseHead(this.sessionBuffer); } catch (ParseException px) { throw new ProtocolException(px.getMessage(), px); } this.state = HEADERS; //$FALL-THROUGH$ case HEADERS: Header[] headers = AbstractMessageParser.parseHeaders( this.sessionBuffer, this.maxHeaderCount, this.maxLineLen, this.lineParser, this.headerLines); this.message.setHeaders(headers); HttpMessage result = this.message; this.message = null; this.headerLines.clear(); this.state = HEAD_LINE; return result; default: throw new IllegalStateException("Inconsistent parser state"); } } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/impl/io/AbstractMessageParser.java
Java
gpl3
10,978
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.impl.io; import java.io.IOException; import java.io.InterruptedIOException; import java.net.Socket; import org.apache.ogt.http.io.EofSensor; import org.apache.ogt.http.io.SessionInputBuffer; import org.apache.ogt.http.params.HttpParams; /** * {@link SessionInputBuffer} implementation bound to a {@link Socket}. * <p> * The following parameters can be used to customize the behavior of this * class: * <ul> * <li>{@link org.apache.ogt.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li> * <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#MAX_LINE_LENGTH}</li> * </ul> * * @since 4.0 */ public class SocketInputBuffer extends AbstractSessionInputBuffer implements EofSensor { static private final Class SOCKET_TIMEOUT_CLASS = SocketTimeoutExceptionClass(); /** * Returns <code>SocketTimeoutExceptionClass<code> or <code>null</code> if the class * does not exist. * * @return <code>SocketTimeoutExceptionClass<code>, or <code>null</code> if unavailable. */ static private Class SocketTimeoutExceptionClass() { try { return Class.forName("java.net.SocketTimeoutException"); } catch (ClassNotFoundException e) { return null; } } private static boolean isSocketTimeoutException(final InterruptedIOException e) { if (SOCKET_TIMEOUT_CLASS != null) { return SOCKET_TIMEOUT_CLASS.isInstance(e); } else { return true; } } private final Socket socket; private boolean eof; /** * Creates an instance of this class. * * @param socket the socket to read data from. * @param buffersize the size of the internal buffer. If this number is less * than <code>0</code> it is set to the value of * {@link Socket#getReceiveBufferSize()}. If resultant number is less * than <code>1024</code> it is set to <code>1024</code>. * @param params HTTP parameters. */ public SocketInputBuffer( final Socket socket, int buffersize, final HttpParams params) throws IOException { super(); if (socket == null) { throw new IllegalArgumentException("Socket may not be null"); } this.socket = socket; this.eof = false; if (buffersize < 0) { buffersize = socket.getReceiveBufferSize(); } if (buffersize < 1024) { buffersize = 1024; } init(socket.getInputStream(), buffersize, params); } protected int fillBuffer() throws IOException { int i = super.fillBuffer(); this.eof = i == -1; return i; } public boolean isDataAvailable(int timeout) throws IOException { boolean result = hasBufferedData(); if (!result) { int oldtimeout = this.socket.getSoTimeout(); try { this.socket.setSoTimeout(timeout); fillBuffer(); result = hasBufferedData(); } catch (InterruptedIOException e) { if (!isSocketTimeoutException(e)) { throw e; } } finally { socket.setSoTimeout(oldtimeout); } } return result; } public boolean isEof() { return this.eof; } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/impl/io/SocketInputBuffer.java
Java
gpl3
4,583
/* * ==================================================================== * 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 * <http://www.apache.org/>. * */ package org.apache.ogt.http.impl.io; import java.io.IOException; import java.net.Socket; import org.apache.ogt.http.io.SessionOutputBuffer; import org.apache.ogt.http.params.HttpParams; /** * {@link SessionOutputBuffer} implementation bound to a {@link Socket}. * <p> * The following parameters can be used to customize the behavior of this * class: * <ul> * <li>{@link org.apache.ogt.http.params.CoreProtocolPNames#HTTP_ELEMENT_CHARSET}</li> * </ul> * * @since 4.0 */ public class SocketOutputBuffer extends AbstractSessionOutputBuffer { /** * Creates an instance of this class. * * @param socket the socket to write data to. * @param buffersize the size of the internal buffer. If this number is less * than <code>0</code> it is set to the value of * {@link Socket#getSendBufferSize()}. If resultant number is less * than <code>1024</code> it is set to <code>1024</code>. * @param params HTTP parameters. */ public SocketOutputBuffer( final Socket socket, int buffersize, final HttpParams params) throws IOException { super(); if (socket == null) { throw new IllegalArgumentException("Socket may not be null"); } if (buffersize < 0) { buffersize = socket.getSendBufferSize(); } if (buffersize < 1024) { buffersize = 1024; } init(socket.getOutputStream(), buffersize, params); } }
zzy157-running
OpenGPSTracker/external_sources/httpcore-4.1.1/httpcore/src/main/java/org/apache/ogt/http/impl/io/SocketOutputBuffer.java
Java
gpl3
2,682