blob: 4df202c05ff9bc6a20d8c9cb9c70694c2a3ac66c (
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 2016 Yahoo Inc. 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 <a href="mailto:bakksjo@yahoo-inc.com">Oyvind Bakksjo</a>
*/
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);
}
}
|