初始化Http响应<br>
初始化包括：

<pre>
1、读取Http状态
2、读取头信息
3、持有Http流，并不关闭流
</pre>

@return this
@throws HttpException IO异常
482874
private HttpResponse init() throws HttpException {
		try {
			this.status = httpConnection.responseCode();
			this.in = (this.status < HttpStatus.HTTP_BAD_REQUEST) ? httpConnection.getInputStream() : httpConnection.getErrorStream();
		} catch (IOException e) {
			if (e instanceof FileNotFoundException) {
				// 服务器无返回内容，忽略之
			} else {
				throw new HttpException(e);
			}
		}

		try {
			this.headers = httpConnection.headers();
		} catch (IllegalArgumentException e) {
			StaticLog.warn(e, e.getMessage());
		}
		final Charset charset = httpConnection.getCharset();
		this.charsetFromResponse = charset;
		if (null != charset) {
			this.charset = charset;
		}

		if (null == this.in) {
			// 在一些情况下，返回的流为null，此时提供状态码说明
			this.in = new ByteArrayInputStream(StrUtil.format("Error request, response status: {}", this.status).getBytes());
		} else if (isGzip() && false == (in instanceof GZIPInputStream)) {
			try {
				in = new GZIPInputStream(in);
			} catch (IOException e) {
				// 在类似于Head等方法中无body返回，此时GZIPInputStream构造会出现错误，在此忽略此错误读取普通数据
				// ignore
			}
		} else if (isDeflate() && false == (in instanceof DeflaterInputStream)) {
			//Accept-Encoding: defalte
			in = new DeflaterInputStream(in);
		}

		// 同步情况下强制同步
		return this.isAsync ? this : forceSync();
	}
1017651
protected function dispatch()
    {
        $routeInfo = $this->createDispatcher()->dispatch($this->getHttpMethod(), $this->getUri());

        switch ($routeInfo[0]) {
            case Dispatcher::NOT_FOUND:
                throw new HttpException(404, 'NOT FOUND');
            case Dispatcher::METHOD_NOT_ALLOWED:
                // $allowedMethods = $routeInfo[1]; //允许的方法
                throw new HttpException(405, 'Method Not Allowed');
            case Dispatcher::FOUND:
                // $routeInfo = [Dispatcher::FOUND, 'handler', 'vars']
                break;
            default: //不会出现这种情况，这里运行不到
                throw new HttpException(404, 'NOT FOUND');
        }

        $this->parseRouteInfo($routeInfo[1], $routeInfo[2]);
    }
730201
protected HttpURLConnection generateConn() throws IOException {
        HttpURLConnection conn;
        conn = (HttpURLConnection) new URL(url).openConnection();
        return conn;
    }
110478
public function reset()
    {
        $this->_headers->clearHeaders();
        $this->params = [];
        $this->postRawData = null;
        $this->httpClient->reset();
        return $this;
    }
620011
public byte[]  bytes() {

        connect();

        ByteArrayOutputStream bout = new ByteArrayOutputStream();

        byte[] bytes = new byte[1024];
        int count;
        try {
            InputStream in = connection.getInputStream();
            while ((count = in.read(bytes)) != -1) {
                bout.write(bytes, 0, count);
            }
        } catch (Exception e) {
            throw new HttpException("Failed URL: " + url, e);
        }finally {
            dispose();
        }

        return bout.toByteArray();
    }
114375
private HttpContent nextChunk() throws ErrorDataEncoderException {
        if (isLastChunk) {
            isLastChunkSent = true;
            return LastHttpContent.EMPTY_LAST_CONTENT;
        }
        // first test if previous buffer is not empty
        int size = calculateRemainingSize();
        if (size <= 0) {
            // NextChunk from buffer
            ByteBuf buffer = fillByteBuf();
            return new DefaultHttpContent(buffer);
        }
        // size > 0
        if (currentData != null) {
            // continue to read data
            HttpContent chunk;
            if (isMultipart) {
                chunk = encodeNextChunkMultipart(size);
            } else {
                chunk = encodeNextChunkUrlEncoded(size);
            }
            if (chunk != null) {
                // NextChunk from data
                return chunk;
            }
            size = calculateRemainingSize();
        }
        if (!iterator.hasNext()) {
            return lastChunk();
        }
        while (size > 0 && iterator.hasNext()) {
            currentData = iterator.next();
            HttpContent chunk;
            if (isMultipart) {
                chunk = encodeNextChunkMultipart(size);
            } else {
                chunk = encodeNextChunkUrlEncoded(size);
            }
            if (chunk == null) {
                // not enough
                size = calculateRemainingSize();
                continue;
            }
            // NextChunk from data
            return chunk;
        }
        // end since no more data
        return lastChunk();
    }
207361
public HttpComponentsClientHttpRequestFactory getObject() throws Exception {
        Assert.notNull(credentials, "User credentials not set properly!");
        
        HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient) {
            @Override
            protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
                // we have to use preemptive authentication
                // therefore add some basic auth cache to the local context
                AuthCache authCache = new BasicAuthCache();
                BasicScheme basicAuth = new BasicScheme();
                
                authCache.put(new HttpHost(authScope.getHost(), authScope.getPort(), "http"), basicAuth);
                authCache.put(new HttpHost(authScope.getHost(), authScope.getPort(), "https"), basicAuth);
                
                BasicHttpContext localcontext = new BasicHttpContext();
                localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
                
                return localcontext;
            }
        };
        
        if (httpClient instanceof AbstractHttpClient) {
            ((AbstractHttpClient)httpClient).getCredentialsProvider().setCredentials(authScope, credentials);
        } else {
            log.warn("Unable to set username password credentials for basic authentication, " +
            		"because nested HttpClient implementation does not support a credentials provider!");
        }
        
        return requestFactory;
    }
949162
public WaitHttpConditionBuilder http() {
        HttpCondition condition = new HttpCondition();
        container.setCondition(condition);
        return new WaitHttpConditionBuilder(condition, this);
    }
480180
private KieServerHttpRequest openOutput() throws IOException {
        if( output != null ) {
            return this;
        }
        getConnection().setDoOutput(true);
        final String charset = getHeaderParam(getConnection().getRequestProperty(CONTENT_TYPE), PARAM_CHARSET);
        output = new RequestOutputStream(getConnection().getOutputStream(), charset, bufferSize);
        return this;
    }
1354752
public Map<String, String> toMap() {
        final Map<String, String> result = new HashMap<>();
        for (final HttpHeader header : headers.values()) {
            result.put(header.name(), header.value());
        }
        return result;
    }
722304
public function exec()
    {
        $this->setOutput(curl_exec($this->ch));
        $this->setStatusCode(curl_getinfo($this->ch, CURLINFO_HTTP_CODE));

        if (curl_errno($this->ch)) {
            throw new \ErrorException(curl_error($this->ch));
        }

        return $this;
    }
732046
protected HttpClient getHttpClient(){

        HttpClientBuilder builder = HttpClientBuilder.create();

        if(proxyHost != null && proxyPort != 0) {
            HttpHost proxy = new HttpHost(proxyHost, proxyPort);
            DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
            builder.setRoutePlanner(routePlanner);
        }

        RequestConfig.Builder config = RequestConfig.custom()
                .setConnectTimeout(timeout)
                .setConnectionRequestTimeout(timeout)
                .setSocketTimeout(timeout);

        builder.setDefaultRequestConfig(config.build());

        return builder.build();
    }
1005131
public ApiResponse<GetArgsResponse> argsWithHttpInfo() throws ApiException {
        com.squareup.okhttp.Call call = argsValidateBeforeCall(null, null);
        Type localVarReturnType = new TypeToken<GetArgsResponse>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }
504780
public String responseMessage() {
        try {
            connect();
            return connection.getResponseMessage();
        } catch (Exception e) {
            throw new HttpException("Failed URL: " + url, e);
        }
    }
1154412
private String httpQuery() {

		String response = null;
		try {
			URL restUrl = new URL( this.url );
			HttpURLConnection conn = (HttpURLConnection) restUrl.openConnection();
			response = query( conn );

		} catch( Exception e ) {
			this.logger.severe( "Cannot issue GET on URL " + this.url + ". Monitoring notification is discarded." );
			Utils.logException(this.logger, e);
		}

		return response;
	}
907831
public function build()
    {
        $uri = $this->trimTrailingSlashes($this->request->getUri()->getPath());
        $method = mb_strtoupper($this->request->getMethod());

        foreach ($this->routes[$method] as $routeUri => $action) {
            $arguments = $this->match($uri, $routeUri);

            if (!is_null($arguments)) {
                return $this->constructAction($action, $arguments);
            }
        }

        throw new HTTPException('Not found', 404);
    }
93735
private HttpResponse sendRedirectIfPosible() {
		if (this.maxRedirectCount < 1) {
			// 不重定向
			return null;
		}

		// 手动实现重定向
		if (this.httpConnection.getHttpURLConnection().getInstanceFollowRedirects()) {
			int responseCode;
			try {
				responseCode = httpConnection.responseCode();
			} catch (IOException e) {
				throw new HttpException(e);
			}
			if (responseCode != HttpURLConnection.HTTP_OK) {
				if (responseCode == HttpURLConnection.HTTP_MOVED_TEMP || responseCode == HttpURLConnection.HTTP_MOVED_PERM || responseCode == HttpURLConnection.HTTP_SEE_OTHER) {
					this.url = httpConnection.header(Header.LOCATION);
					if (redirectCount < this.maxRedirectCount) {
						redirectCount++;
						return execute();
					} else {
						StaticLog.warn("URL [{}] redirect count more than two !", this.url);
					}
				}
			}
		}
		return null;
	}