示例#1
0
 /** Returns headers for a name value block containing a SPDY response. */
 public static RawHeaders fromNameValueBlock(List<String> nameValueBlock) throws IOException {
   if (nameValueBlock.size() % 2 != 0) {
     throw new IllegalArgumentException("Unexpected name value block: " + nameValueBlock);
   }
   String status = null;
   String version = null;
   Builder builder = new Builder();
   builder.set(ResponseHeaders.SELECTED_TRANSPORT, "spdy/3");
   for (int i = 0; i < nameValueBlock.size(); i += 2) {
     String name = nameValueBlock.get(i);
     String values = nameValueBlock.get(i + 1);
     for (int start = 0; start < values.length(); ) {
       int end = values.indexOf('\0', start);
       if (end == -1) {
         end = values.length();
       }
       String value = values.substring(start, end);
       if (":status".equals(name)) {
         status = value;
       } else if (":version".equals(name)) {
         version = value;
       } else {
         builder.namesAndValues.add(name);
         builder.namesAndValues.add(value);
       }
       start = end + 1;
     }
   }
   if (status == null) throw new ProtocolException("Expected ':status' header not present");
   if (version == null) throw new ProtocolException("Expected ':version' header not present");
   builder.setStatusLine(version + " " + status);
   return builder.build();
 }
示例#2
0
 /** Parses bytes of a response header from an HTTP transport. */
 public static RawHeaders readHttpHeaders(InputStream in) throws IOException {
   Builder builder;
   do {
     builder = new Builder();
     builder.set(ResponseHeaders.SELECTED_TRANSPORT, "http/1.1");
     builder.setStatusLine(Util.readAsciiLine(in));
     builder.readHeaders(in);
   } while (builder.responseCode == HttpEngine.HTTP_CONTINUE);
   return builder.build();
 }
 @Test
 public void testSetUnknownTag() {
   try {
     Builder builder = new YeastBuilderImpl();
     builder.set("ökldafs", "");
     Assert.fail();
   } catch (UnknownTagException ex) {
     Assert.assertTrue(true);
   } catch (ParseException ex) {
     Assert.fail();
   }
 }