use of org.wso2.transport.http.netty.message.Http2PushPromise in project ballerina by ballerina-lang.
the class GetHeaders 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);
context.setReturnValues(new BStringArray(http2PushPromise.getHeaders(headerName)));
}
use of org.wso2.transport.http.netty.message.Http2PushPromise in project ballerina by ballerina-lang.
the class HttpUtil method createHttpPushPromise.
/**
* Creates native {@code Http2PushPromise} from PushPromise struct.
*
* @param struct the PushPromise struct
* @return the populated the native {@code Http2PushPromise}
*/
public static Http2PushPromise createHttpPushPromise(BStruct struct) {
String method = struct.getStringField(HttpConstants.PUSH_PROMISE_METHOD_INDEX);
if (method == null || method.isEmpty()) {
method = HttpConstants.HTTP_METHOD_GET;
}
String path = struct.getStringField(HttpConstants.PUSH_PROMISE_PATH_INDEX);
if (path == null || path.isEmpty()) {
path = HttpConstants.DEFAULT_BASE_PATH;
}
return new Http2PushPromise(method, path);
}
use of org.wso2.transport.http.netty.message.Http2PushPromise in project ballerina by ballerina-lang.
the class HttpUtil method getPushPromise.
/**
* Gets the {@code Http2PushPromise} represented by the PushPromise struct.
*
* @param pushPromiseStruct the push promise struct
* @param defaultPushPromise the Http2PushPromise to use if the struct does not have native data of a push promise
* @return the {@code Http2PushPromise} represented by the PushPromise struct
*/
public static Http2PushPromise getPushPromise(BStruct pushPromiseStruct, Http2PushPromise defaultPushPromise) {
Http2PushPromise pushPromise = (Http2PushPromise) pushPromiseStruct.getNativeData(HttpConstants.TRANSPORT_PUSH_PROMISE);
if (pushPromise != null) {
return pushPromise;
}
pushPromiseStruct.addNativeData(HttpConstants.TRANSPORT_PUSH_PROMISE, defaultPushPromise);
return defaultPushPromise;
}
use of org.wso2.transport.http.netty.message.Http2PushPromise in project ballerina by ballerina-lang.
the class PushPromiseNativeFunctionTest method testAddHeader.
@Test(description = "Test addHeader function of PushPromise")
public void testAddHeader() {
BStruct promise = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, promiseStruct);
String headerName = "header1";
String headerValue = "value1";
BString key = new BString(headerName);
BString value = new BString(headerValue);
BValue[] inputArg = { promise, key, value };
BValue[] returnVal = BRunUtil.invoke(result, "testAddHeader", inputArg);
Assert.assertFalse(returnVal == null || returnVal.length == 0 || returnVal[0] == null, "Invalid Return Values.");
Assert.assertTrue(returnVal[0] instanceof BStruct);
Http2PushPromise http2PushPromise = (Http2PushPromise) ((BStruct) returnVal[0]).getNativeData(HttpConstants.TRANSPORT_PUSH_PROMISE);
Assert.assertEquals(http2PushPromise.getHeader(headerName), headerValue);
}
use of org.wso2.transport.http.netty.message.Http2PushPromise in project ballerina by ballerina-lang.
the class PushPromiseNativeFunctionTest method testGetHeaders.
@Test(description = "Test getHeaders function of PushPromise")
public void testGetHeaders() {
BStruct promise = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, promiseStruct);
Http2PushPromise http2PushPromise = new Http2PushPromise(HttpConstants.HTTP_METHOD_GET, HttpConstants.DEFAULT_BASE_PATH);
String headerName = "header";
String headerValue1 = "value1";
String headerValue2 = "value2";
http2PushPromise.addHeader(headerName, headerValue1);
http2PushPromise.addHeader(headerName, headerValue2);
HttpUtil.populatePushPromiseStruct(promise, http2PushPromise);
BString key = new BString(headerName);
BValue[] inputArg = { promise, key };
BValue[] returnVal = BRunUtil.invoke(result, "testGetHeaders", inputArg);
Assert.assertFalse(returnVal == null || returnVal.length == 0 || returnVal[0] == null, "Invalid Return Values.");
Assert.assertEquals(((BStringArray) returnVal[0]).get(0), headerValue1);
Assert.assertEquals(((BStringArray) returnVal[0]).get(1), headerValue2);
}
Aggregations