List of usage examples for io.netty.handler.codec.http HttpHeaderNames ALLOW
AsciiString ALLOW
To view the source code for io.netty.handler.codec.http HttpHeaderNames ALLOW.
Click Source Link
From source file:org.ballerinalang.net.http.CorsHeaderGenerator.java
License:Open Source License
public static void process(HttpCarbonMessage requestMsg, HttpCarbonMessage responseMsg, boolean isSimpleRequest) { boolean isCorsResponseHeadersAvailable = false; Map<String, String> responseHeaders; CorsHeaders resourceCors;//from w ww. j av a 2 s .c o m if (isSimpleRequest) { resourceCors = (CorsHeaders) requestMsg.getProperty(HttpConstants.RESOURCES_CORS); String origin = requestMsg.getHeader(HttpHeaderNames.ORIGIN.toString()); //resourceCors cannot be null here if (origin == null || resourceCors == null || !resourceCors.isAvailable()) { return; } if ((responseHeaders = processSimpleRequest(origin, resourceCors)) != null) { isCorsResponseHeadersAvailable = true; } } else { String origin = requestMsg.getHeader(HttpHeaderNames.ORIGIN.toString()); if (origin == null) { return; } if ((responseHeaders = processPreflightRequest(origin, requestMsg)) != null) { isCorsResponseHeadersAvailable = true; } } if (isCorsResponseHeadersAvailable) { responseHeaders.forEach(responseMsg::setHeader); responseMsg.removeHeader(HttpHeaderNames.ALLOW.toString()); } }
From source file:org.ballerinalang.net.http.HttpResourceDataElement.java
License:Open Source License
private boolean isOptionsRequest(HttpCarbonMessage inboundMessage) { //Return true to break the resource searching loop, only if the ALLOW header is set in message for //OPTIONS request. return inboundMessage.getHeader(HttpHeaderNames.ALLOW.toString()) != null; }
From source file:org.ballerinalang.net.http.HttpResourceDataElement.java
License:Open Source License
private boolean setAllowHeadersIfOPTIONS(String httpMethod, HttpCarbonMessage cMsg) { if (httpMethod.equals(HttpConstants.HTTP_METHOD_OPTIONS)) { cMsg.setHeader(HttpHeaderNames.ALLOW.toString(), getAllowHeaderValues(cMsg)); return true; }//from ww w . java 2 s .c om return false; }
From source file:org.ballerinalang.net.http.HttpResourceDispatcher.java
License:Open Source License
private static void handleOptionsRequest(HttpCarbonMessage cMsg, HttpService service) { HttpCarbonMessage response = HttpUtil.createHttpCarbonMessage(false); if (cMsg.getHeader(HttpHeaderNames.ALLOW.toString()) != null) { response.setHeader(HttpHeaderNames.ALLOW.toString(), cMsg.getHeader(HttpHeaderNames.ALLOW.toString())); } else if (service.getBasePath().equals(cMsg.getProperty(HttpConstants.TO)) && !service.getAllAllowedMethods().isEmpty()) { response.setHeader(HttpHeaderNames.ALLOW.toString(), DispatcherUtil.concatValues(service.getAllAllowedMethods(), false)); } else {//from w w w . ja va 2 s.c o m cMsg.setProperty(HttpConstants.HTTP_STATUS_CODE, 404); throw new BallerinaConnectorException("no matching resource found for path : " + cMsg.getProperty(HttpConstants.TO) + " , method : " + "OPTIONS"); } CorsHeaderGenerator.process(cMsg, response, false); response.setProperty(HttpConstants.HTTP_STATUS_CODE, 200); response.addHttpContent(new DefaultLastHttpContent()); PipeliningHandler.sendPipelinedResponse(cMsg, response); }
From source file:org.ballerinalang.stdlib.services.cors.HTTPCorsTest.java
License:Open Source License
@Test(description = "Test preflight without CORS headers") public void testPreFlightReqNoCorsResource() { String path = "/echo4/info1"; HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS", "Hello there"); cMsg.setHeader(HttpHeaderNames.ORIGIN.toString(), "http://www.wso2.com"); cMsg.setHeader(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD.toString(), HttpConstants.HTTP_METHOD_POST); HttpCarbonMessage response = Services.invokeNew(complieResult, TEST_EP, cMsg); Assert.assertNotNull(response);/*from w ww . j a v a 2s . c om*/ assertEqualsCorsResponse(response, 200, null, null, null, null, null); Assert.assertEquals(response.getHeader(HttpHeaderNames.ALLOW.toString()), "POST, OPTIONS"); }
From source file:org.ballerinalang.stdlib.services.dispatching.UriTemplateDispatcherTest.java
License:Open Source License
@Test(description = "Test dispatching with OPTIONS request with GET method") public void testOPTIONSWithGETMethods() { String path = "/options/getme"; HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS", "hi"); HttpCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg); Assert.assertNotNull(response, "Response message not found"); Assert.assertEquals(/*from w w w . ja v a 2 s.com*/ StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream()), ""); Assert.assertEquals(response.getProperty(HttpConstants.HTTP_STATUS_CODE), 200, "Response code mismatch"); String allowHeader = cMsg.getHeader(HttpHeaderNames.ALLOW.toString()); Assert.assertEquals(allowHeader, "GET, HEAD, OPTIONS"); }
From source file:org.ballerinalang.stdlib.services.dispatching.UriTemplateDispatcherTest.java
License:Open Source License
@Test(description = "Test dispatching with OPTIONS request with POST method") public void testOPTIONSWithPOSTMethods() { String path = "/options/post"; HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS"); HttpCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg); Assert.assertNotNull(response, "Response message not found"); Assert.assertEquals(//w ww .ja va 2 s. c om StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream()), ""); Assert.assertEquals(response.getProperty(HttpConstants.HTTP_STATUS_CODE), 200, "Response code mismatch"); String allowHeader = cMsg.getHeader(HttpHeaderNames.ALLOW.toString()); Assert.assertEquals(allowHeader, "POST, OPTIONS"); }
From source file:org.ballerinalang.stdlib.services.dispatching.UriTemplateDispatcherTest.java
License:Open Source License
@Test(description = "Test dispatching with OPTIONS request with PUT method") public void testOPTIONSWithPUTMethods() { String path = "/options/put/add"; HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS"); HttpCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg); Assert.assertNotNull(response, "Response message not found"); Assert.assertEquals(/*from w w w. j ava2 s .c om*/ StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream()), ""); Assert.assertEquals(response.getProperty(HttpConstants.HTTP_STATUS_CODE), 200, "Response code mismatch"); String allowHeader = response.getHeader(HttpHeaderNames.ALLOW.toString()); Assert.assertEquals(allowHeader, "PUT, OPTIONS"); }
From source file:org.ballerinalang.stdlib.services.dispatching.UriTemplateDispatcherTest.java
License:Open Source License
@Test(description = "Test dispatching with OPTIONS request with PATH params") public void testOPTIONSWithPathParams() { String path = "/options/put/xyz"; HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS"); HttpCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg); Assert.assertNotNull(response, "Response message not found"); Assert.assertEquals(//w w w.j av a 2s .c om StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream()), ""); Assert.assertEquals(response.getProperty(HttpConstants.HTTP_STATUS_CODE), 200, "Response code mismatch"); String allowHeader = response.getHeader(HttpHeaderNames.ALLOW.toString()); Assert.assertEquals(allowHeader, "DELETE, OPTIONS"); }
From source file:org.ballerinalang.stdlib.services.dispatching.UriTemplateDispatcherTest.java
License:Open Source License
@Test(description = "Test dispatching with OPTIONS request multiple resources") public void testOPTIONSWithMultiResources() { String path = "/options/test"; HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "OPTIONS"); HttpCarbonMessage response = Services.invokeNew(application, TEST_EP, cMsg); Assert.assertNotNull(response, "Response message not found"); Assert.assertEquals(//ww w.j a v a 2 s . c o m StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream()), ""); Assert.assertEquals(response.getProperty(HttpConstants.HTTP_STATUS_CODE), 200, "Response code mismatch"); String allowHeader = response.getHeader(HttpHeaderNames.ALLOW.toString()); Assert.assertEquals(allowHeader, "POST, UPDATE, GET, PUT, HEAD, OPTIONS"); }