📄 curlresource.java
字号:
/* * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty * of NON-INFRINGEMENT. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the * * Free Software Foundation, Inc. * 59 Temple Place, Suite 330 * Boston, MA 02111-1307 USA * * @author Nam Nguyen */package com.caucho.quercus.lib.curl;import com.caucho.quercus.QuercusModuleException;import com.caucho.quercus.env.*;import com.caucho.quercus.lib.file.BinaryInput;import com.caucho.quercus.lib.file.BinaryOutput;import com.caucho.quercus.lib.file.FileModule;import com.caucho.util.L10N;import com.caucho.vfs.Path;import com.caucho.vfs.WriteStream;import java.io.IOException;import java.net.HttpURLConnection;import java.util.HashMap;import java.util.Map;import java.util.logging.Logger;public class CurlResource{ private static final Logger log = Logger.getLogger(CurlResource.class.getName()); private static final L10N L = new L10N(CurlResource.class); private String _requestMethod = "GET"; private int _responseCode; private String _URL; private int _port = -1; private String _username; private String _password; private boolean _isProxying = false; private String _proxyUsername; private String _proxyPassword; private String _proxyURL; private String _proxyType = "HTTP"; private int _proxyPort = -1; private boolean _isFollowingRedirects = true; private boolean _isReturningBody = true; private boolean _isReturningData = false; private boolean _isReturningHeader = false; private boolean _isVerifySSLPeer = true; private boolean _isVerifySSLCommonName = true; private boolean _isVerifySSLHostname = true; private boolean _ifModifiedSince = true; private String _modifiedTime; private int _errorCode = CurlModule.CURLE_OK; private String _error = ""; private boolean _failOnError = false; private boolean _isVerbose = false; private int _readTimeout = -1; private int _connectTimeout = -1; private HashMap<String,String> _requestProperties = new HashMap<String, String>(); private StringValue _header; private StringValue _body; private StringValue _postBody; private String _contentType; private int _contentLength; private String _cookie; private String _cookieFilename; private BinaryOutput _outputFile; private BinaryOutput _outputHeaderFile; private BinaryInput _uploadFile; private int _uploadFileSize; private Callback _headerCallback; private Callback _passwordCallback; private Callback _readCallback; private Callback _writeCallback; public CurlResource() { } /** * Returns body of last transfer. */ public Value getBody() { return _body; } /** * Sets the body of the last request. */ public void setBody(StringValue body) { _body = body; } /** * Returns the max time until timeout while establishing a connection. */ public int getConnectTimeout() { return _connectTimeout; } /** * Sets the max time until timeout while establishing a connection. */ public void setConnectTimeout(int timeout) { _connectTimeout = timeout; } /** * Returns the length of the body from the last request. */ public int getContentLength() { return _contentLength; } /** * Sets the length of the body from the last request. */ public void setContentLength(int length) { _contentLength = length; } /** * Returns the "Content-Type" header from the last request. */ public String getContentType() { return _contentType; } /** * Sets the "Content-Type" from the last request. */ public void setContentType(String type) { _contentType = type; } /** * Sets the "Set-Cookie" request property. */ public void setCookie(String cookie) { _cookie = cookie; } /** * Sets the filename to save the cookies from the last request. */ public void setCookieFilename(String filename) { _cookieFilename = filename; } /** * Returns the error string from the last request. */ public String getError() { return _error; } /** * Sets the error string from the last request. */ public void setError(String error) { _error = error; } /** * Sets the error code from the last request. */ public int getErrorCode() { return _errorCode; } /** * Returns the error code from the last request. */ public void setErrorCode(int code) { _errorCode = code; } /** * Set to true to fail on response codes >= 400. */ public void setFailOnError(boolean failOnError) { _failOnError = failOnError; } /** * Returns the header from the last request. */ public Value getHeader() { return _header; } /** * Saves the header that was returned by the server. */ public void setHeader(StringValue header) { _header = header; } /* * Returns the header callback. */ public Callback getHeaderCallback() { return _headerCallback; } /** * Sets the callback to read the header. */ public void setHeaderCallback(Callback callback) { _headerCallback = callback; } /** * Set to true to set the If-Modified-Since property. * Time to use is set with setModifiedTime(). */ public void setIfModifiedSince(boolean option) { _ifModifiedSince = option; } /** * Returns true if automatically following redirects. */ public boolean getIsFollowingRedirects() { return _isFollowingRedirects; } /** * Set to true to automatically follow redirects. */ public void setIsFollowingRedirects(boolean followRedirects) { _isFollowingRedirects = followRedirects; } /** * Returns true if a proxy is to be used. */ public boolean getIsProxying() { return _isProxying; } /** * Set to true to proxy request. */ public void setIsProxying(boolean proxy) { _isProxying = proxy; } /** * Set to true to return body for this request. */ public void setIsReturningBody(boolean returnBody) { _isReturningBody = returnBody; } /** * Set to true to return data instead of to stdout. */ public void setIsReturningData(boolean returnData) { _isReturningData = returnData; } /** * Set to true to return the body from this request. */ public void setIsReturningHeader(boolean returnHeader) { _isReturningHeader = returnHeader; } /** * Returns the verbosity of this library. */ public boolean getIsVerbose() { return _isVerbose; } /** * Sets the verbosity of this library. */ public void setIsVerbose(boolean verbose) { _isVerbose = verbose; } public boolean getIsVerifySSLPeer() { return _isVerifySSLPeer; } public void setIsVerifySSLPeer(boolean isVerify) { _isVerifySSLPeer = isVerify; } public boolean getIsVerifySSLCommonName() { return _isVerifySSLCommonName; } public void setIsVerifySSLCommonName(boolean isVerify) { _isVerifySSLCommonName = isVerify; } public boolean getIsVerifySSLHostname() { return _isVerifySSLHostname; } public void setIsVerifySSLHostname(boolean isVerify) { _isVerifySSLHostname = isVerify; } /** * Sets the modified time request property. */ public void setModifiedTime(String time) { _modifiedTime = time; } /** * Sets the file to save the data to save from a request. */ public void setOutputFile(BinaryOutput file) { _outputFile = file; } /** * Sets the file to save the header from a request. */ public void setOutputHeaderFile(BinaryOutput file) { _outputHeaderFile = file; } /** * Returns the password to use for authentication. */ public String getPassword() { return _password; } /** * Sets the password to use for authentication. */ public void setPassword(String pwd) { _password = pwd; } /** * */ public void setPasswordCallback(Callback callback) { _passwordCallback = callback; } /** * Returns the port to use for this request. */ public int getPort() { return _port; } /** * Sets the port to use for this request. */ public void setPort(int port) { _port = port; } /** * Sets the body to POST to the server. */ public StringValue getPostBody() { return _postBody; } /** * Sets the body to POST to the server. */ public void setPostBody(StringValue body) { _postBody = body; } /** * Returns the password to use for proxy authentication. */ public String getProxyPassword()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -