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

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

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

HttpRequest.hostUrl介绍

[英]Returns just host url, without path and query.
[中]只返回主机url,不返回路径和查询。

代码示例

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

/**
 * Returns full URL path.
 * Simply concatenates {@link #protocol(String) protocol}, {@link #host(String) host},
 * {@link #port(int) port}, {@link #path(String) path} and {@link #queryString(String) query string}.
 */
public String url() {
  StringBuilder url = new StringBuilder();
  url.append(hostUrl());
  if (path != null) {
    url.append(path);
  }
  String queryString = queryString();
  if (StringUtil.isNotBlank(queryString)) {
    url.append('?');
    url.append(queryString);
  }
  return url.toString();
}

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

/**
 * Parses 'location' header to return the next location or returns {@code null} if location not specified.
 * Specification (<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30">rfc2616</a>)
 * says that only absolute path must be provided, however, this does not
 * happens in the real world. There a <a href="https://tools.ietf.org/html/rfc7231#section-7.1.2">proposal</a>
 * that allows server name etc to be omitted.
 */
public String location() {
  String location = header("location");
  if (location == null) {
    return null;
  }
  if (location.startsWith(StringPool.SLASH)) {
    location = getHttpRequest().hostUrl() + location;
  }
  return location;
}

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

@Test
void testUrl() {
  HttpRequest httpRequest = new HttpRequest();
  httpRequest.set("GET http://jodd.org:173/index.html?light=true");
  assertEquals("http://jodd.org:173/index.html?light=true", httpRequest.url());
  assertEquals("http://jodd.org:173", httpRequest.hostUrl());
  httpRequest = HttpRequest.get("foo.com/");
  assertEquals("http://foo.com", httpRequest.hostUrl());
}

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

/**
 * Returns full URL path.
 * Simply concatenates {@link #protocol(String) protocol}, {@link #host(String) host},
 * {@link #port(int) port}, {@link #path(String) path} and {@link #queryString(String) query string}.
 */
public String url() {
  StringBuilder url = new StringBuilder();
  url.append(hostUrl());
  if (path != null) {
    url.append(path);
  }
  String queryString = queryString();
  if (StringUtil.isNotBlank(queryString)) {
    url.append('?');
    url.append(queryString);
  }
  return url.toString();
}

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

/**
 * Parses 'location' header to return the next location or returns {@code null} if location not specified.
 * Specification (<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30">rfc2616</a>)
 * says that only absolute path must be provided, however, this does not
 * happens in the real world. There a <a href="https://tools.ietf.org/html/rfc7231#section-7.1.2">proposal</a>
 * that allows server name etc to be omitted.
 */
public String location() {
  String location = header("location");
  if (location == null) {
    return null;
  }
  if (location.startsWith(StringPool.SLASH)) {
    location = getHttpRequest().hostUrl() + location;
  }
  return location;
}

相关文章