GPRequest.java 901 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package cn.hhj.http;
  2. import io.netty.channel.ChannelHandlerContext;
  3. import io.netty.handler.codec.http.HttpRequest;
  4. import io.netty.handler.codec.http.QueryStringDecoder;
  5. import java.util.List;
  6. import java.util.Map;
  7. public class GPRequest {
  8. private ChannelHandlerContext ctx;
  9. private HttpRequest req;
  10. public GPRequest(ChannelHandlerContext ctx, HttpRequest req) {
  11. this.ctx = ctx;
  12. this.req = req;
  13. }
  14. public String getUrl() {
  15. return req.uri();
  16. }
  17. public String getMethod() {
  18. return req.method().name();
  19. }
  20. public Map<String, List<String>> getParameters() {
  21. QueryStringDecoder decoder = new QueryStringDecoder(req.uri());
  22. return decoder.parameters();
  23. }
  24. public String getParameter(String name) {
  25. Map<String, List<String>> params = getParameters();
  26. List<String> param = params.get(name);
  27. if (null == param) {
  28. return null;
  29. } else {
  30. return param.get(0);
  31. }
  32. }
  33. }