jodd.http.HttpRequest.keepAlive()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(2.2k)|赞(0)|评价(0)|浏览(187)

本文整理了Java中jodd.http.HttpRequest.keepAlive()方法的一些代码示例,展示了HttpRequest.keepAlive()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.keepAlive()方法的具体详情如下:
包路径:jodd.http.HttpRequest
类名称:HttpRequest
方法名:keepAlive

HttpRequest.keepAlive介绍

[英]Continues using the same keep-alive connection. Don't use any variant of open() when continuing the communication! First it checks if "Connection" header exist in the response and if it is equal to "Keep-Alive" value. Then it checks the "Keep-Alive" headers "max" parameter. If its value is positive, then the existing jodd.http.HttpConnectionfrom the request will be reused. If max value is 1, connection will be sent with "Connection: Close" header, indicating its the last request. When new connection is created, the same jodd.http.HttpConnectionProvider that was used for creating initial connection is used for opening the new connection.
[中]继续使用相同的保持活动连接。继续通信时,不要使用open()的任何变体!首先,它检查响应中是否存在“Connection”头,以及它是否等于“Keep Alive”值。然后检查“Keep Alive”headers“max”参数。如果其值为正值,则现有jodd。http。请求中的HttpConnection将被重用。如果最大值为1,则将发送带有“connection:Close”头的连接,指示其为最后一个请求。创建新连接时,将使用相同的jodd。http。用于创建初始连接的HttpConnectionProvider用于打开新连接。

代码示例

代码示例来源:origin: oblac/jodd

/**
 * Opens connection and sends a response.
 */
protected HttpResponse _sendRequest(final HttpRequest httpRequest, final HttpResponse previouseResponse) {
  if (!keepAlive) {
    httpRequest.open(httpConnectionProvider);
  } else {
    // keeping alive
    if (previouseResponse == null) {
      httpRequest.open(httpConnectionProvider).connectionKeepAlive(true);
    } else {
      httpRequest.keepAlive(previouseResponse, true);
    }
  }
  return httpRequest.send();
}

代码示例来源:origin: oblac/jodd

response = request.keepAlive(response, true).send();
response = request.keepAlive(response, true).send();
response = request.keepAlive(response, true).send();		// should be false for the last connection, but ok.

代码示例来源:origin: org.jodd/jodd-http

/**
 * Opens connection and sends a response.
 */
protected HttpResponse _sendRequest(final HttpRequest httpRequest, final HttpResponse previouseResponse) {
  if (!keepAlive) {
    httpRequest.open(httpConnectionProvider);
  } else {
    // keeping alive
    if (previouseResponse == null) {
      httpRequest.open(httpConnectionProvider).connectionKeepAlive(true);
    } else {
      httpRequest.keepAlive(previouseResponse, true);
    }
  }
  return httpRequest.send();
}

相关文章