熟悉 ExNewResponse 接口
ExNewRequest 接口,用于在网关过滤时,修改(或构建)响应数据。
public class ExNewResponse {
private int status = 200;
private MultiMap<String> headers = new MultiMap<>();
private ExBody body;
public void status(int code) {
this.status = code;
}
/**
* 配置头(替换)
*/
public ExNewResponse header(String key, String... values) {
headers.holder(key).setValues(values);
return this;
}
/**
* 配置头(替换)
*/
public ExNewResponse header(String key, List<String> values) {
headers.holder(key).setValues(values);
return this;
}
/**
* 添加头(添加)
*/
public ExNewResponse headerAdd(String key, String value) {
headers.holder(key).addValue(value);
return this;
}
/**
* 移除头
*/
public ExNewResponse headerRemove(String... keys) {
for (String key : keys) {
headers.remove(key);
}
return this;
}
/**
* 跳转
*/
public ExNewResponse redirect(int code, String url) {
status(code);
header(HeaderNames.HEADER_LOCATION, url);
return this;
}
/**
* 配置主体(方便用户修改)
*
* @param body 主体数据
*/
public ExNewResponse body(Buffer body) {
this.body = new ExBodyOfBuffer(body);
return this;
}
/**
* 配置主体(实现流式转发)
*
* @param body 主体数据
*/
public ExNewResponse body(ReadStream<Buffer> body) {
this.body = new ExBodyOfStream(body);
return this;
}
/**
* 获取状态
*/
public int getStatus() {
return status;
}
/**
* 获取头集合
*/
public MultiMap<String> getHeaders() {
return headers;
}
/**
* 获取主体
*/
public ExBody getBody() {
return body;
}
}