Search in sources :

Example 41 with HttpHeaders

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.

the class RemoveHeader method execute.

@Override
public void execute(Context context) {
    BStruct entityStruct = (BStruct) context.getRefArgument(FIRST_PARAMETER_INDEX);
    String headerName = context.getStringArgument(FIRST_PARAMETER_INDEX);
    if (entityStruct.getNativeData(ENTITY_HEADERS) != null) {
        HttpHeaders httpHeaders = (HttpHeaders) entityStruct.getNativeData(ENTITY_HEADERS);
        httpHeaders.remove(headerName);
    }
    context.setReturnValues();
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) BStruct(org.ballerinalang.model.values.BStruct)

Example 42 with HttpHeaders

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.

the class SetHeader method execute.

@Override
public void execute(Context context) {
    BStruct entityStruct = (BStruct) context.getRefArgument(FIRST_PARAMETER_INDEX);
    String headerName = context.getStringArgument(FIRST_PARAMETER_INDEX);
    String headerValue = context.getStringArgument(SECOND_PARAMETER_INDEX);
    if (headerName == null || headerValue == null) {
        return;
    }
    HttpHeaders httpHeaders;
    if (entityStruct.getNativeData(ENTITY_HEADERS) != null) {
        httpHeaders = (HttpHeaders) entityStruct.getNativeData(ENTITY_HEADERS);
    } else {
        httpHeaders = new DefaultHttpHeaders();
        entityStruct.addNativeData(ENTITY_HEADERS, httpHeaders);
    }
    httpHeaders.set(headerName, headerValue);
    context.setReturnValues();
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) BStruct(org.ballerinalang.model.values.BStruct) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders)

Example 43 with HttpHeaders

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.

the class RequestNativeFunctionNegativeTest method testRemoveAllHeadersNegative.

@Test
@SuppressWarnings("unchecked")
public void testRemoveAllHeadersNegative() {
    BStruct outRequest = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, reqStruct);
    BValue[] inputArg = { outRequest };
    BValue[] returnVals = BRunUtil.invoke(result, "testRemoveAllHeaders", inputArg);
    Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
    Assert.assertTrue(returnVals[0] instanceof BStruct);
    BStruct entityStruct = (BStruct) ((BStruct) returnVals[0]).getNativeData(MESSAGE_ENTITY);
    HttpHeaders returnHeaders = (HttpHeaders) entityStruct.getNativeData(ENTITY_HEADERS);
    Assert.assertNull(returnHeaders.get("Expect"));
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) BStruct(org.ballerinalang.model.values.BStruct) BValue(org.ballerinalang.model.values.BValue) Test(org.testng.annotations.Test)

Example 44 with HttpHeaders

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.

the class RequestNativeFunctionSuccessTest method testSetMultipleHeader.

@Test
@SuppressWarnings("unchecked")
public void testSetMultipleHeader() {
    String headerName = "team";
    String headerValue = "lang, composer";
    BString key = new BString(headerName);
    BString value = new BString(headerValue);
    BValue[] inputArg = { key, value };
    BValue[] returnVals = BRunUtil.invoke(result, "testSetHeader", inputArg);
    Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
    Assert.assertTrue(returnVals[0] instanceof BStruct);
    BStruct entityStruct = (BStruct) ((BStruct) returnVals[0]).getNativeData(MESSAGE_ENTITY);
    HttpHeaders httpHeaders = (HttpHeaders) entityStruct.getNativeData(ENTITY_HEADERS);
    Assert.assertEquals(httpHeaders.get(headerName), headerValue);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) BStruct(org.ballerinalang.model.values.BStruct) BString(org.ballerinalang.model.values.BString) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 45 with HttpHeaders

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.

the class RequestNativeFunctionSuccessTest method testGetContentLength.

@Test(description = "Enable this once the getContentLength() is added back in http package", enabled = false)
public void testGetContentLength() {
    BStruct inRequest = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, reqStruct);
    BStruct entity = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageMime, entityStruct);
    String payload = "ballerina";
    HttpHeaders httpHeaders = new DefaultHttpHeaders();
    httpHeaders.add(HttpHeaderNames.CONTENT_LENGTH.toString(), payload.length());
    entity.addNativeData(ENTITY_HEADERS, httpHeaders);
    inRequest.addNativeData(MESSAGE_ENTITY, entity);
    BValue[] inputArg = { inRequest };
    BValue[] returnVals = BRunUtil.invoke(result, "testGetContentLength", inputArg);
    Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
    Assert.assertEquals(payload.length(), ((BInteger) returnVals[0]).intValue());
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) BStruct(org.ballerinalang.model.values.BStruct) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Aggregations

HttpHeaders (io.netty.handler.codec.http.HttpHeaders)286 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)149 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)83 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)73 Test (org.junit.Test)68 Test (org.junit.jupiter.api.Test)57 Test (org.testng.annotations.Test)51 HttpRequest (io.netty.handler.codec.http.HttpRequest)43 HttpResponse (io.netty.handler.codec.http.HttpResponse)40 AsciiString (io.netty.util.AsciiString)29 ByteBuf (io.netty.buffer.ByteBuf)27 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)27 BStruct (org.ballerinalang.model.values.BStruct)26 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)22 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)22 HttpServletResponse (javax.servlet.http.HttpServletResponse)20 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)19 Cookie (io.netty.handler.codec.http.cookie.Cookie)19 BValue (org.ballerinalang.model.values.BValue)19 ChannelPromise (io.netty.channel.ChannelPromise)18