Search in sources :

Example 26 with Request

use of com.blade.mvc.http.Request in project blade by biezhi.

the class HttpRequestTest method testUserAgent.

@Test
public void testUserAgent() {
    Map<String, String> headers = Collections.singletonMap("User-Agent", firefoxUA);
    Request mockRequest = mockHttpRequest("GET");
    when(mockRequest.headers()).thenReturn(headers);
    Request request = new HttpRequest(mockRequest);
    assertEquals(firefoxUA, request.userAgent());
}
Also used : HttpRequest(com.blade.mvc.http.HttpRequest) HttpRequest(com.blade.mvc.http.HttpRequest) Request(com.blade.mvc.http.Request) Test(org.junit.Test)

Example 27 with Request

use of com.blade.mvc.http.Request in project blade by biezhi.

the class HttpRequestTest method testIsAjax.

@Test
public void testIsAjax() {
    Request mockRequest = mockHttpRequest("GET");
    Map<String, String> headers = Collections.singletonMap("x-requested-with", "XMLHttpRequest");
    when(mockRequest.headers()).thenReturn(headers);
    Request request = new HttpRequest(mockRequest);
    assertEquals(Boolean.TRUE, request.isAjax());
    when(mockRequest.headers()).thenReturn(Collections.EMPTY_MAP);
    request = new HttpRequest(mockRequest);
    assertEquals(Boolean.FALSE, request.isAjax());
}
Also used : HttpRequest(com.blade.mvc.http.HttpRequest) HttpRequest(com.blade.mvc.http.HttpRequest) Request(com.blade.mvc.http.Request) Test(org.junit.Test)

Example 28 with Request

use of com.blade.mvc.http.Request in project blade by biezhi.

the class HttpRequestTest method testHeaders.

@Test
public void testHeaders() {
    Request mockRequest = mockHttpRequest("GET");
    Map<String, String> headers = new CaseInsensitiveHashMap<>();
    headers.put("h1", "a1");
    headers.put("H2", "a2");
    when(mockRequest.headers()).thenReturn(headers);
    Request request = new HttpRequest(mockRequest);
    assertEquals("a1", request.header("h1"));
    assertEquals("a1", request.header("H1"));
    assertEquals("a2", request.header("h2"));
    assertEquals("a2", request.header("H2"));
    request.headers().forEach((key, val) -> System.out.println(key + "\t=\t" + val));
}
Also used : HttpRequest(com.blade.mvc.http.HttpRequest) HttpRequest(com.blade.mvc.http.HttpRequest) Request(com.blade.mvc.http.Request) CaseInsensitiveHashMap(com.blade.kit.CaseInsensitiveHashMap) Test(org.junit.Test)

Example 29 with Request

use of com.blade.mvc.http.Request in project blade by biezhi.

the class HttpRequestTest method testQueryString.

@Test
public void testQueryString() {
    Request mockRequest = mockHttpRequest("GET");
    when(mockRequest.url()).thenReturn("/hello?name=q1");
    Request request = new HttpRequest(mockRequest);
    assertEquals("name=q1", request.queryString());
}
Also used : HttpRequest(com.blade.mvc.http.HttpRequest) HttpRequest(com.blade.mvc.http.HttpRequest) Request(com.blade.mvc.http.Request) Test(org.junit.Test)

Aggregations

Request (com.blade.mvc.http.Request)29 HttpRequest (com.blade.mvc.http.HttpRequest)18 Test (org.junit.Test)18 HashMap (java.util.HashMap)7 CaseInsensitiveHashMap (com.blade.kit.CaseInsensitiveHashMap)5 WebContext (com.blade.mvc.WebContext)3 Response (com.blade.mvc.http.Response)3 RouteContext (com.blade.mvc.RouteContext)2 AuthOption (com.blade.security.web.auth.AuthOption)2 BasicAuthMiddleware (com.blade.security.web.auth.BasicAuthMiddleware)2 ForbiddenException (com.blade.exception.ForbiddenException)1 NotFoundException (com.blade.exception.NotFoundException)1 TemplateException (com.blade.exception.TemplateException)1 Session (com.blade.mvc.http.Session)1 FileItem (com.blade.mvc.multipart.FileItem)1 Contents (com.tale.model.entity.Contents)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 DefaultFileRegion (io.netty.channel.DefaultFileRegion)1 SslHandler (io.netty.handler.ssl.SslHandler)1