private boolean validateUriHeader(Fields headers) { Fields.Field uriHeader = headers.get(HTTPSPDYHeader.URI.name(version)); if (uriHeader != null) if (version == SPDY.V2 && uriHeader.value().startsWith("http://")) return true; else if (version == SPDY.V3 && uriHeader.value().startsWith("/") && headers.get(HTTPSPDYHeader.HOST.name(version)) != null && headers.get(HTTPSPDYHeader.SCHEME.name(version)) != null) return true; System.out.println(HTTPSPDYHeader.URI.name(version) + " not valid!"); return false; }
private boolean validateHeader(Fields headers, String name, String expectedValue) { Fields.Field header = headers.get(name); if (header != null && expectedValue.equals(header.value())) return true; System.out.println( name + " not valid! Expected: " + expectedValue + " headers received:" + headers); return false; }
@Override public void reply(ReplyInfo replyInfo, Callback handler) { try { Fields headers = new Fields(replyInfo.getHeaders(), false); headers.remove(HTTPSPDYHeader.SCHEME.name(version)); String status = headers.remove(HTTPSPDYHeader.STATUS.name(version)).value(); Matcher matcher = statusRegexp.matcher(status); matcher.matches(); int code = Integer.parseInt(matcher.group(1)); String reason = matcher.group(2).trim(); HttpVersion httpVersion = HttpVersion.fromString(headers.remove(HTTPSPDYHeader.VERSION.name(version)).value()); // Convert the Host header from a SPDY special header to a normal header Fields.Field host = headers.remove(HTTPSPDYHeader.HOST.name(version)); if (host != null) headers.put("host", host.value()); HttpFields fields = new HttpFields(); for (Fields.Field header : headers) { String name = camelize(header.name()); fields.put(name, header.value()); } // TODO: handle better the HEAD last parameter HttpGenerator.ResponseInfo info = new HttpGenerator.ResponseInfo(httpVersion, fields, -1, code, reason, false); send(info, null, replyInfo.isClose()); if (replyInfo.isClose()) completed(); handler.succeeded(); } catch (IOException x) { handler.failed(x); } }