1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.apache.hc.client5.http.impl;
28
29 import org.apache.hc.core5.annotation.Internal;
30 import org.apache.hc.core5.http.HttpRequest;
31 import org.apache.hc.core5.http.URIScheme;
32 import org.apache.hc.core5.net.URIAuthority;
33
34
35
36
37
38
39 @Internal
40 public final class ProtocolSupport {
41
42 public static String getRequestUri(final HttpRequest request) {
43 final URIAuthority authority = request.getAuthority();
44 if (authority != null) {
45 final StringBuilder buf = new StringBuilder();
46 final String scheme = request.getScheme();
47 buf.append(scheme != null ? scheme : URIScheme.HTTP.id);
48 buf.append("://");
49 if (authority.getUserInfo() != null) {
50 buf.append(authority.getUserInfo());
51 buf.append("@");
52 }
53 buf.append(authority.getHostName());
54 if (authority.getPort() != -1) {
55 buf.append(":");
56 buf.append(authority.getPort());
57 }
58 final String path = request.getPath();
59 if (path == null || !path.startsWith("/")) {
60 buf.append("/");
61 }
62 if (path != null) {
63 buf.append(path);
64 }
65 return buf.toString();
66 } else {
67 return request.getPath();
68 }
69 }
70
71 }