com.clouway.friendlyserve.TkRequestWrap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fserve Show documentation
Show all versions of fserve Show documentation
Friendly Serving HTTP Library.
package com.clouway.friendlyserve;
import com.google.common.collect.Lists;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;
/**
* @author Miroslav Genov ([email protected])
*/
public class TkRequestWrap implements Request {
private final transient HttpServletRequest req;
public TkRequestWrap(HttpServletRequest req) {
this.req = req;
}
@Override
public String path() {
return req.getRequestURI();
}
@Override
public String param(String name) {
return req.getParameter(name);
}
@SuppressWarnings("unchecked")
@Override
public Iterable names() {
return req.getParameterMap().keySet();
}
@Override
public Iterable cookie(String name) {
Cookie[] cookies = req.getCookies();
if (cookies == null) {
return new LinkedList();
}
List values = Lists.newLinkedList();
for (Cookie each : cookies) {
if (name.equalsIgnoreCase(each.getName())) {
values.add(each.getValue());
}
}
return values;
}
@Override
public String header(String name) {
return req.getHeader(name);
}
@Override
public InputStream body() throws IOException {
return req.getInputStream();
}
}