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();
}
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();
}
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"));
}
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);
}
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());
}
Aggregations