blob: 3c688ab0c4d1d3ee07be8b835558f53f8aab9825 (
plain) (
blame)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.http;
import com.yahoo.jdisc.http.HttpRequest;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.List;
/**
* @author bakksjo
*/
public class AccessLogUtil {
public static String getHttpMethod(final HttpRequest httpRequest) {
return httpRequest.getMethod().toString();
}
public static URI getUri(final HttpRequest httpRequest) {
return httpRequest.getUri();
}
public static String getHttpVersion(final HttpRequest httpRequest) {
return httpRequest.getVersion().toString();
}
public static String getReferrerHeader(final HttpRequest httpRequest) {
// Yes, the header name is misspelled in the standard
return getFirstHeaderValue(httpRequest, "Referer");
}
public static String getUserAgentHeader(final HttpRequest httpRequest) {
return getFirstHeaderValue(httpRequest, "User-Agent");
}
public static InetSocketAddress getRemoteAddress(final HttpRequest httpRequest) {
return (InetSocketAddress) httpRequest.getRemoteAddress();
}
private static String getFirstHeaderValue(final HttpRequest httpRequest, final String headerName) {
final List<String> headerValues = httpRequest.headers().get(headerName);
return (headerValues == null || headerValues.isEmpty()) ? "" : headerValues.get(0);
}
}
|