org.eclipse.jetty.http.MetaData.Response Java Examples

The following examples show how to use org.eclipse.jetty.http.MetaData.Response. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HeadersFrame.java    From PacketProxy with Apache License 2.0 4 votes vote down vote up
private void decodeToHttp(HpackDecoder decoder) throws Exception {
	if ((super.flags & FLAG_EXTRA) > 0) {
		return;
	}
	if (decoder == null) {
		return;
	}
   	ByteBuffer in = ByteBuffer.allocate(65535);
   	in.put(super.payload);
   	in.flip();
   	
   	if ((super.flags & FLAG_PRIORITY) > 0) {
   		priority = true;
   		dependency = in.getInt() & 0x7fffffff;
   		weight = in.get();
   	}

   	MetaData meta = decoder.decode(in);

   	isGRPC2ndResponseHeader = false;

   	if (meta instanceof Request) {
   		//System.out.println("# meta.request: " + meta);
   		bRequest = true;
   		Request req = (Request)meta;
   		method = req.getMethod();
   		version = req.getHttpVersion();
   		uriString = req.getURIString();
   		HttpURI uri = req.getURI();
   		scheme = uri.getScheme();
   		authority = uri.getAuthority();
   		path = uri.getPath();
   		query = uri.getQuery();
   		
   	} else if (meta instanceof Response) {
   		//System.out.println("# meta.response: " + meta);
   		bResponse = true;
   		Response res = (Response)meta;
   		status = res.getStatus();
   	} else {
   		//gRPC Trailer Frame
  			bTrailer = true;
   	}
   	fields = meta.getFields();

   	if(bTrailer){
   		for(HttpField i:fields){
   			if(i.getName().contains("grpc-status")){
   				isGRPC2ndResponseHeader = true;
   				break;
			}
		}
	}
   	
	ByteArrayOutputStream buf = new ByteArrayOutputStream();
	if (bRequest) {
		String queryStr = (query != null && query.length() > 0) ? "?" + query : "";
		//String fragmentStr = (fragment != null && fragment.length() > 0) ? "#"+fragment : "";
		String statusLine = String.format("%s %s%s HTTP/2\r\n", method, path, queryStr);
		buf.write(statusLine.getBytes());
	} else {
		buf.write(String.format("HTTP/2 %d %s\r\n", status, HttpStatus.getMessage(status)).getBytes());
	}
	for (HttpField field: fields) {
		buf.write(String.format("%s: %s\r\n", field.getName(), field.getValue()).getBytes());
	}
	if(!isGRPC2ndResponseHeader) {
		if (bRequest) {
			buf.write(String.format("X-PacketProxy-HTTP2-Host: %s\r\n", authority).getBytes());
		}
		if (priority) {
			buf.write(String.format("X-PacketProxy-HTTP2-Dependency: %d\r\n", dependency).getBytes());
			buf.write(String.format("X-PacketProxy-HTTP2-Weight: %d\r\n", weight & 0xff).getBytes());
		}
		buf.write(String.format("X-PacketProxy-HTTP2-Stream-Id: %d\r\n", streamId).getBytes());
		buf.write(String.format("X-PacketProxy-HTTP2-Flags: %d\r\n", flags).getBytes());
		buf.write(String.format("X-PacketProxy-HTTP2-UUID: %s\r\n", StringUtils.randomUUID()).getBytes());
	}
	buf.write("\r\n".getBytes());

   	saveExtra(buf.toByteArray());
}
 
Example #2
Source File: HttpResponseStatisticsCollectorTest.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
public void send(Response info, boolean head, ByteBuffer content, boolean lastContent, Callback callback) {
    callback.succeeded();
}