]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - http/HttpServerUtils.java
1 package org
.argeo
.util
.http
;
4 import java
.util
.Objects
;
6 import com
.sun
.net
.httpserver
.HttpContext
;
7 import com
.sun
.net
.httpserver
.HttpExchange
;
9 public class HttpServerUtils
{
11 public static String
relativize(HttpContext httpContext
, String path
) {
12 Objects
.requireNonNull(path
);
13 if (!path
.startsWith(httpContext
.getPath()))
14 throw new IllegalArgumentException(path
+ " does not belong to context" + httpContext
.getPath());
15 String relativePath
= path
.substring(httpContext
.getPath().length());
17 if (relativePath
.startsWith("/"))
18 relativePath
= relativePath
.substring(1);
22 public static String
relativize(HttpExchange exchange
) {
23 URI uri
= exchange
.getRequestURI();
24 HttpContext httpContext
= exchange
.getHttpContext();
25 return relativize(httpContext
, uri
.getPath());
29 private HttpServerUtils() {