📄 curlresource.java
字号:
{ return _proxyPassword; } /** * Sets the password to use for proxy authentication. */ public void setProxyPassword(String pass) { _proxyPassword = pass; } /** * Returns the port to use for the proxy. */ public int getProxyPort() { return _proxyPort; } /** * Sets the port to use for the proxy. */ public void setProxyPort(int port) { _proxyPort = port; } /** * Returns of type of the proxy (Http or SOCKS). */ public String getProxyType() { return _proxyType; } /** * Sets the type of the proxy (Http or SOCKS). */ public void setProxyType(String type) { _proxyType = type; } /** * Returns the URL of the proxy. */ public String getProxyURL() { return _proxyURL; } /** * Sets the URL of the proxy. */ public void setProxyURL(String proxy) { _proxyURL = proxy; } /** * Returns the username to use for proxy authentication. */ public String getProxyUsername() { return _proxyUsername; } /** * Sets the username to use for proxy authentication. */ public void setProxyUsername(String user) { _proxyUsername = user; } /* * Returns the callback to read the body. */ public Callback getReadCallback() { return _readCallback; } /** * Sets the callback to read the body. */ public void setReadCallback(Callback callback) { _readCallback = callback; } /** * Returns the max time until timeout while reading body. */ public int getReadTimeout() { return _readTimeout; } /** * Sets the max time until timeout while reading body. */ public void setReadTimeout(int timeout) { _readTimeout = timeout; } /** * Returns the current request method. */ public String getRequestMethod() { return _requestMethod; } /** * Sets the request method to use for this request. */ public void setRequestMethod(String method) { _requestMethod = method; } /** * Returns a map of all the request properties. */ public HashMap<String,String> getRequestPropertiesMap() { return _requestProperties; } /** * Returns all the request properties as a String. */ public Value getRequestProperties(Env env) { StringValue bb = env.createBinaryBuilder(); for (Map.Entry<String,String> entry: _requestProperties.entrySet()) { bb.append(entry.getKey()); bb.append(": "); bb.append(entry.getValue()); bb.append("\r\n"); } bb.append("\r\n"); return bb; } /** * Sets a request property to use for this request. */ public void setRequestProperty(String key, String value) { _requestProperties.put(key, value); } /** * Returns the response code for the last request. */ public int getResponseCode() { return _responseCode; } /** * Sets the response code for the last request. */ public void setResponseCode(int code) { _responseCode = code; } /** * Returns handle of file to upload. */ public BinaryInput getUploadFile() { return _uploadFile; } /** * Sets handle of file to upload. */ public void setUploadFile(BinaryInput file) { _uploadFile = file; } /** * Returns size of file to upload. */ public int getUploadFileSize() { return _uploadFileSize; } /** * Sets size of file to upload. */ public void setUploadFileSize(int size) { _uploadFileSize = size; } /** * Gets the URL to use for this request. */ public String getURL() { return _URL; } /** * Sets the URL to use for this request. */ public void setURL(String url) { _URL = url; } /** * Gets the username to use for authentication. */ public String getUsername() { return _username; } /** * Sets the username to use for authentication. */ public void setUsername(String user) { _username = user; } /** * */ public void setWriteCallback(Callback callback) { _writeCallback = callback; } /** * Remove a request property. */ public void removeRequestProperty(String key) { _requestProperties.remove(key); } /** * Finalizes the request properties for this connection. */ private void init() { _error = null; _errorCode = CurlModule.CURLE_OK; if (_modifiedTime != null) { if (_ifModifiedSince) { removeRequestProperty("If-Unmodified-Since"); setRequestProperty("If-Modified-Since", _modifiedTime); } else { removeRequestProperty("If-Modified-Since"); setRequestProperty("If-Unmodified-Since", _modifiedTime); } } if (_cookie != null) setRequestProperty("Cookie", _cookie); else removeRequestProperty("Cookie"); } /** * Executes this request. */ public Value execute(Env env) { init(); HttpRequest httpRequest = HttpRequest.getRequest(this); env.addCleanup(httpRequest); if (! httpRequest.execute(env)) return BooleanValue.FALSE; //if (hasError()) //return BooleanValue.FALSE; if (_cookie != null && _cookieFilename != null) saveCookie(env); return getReturnValue(env); } /** * Returns headers and/or body of the last request. */ private Value getReturnValue(Env env) { StringValue data; if (_responseCode == HttpURLConnection.HTTP_NOT_MODIFIED || _responseCode == HttpURLConnection.HTTP_PRECON_FAILED || (_failOnError && _responseCode >= 400)) { if (_isReturningHeader) data = _header; else return BooleanValue.TRUE; } else { StringValue bb = env.createBinaryBuilder(); if (_isReturningHeader) bb.append(_header); if (_isReturningBody) bb.append(_body); data = bb; } if (_isReturningData) return data; if (_outputHeaderFile != null) { FileModule.fwrite(env, _outputHeaderFile, _header.toInputStream(), Integer.MAX_VALUE); } if (_outputFile != null) { FileModule.fwrite(env, _outputFile, data.toInputStream(), Integer.MAX_VALUE); } else { env.print(data); } return BooleanValue.TRUE; } /** * Save the cookies from the last request. */ private void saveCookie(Env env) { WriteStream out = null; try { Path path = env.getPwd().lookup(_cookieFilename); out = path.openWrite(); int len = _cookie.length(); for (int i = 0; i < len; i++) { out.write((byte)_cookie.charAt(i)); } } catch (IOException e) { throw new QuercusModuleException(e); } finally { try { if (out != null) out.close(); } catch (IOException e) {} } } /** * */ public void close() { } /** * Returns true if an error occuring during the last operation. */ protected boolean hasError() { return _errorCode != CurlModule.CURLE_OK; } /** * Returns a copy of this resource. */ public CurlResource clone() { CurlResource curl = new CurlResource(); curl.setBody(_body); curl.setConnectTimeout(_connectTimeout); curl.setContentLength(_contentLength); curl.setContentType(_contentType); curl.setCookie(_cookie); curl.setCookieFilename(_cookieFilename); curl.setError(_error); curl.setErrorCode(_errorCode); curl.setFailOnError(_failOnError); curl.setHeaderCallback(_headerCallback); curl.setHeader(_header); curl.setIsFollowingRedirects(_isFollowingRedirects); curl.setIfModifiedSince(_ifModifiedSince); curl.setIsProxying(_isProxying); curl.setIsReturningBody(_isReturningBody); curl.setIsReturningData(_isReturningData); curl.setIsReturningHeader(_isReturningHeader); curl.setIsVerbose(_isVerbose); curl.setModifiedTime(_modifiedTime); curl.setOutputFile(_outputFile); curl.setOutputHeaderFile(_outputHeaderFile); curl.setPassword(_password); curl.setPasswordCallback(_passwordCallback); curl.setPort(_port); curl.setPostBody(_postBody); curl.setProxyPassword(_proxyPassword); curl.setProxyPort(_proxyPort); curl.setProxyType(_proxyType); curl.setProxyURL(_proxyURL); curl.setProxyUsername(_proxyUsername); curl.setReadCallback(_readCallback); curl.setReadTimeout(_readTimeout); curl.setRequestMethod(_requestMethod); for (Map.Entry<String,String> entry: _requestProperties.entrySet()) { curl.setRequestProperty(entry.getKey(), entry.getValue()); } curl.setResponseCode(_responseCode); curl.setUploadFile(_uploadFile); curl.setUploadFileSize(_uploadFileSize); curl.setURL(_URL); curl.setUsername(_username); curl.setWriteCallback(_writeCallback); return curl; } public String toString() { return "CurlResource[" + _requestMethod + "]"; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -