use of org.wso2.transport.http.netty.message.Http2PushPromise in project ballerina by ballerina-lang.
the class PushPromiseNativeFunctionTest method testSetHeader.
@Test(description = "Test setHeader function of PushPromise")
public void testSetHeader() {
BStruct promise = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, promiseStruct);
Http2PushPromise http2PushPromise = new Http2PushPromise(HttpConstants.HTTP_METHOD_GET, HttpConstants.DEFAULT_BASE_PATH);
String headerName = "header1";
String headerValue = "value1";
http2PushPromise.addHeader(headerName, headerValue);
HttpUtil.populatePushPromiseStruct(promise, http2PushPromise);
String targetHeaderValue = "value2";
BString key = new BString(headerName);
BString value = new BString(targetHeaderValue);
BValue[] inputArg = { promise, key, value };
BValue[] returnVal = BRunUtil.invoke(result, "testSetHeader", inputArg);
Assert.assertFalse(returnVal == null || returnVal.length == 0 || returnVal[0] == null, "Invalid Return Values.");
Assert.assertTrue(returnVal[0] instanceof BStruct);
Http2PushPromise retrievedHttp2PushPromise = (Http2PushPromise) ((BStruct) returnVal[0]).getNativeData(HttpConstants.TRANSPORT_PUSH_PROMISE);
Assert.assertEquals(retrievedHttp2PushPromise.getHeader(headerName), targetHeaderValue);
}
use of org.wso2.transport.http.netty.message.Http2PushPromise in project ballerina by ballerina-lang.
the class PushPromiseNativeFunctionTest method testRemoveHeader.
@Test(description = "Test removeHeader function of PushPromise")
public void testRemoveHeader() {
BStruct promise = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, promiseStruct);
Http2PushPromise http2PushPromise = new Http2PushPromise(HttpConstants.HTTP_METHOD_GET, HttpConstants.DEFAULT_BASE_PATH);
String headerName = "header1";
String headerValue = "value1";
http2PushPromise.addHeader(headerName, headerValue);
HttpUtil.populatePushPromiseStruct(promise, http2PushPromise);
BString key = new BString(headerName);
BValue[] inputArg = { promise, key };
BValue[] returnVal = BRunUtil.invoke(result, "testRemoveHeader", inputArg);
Assert.assertFalse(returnVal == null || returnVal.length == 0 || returnVal[0] == null, "Invalid Return Values.");
Assert.assertTrue(returnVal[0] instanceof BStruct);
Http2PushPromise retrievedHttp2PushPromise = (Http2PushPromise) ((BStruct) returnVal[0]).getNativeData(HttpConstants.TRANSPORT_PUSH_PROMISE);
Assert.assertNull(retrievedHttp2PushPromise.getHeader(headerName));
}
use of org.wso2.transport.http.netty.message.Http2PushPromise in project ballerina by ballerina-lang.
the class PushPromiseNativeFunctionTest method testRemoveAllHeaders.
@Test(description = "Test removeAllHeaders function of PushPromise")
public void testRemoveAllHeaders() {
BStruct promise = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, promiseStruct);
Http2PushPromise http2PushPromise = new Http2PushPromise(HttpConstants.HTTP_METHOD_GET, HttpConstants.DEFAULT_BASE_PATH);
String header1Name = "header1";
String header1Value = "value1";
http2PushPromise.addHeader(header1Name, header1Value);
String header2Name = "header2";
String header2Value = "value2";
http2PushPromise.addHeader(header2Name, header2Value);
HttpUtil.populatePushPromiseStruct(promise, http2PushPromise);
BValue[] inputArg = { promise };
BValue[] returnVal = BRunUtil.invoke(result, "testRemoveAllHeaders", inputArg);
Assert.assertFalse(returnVal == null || returnVal.length == 0 || returnVal[0] == null, "Invalid Return Values.");
Assert.assertTrue(returnVal[0] instanceof BStruct);
Http2PushPromise retrievedHttp2PushPromise = (Http2PushPromise) ((BStruct) returnVal[0]).getNativeData(HttpConstants.TRANSPORT_PUSH_PROMISE);
Assert.assertNull(retrievedHttp2PushPromise.getHeader(header1Name));
Assert.assertNull(retrievedHttp2PushPromise.getHeader(header2Name));
}
use of org.wso2.transport.http.netty.message.Http2PushPromise in project ballerina by ballerina-lang.
the class RejectPromise method execute.
@Override
public void execute(Context context, CallableUnitCallback callback) {
BStruct pushPromiseStruct = (BStruct) context.getRefArgument(1);
Http2PushPromise http2PushPromise = HttpUtil.getPushPromise(pushPromiseStruct, null);
if (http2PushPromise == null) {
throw new BallerinaException("invalid push promise");
}
BStruct bConnector = (BStruct) context.getRefArgument(0);
HttpClientConnector clientConnector = (HttpClientConnector) bConnector.getNativeData(HttpConstants.HTTP_CLIENT);
clientConnector.rejectPushResponse(http2PushPromise);
// TODO: Implement a listener to see the progress
context.setReturnValues(new BBoolean(true));
callback.notifySuccess();
}
use of org.wso2.transport.http.netty.message.Http2PushPromise in project ballerina by ballerina-lang.
the class AddHeader method execute.
@Override
public void execute(Context context) {
BStruct pushPromiseStruct = (BStruct) context.getRefArgument(0);
Http2PushPromise http2PushPromise = HttpUtil.getPushPromise(pushPromiseStruct, HttpUtil.createHttpPushPromise(pushPromiseStruct));
String headerName = context.getStringArgument(0);
String headerValue = context.getStringArgument(1);
http2PushPromise.addHeader(headerName, headerValue);
context.setReturnValues();
}
Aggregations