@Override public void fromHeaders(MutableContentMetadata contentMetadata, Multimap<String, String> headers) { boolean chunked = any(headers.entries(), new Predicate<Entry<String, String>>() { @Override public boolean apply(Entry<String, String> input) { return "Transfer-Encoding".equalsIgnoreCase(input.getKey()) && "chunked".equalsIgnoreCase(input.getValue()); } }); for (Entry<String, String> header : headers.entries()) { if (CACHE_CONTROL.equalsIgnoreCase(header.getKey())) { contentMetadata.setCacheControl(header.getValue()); } else if (!chunked && CONTENT_LENGTH.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentLength(Long.valueOf(header.getValue())); } else if (CONTENT_MD5.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentMD5(base64().decode(header.getValue())); } else if (CONTENT_TYPE.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentType(header.getValue()); } else if (CONTENT_DISPOSITION.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentDisposition(header.getValue()); } else if (CONTENT_ENCODING.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentEncoding(header.getValue()); } else if (CONTENT_LANGUAGE.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentLanguage(header.getValue()); } else if (EXPIRES.equalsIgnoreCase(header.getKey())) { contentMetadata.setExpires(parseExpires(header.getValue())); } } }
@Override public Multimap<String, String> toHeaders(ContentMetadata md) { Builder<String, String> builder = ImmutableMultimap.builder(); if (md.getContentType() != null) builder.put(CONTENT_TYPE, md.getContentType()); if (md.getContentDisposition() != null) builder.put(CONTENT_DISPOSITION, md.getContentDisposition()); if (md.getContentEncoding() != null) builder.put(CONTENT_ENCODING, md.getContentEncoding()); if (md.getContentLanguage() != null) builder.put(CONTENT_LANGUAGE, md.getContentLanguage()); if (md.getContentLength() != null) builder.put(CONTENT_LENGTH, md.getContentLength() + ""); if (md.getContentMD5() != null) builder.put(CONTENT_MD5, base64().encode(md.getContentMD5())); if (md.getExpires() != null) builder.put(EXPIRES, getExpiresDateCodec().toString(md.getExpires())); return builder.build(); }
@Override public void fromHeaders(MutableContentMetadata contentMetadata, Multimap<String, String> headers) { boolean chunked = any(headers.entries(), new Predicate<Entry<String, String>>() { @Override public boolean apply(Entry<String, String> input) { return "Transfer-Encoding".equalsIgnoreCase(input.getKey()) && "chunked".equalsIgnoreCase(input.getValue()); } }); for (Entry<String, String> header : headers.entries()) { if (CACHE_CONTROL.equalsIgnoreCase(header.getKey())) { contentMetadata.setCacheControl(header.getValue()); } else if (!chunked && CONTENT_LENGTH.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentLength(Long.valueOf(header.getValue())); } else if (CONTENT_MD5.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentMD5(base64().decode(header.getValue())); } else if (CONTENT_TYPE.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentType(header.getValue()); } else if (CONTENT_DISPOSITION.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentDisposition(header.getValue()); } else if (CONTENT_ENCODING.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentEncoding(header.getValue()); } else if (CONTENT_LANGUAGE.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentLanguage(header.getValue()); } else if (EXPIRES.equalsIgnoreCase(header.getKey())) { contentMetadata.setExpires(parseExpires(header.getValue())); } } }
/** * Parses the date from the given Expires header. * <p> * According to the RFC, dates should always come in RFC-1123 format. * However, clients should also support older and deprecated formats for * compatibility, so this method will try to parse an RFC-1123 date, and * fallback to the ANSI C format. * * @see https://tools.ietf.org/html/rfc2616#section-3.3 */ public Date parseExpires(String expires) { if (expires == null) return null; for (DateCodec decoder : getExpiresDateDecoders()) { try { return decoder.toDate(expires); } catch (IllegalArgumentException ex) { logger.trace("Expires header (%s) is not in the expected %s format", expires, decoder); // Continue trying the other decoders } } logger.debug("Invalid Expires header (%s); should be in RFC-1123 format; treating as already expired", expires); return new Date(0); } }
@Override public void fromHeaders(MutableContentMetadata contentMetadata, Multimap<String, String> headers) { boolean chunked = any(headers.entries(), new Predicate<Entry<String, String>>() { @Override public boolean apply(Entry<String, String> input) { return "Transfer-Encoding".equalsIgnoreCase(input.getKey()) && "chunked".equalsIgnoreCase(input.getValue()); } }); for (Entry<String, String> header : headers.entries()) { if (CACHE_CONTROL.equalsIgnoreCase(header.getKey())) { contentMetadata.setCacheControl(header.getValue()); } else if (!chunked && CONTENT_LENGTH.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentLength(Long.valueOf(header.getValue())); } else if (CONTENT_MD5.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentMD5(base64().decode(header.getValue())); } else if (CONTENT_TYPE.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentType(header.getValue()); } else if (CONTENT_DISPOSITION.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentDisposition(header.getValue()); } else if (CONTENT_ENCODING.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentEncoding(header.getValue()); } else if (CONTENT_LANGUAGE.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentLanguage(header.getValue()); } else if (EXPIRES.equalsIgnoreCase(header.getKey())) { contentMetadata.setExpires(parseExpires(header.getValue())); } } }
/** * Parses the date from the given Expires header. * <p> * According to the RFC, dates should always come in RFC-1123 format. * However, clients should also support older and deprecated formats for * compatibility, so this method will try to parse an RFC-1123 date, and * fallback to the ANSI C format. * * @see https://tools.ietf.org/html/rfc2616#section-3.3 */ public Date parseExpires(String expires) { if (expires == null) return null; for (DateCodec decoder : getExpiresDateDecoders()) { try { return decoder.toDate(expires); } catch (IllegalArgumentException ex) { logger.trace("Expires header (%s) is not in the expected %s format", expires, decoder); // Continue trying the other decoders } } logger.debug("Invalid Expires header (%s); should be in RFC-1123 format; treating as already expired", expires); return new Date(0); } }
@Override public void fromHeaders(MutableContentMetadata contentMetadata, Multimap<String, String> headers) { boolean chunked = any(headers.entries(), new Predicate<Entry<String, String>>() { @Override public boolean apply(Entry<String, String> input) { return "Transfer-Encoding".equalsIgnoreCase(input.getKey()) && "chunked".equalsIgnoreCase(input.getValue()); } }); for (Entry<String, String> header : headers.entries()) { if (!chunked && CONTENT_LENGTH.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentLength(Long.valueOf(header.getValue())); } else if (CONTENT_MD5.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentMD5(base64().decode(header.getValue())); } else if (CONTENT_TYPE.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentType(header.getValue()); } else if (CONTENT_DISPOSITION.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentDisposition(header.getValue()); } else if (CONTENT_ENCODING.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentEncoding(header.getValue()); } else if (CONTENT_LANGUAGE.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentLanguage(header.getValue()); } else if (EXPIRES.equalsIgnoreCase(header.getKey())) { contentMetadata.setExpires(parseExpires(header.getValue())); } } }
@Override public void fromHeaders(MutableContentMetadata contentMetadata, Multimap<String, String> headers) { boolean chunked = any(headers.entries(), new Predicate<Entry<String, String>>() { @Override public boolean apply(Entry<String, String> input) { return "Transfer-Encoding".equalsIgnoreCase(input.getKey()) && "chunked".equalsIgnoreCase(input.getValue()); } }); for (Entry<String, String> header : headers.entries()) { if (!chunked && CONTENT_LENGTH.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentLength(Long.valueOf(header.getValue())); } else if (CONTENT_MD5.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentMD5(base64().decode(header.getValue())); } else if (CONTENT_TYPE.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentType(header.getValue()); } else if (CONTENT_DISPOSITION.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentDisposition(header.getValue()); } else if (CONTENT_ENCODING.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentEncoding(header.getValue()); } else if (CONTENT_LANGUAGE.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentLanguage(header.getValue()); } else if (EXPIRES.equalsIgnoreCase(header.getKey())) { contentMetadata.setExpires(parseExpires(header.getValue())); } } }
@Override public void fromHeaders(MutableContentMetadata contentMetadata, Multimap<String, String> headers) { boolean chunked = any(headers.entries(), new Predicate<Entry<String, String>>() { @Override public boolean apply(Entry<String, String> input) { return "Transfer-Encoding".equalsIgnoreCase(input.getKey()) && "chunked".equalsIgnoreCase(input.getValue()); } }); for (Entry<String, String> header : headers.entries()) { if (!chunked && CONTENT_LENGTH.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentLength(Long.valueOf(header.getValue())); } else if (CONTENT_MD5.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentMD5(base64().decode(header.getValue())); } else if (CONTENT_TYPE.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentType(header.getValue()); } else if (CONTENT_DISPOSITION.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentDisposition(header.getValue()); } else if (CONTENT_ENCODING.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentEncoding(header.getValue()); } else if (CONTENT_LANGUAGE.equalsIgnoreCase(header.getKey())) { contentMetadata.setContentLanguage(header.getValue()); } else if (EXPIRES.equalsIgnoreCase(header.getKey())) { contentMetadata.setExpires(parseExpires(header.getValue())); } } }
@Override public Multimap<String, String> toHeaders(ContentMetadata md) { Builder<String, String> builder = ImmutableMultimap.builder(); if (md.getCacheControl() != null) builder.put(CACHE_CONTROL, md.getCacheControl()); if (md.getContentType() != null) builder.put(CONTENT_TYPE, md.getContentType()); if (md.getContentDisposition() != null) builder.put(CONTENT_DISPOSITION, md.getContentDisposition()); if (md.getContentEncoding() != null) builder.put(CONTENT_ENCODING, md.getContentEncoding()); if (md.getContentLanguage() != null) builder.put(CONTENT_LANGUAGE, md.getContentLanguage()); if (md.getContentLength() != null) builder.put(CONTENT_LENGTH, md.getContentLength() + ""); if (md.getContentMD5() != null) builder.put(CONTENT_MD5, base64().encode(md.getContentMD5())); if (md.getExpires() != null) builder.put(EXPIRES, getExpiresDateCodec().toString(md.getExpires())); return builder.build(); }
@Override public Multimap<String, String> toHeaders(ContentMetadata md) { Builder<String, String> builder = ImmutableMultimap.builder(); if (md.getCacheControl() != null) builder.put(CACHE_CONTROL, md.getCacheControl()); if (md.getContentType() != null) builder.put(CONTENT_TYPE, md.getContentType()); if (md.getContentDisposition() != null) builder.put(CONTENT_DISPOSITION, md.getContentDisposition()); if (md.getContentEncoding() != null) builder.put(CONTENT_ENCODING, md.getContentEncoding()); if (md.getContentLanguage() != null) builder.put(CONTENT_LANGUAGE, md.getContentLanguage()); if (md.getContentLength() != null) builder.put(CONTENT_LENGTH, md.getContentLength() + ""); if (md.getContentMD5() != null) builder.put(CONTENT_MD5, base64().encode(md.getContentMD5())); if (md.getExpires() != null) builder.put(EXPIRES, getExpiresDateCodec().toString(md.getExpires())); return builder.build(); }
@Override public Multimap<String, String> toHeaders(ContentMetadata md) { Builder<String, String> builder = ImmutableMultimap.builder(); if (md.getCacheControl() != null) builder.put(CACHE_CONTROL, md.getCacheControl()); if (md.getContentType() != null) builder.put(CONTENT_TYPE, md.getContentType()); if (md.getContentDisposition() != null) builder.put(CONTENT_DISPOSITION, md.getContentDisposition()); if (md.getContentEncoding() != null) builder.put(CONTENT_ENCODING, md.getContentEncoding()); if (md.getContentLanguage() != null) builder.put(CONTENT_LANGUAGE, md.getContentLanguage()); if (md.getContentLength() != null) builder.put(CONTENT_LENGTH, md.getContentLength() + ""); if (md.getContentMD5() != null) builder.put(CONTENT_MD5, base64().encode(md.getContentMD5())); if (md.getExpires() != null) builder.put(EXPIRES, getExpiresDateCodec().toString(md.getExpires())); return builder.build(); }
@Override public Multimap<String, String> toHeaders(ContentMetadata md) { Builder<String, String> builder = ImmutableMultimap.builder(); if (md.getContentType() != null) builder.put(CONTENT_TYPE, md.getContentType()); if (md.getContentDisposition() != null) builder.put(CONTENT_DISPOSITION, md.getContentDisposition()); if (md.getContentEncoding() != null) builder.put(CONTENT_ENCODING, md.getContentEncoding()); if (md.getContentLanguage() != null) builder.put(CONTENT_LANGUAGE, md.getContentLanguage()); if (md.getContentLength() != null) builder.put(CONTENT_LENGTH, md.getContentLength() + ""); if (md.getContentMD5() != null) builder.put(CONTENT_MD5, base64().encode(md.getContentMD5())); if (md.getExpires() != null) builder.put(EXPIRES, getExpiresDateCodec().toString(md.getExpires())); return builder.build(); }
@Override public Multimap<String, String> toHeaders(ContentMetadata md) { Builder<String, String> builder = ImmutableMultimap.builder(); if (md.getContentType() != null) builder.put(CONTENT_TYPE, md.getContentType()); if (md.getContentDisposition() != null) builder.put(CONTENT_DISPOSITION, md.getContentDisposition()); if (md.getContentEncoding() != null) builder.put(CONTENT_ENCODING, md.getContentEncoding()); if (md.getContentLanguage() != null) builder.put(CONTENT_LANGUAGE, md.getContentLanguage()); if (md.getContentLength() != null) builder.put(CONTENT_LENGTH, md.getContentLength() + ""); if (md.getContentMD5() != null) builder.put(CONTENT_MD5, base64().encode(md.getContentMD5())); if (md.getExpires() != null) builder.put(EXPIRES, getExpiresDateCodec().toString(md.getExpires())); return builder.build(); }
@BeforeTest void setupClient() { endPoint = URI.create("http://localhost:80/foo"); req = new ConvertToGaeRequest(new HttpUtils(0, 0, 0, 0), new DefaultContentMetadataCodec( new DateServiceDateCodecFactory(new SimpleDateFormatDateService()))); }
public void testFallbackToExpiredDate() { DefaultContentMetadataCodec codec = new DefaultContentMetadataCodec(codecfactory); Date parsed = codec.parseExpires("1994-12-01T16:00:00.000Z"); assertEquals(parsed, new Date(0)); } }
@BeforeTest void setupClient() { endPoint = URI.create("http://localhost:80/foo"); req = new ConvertToJcloudsResponse(new DefaultContentMetadataCodec(new DateServiceDateCodecFactory( new SimpleDateFormatDateService()))); }
public void testCanParseAsctimeDates() { DefaultContentMetadataCodec codec = new DefaultContentMetadataCodec(codecfactory); Date parsed = codec.parseExpires("Thu Dec 01 16:00:00 GMT 1994"); assertEquals(parsed, new Date(786297600000L)); }
public void testCanParseRFC1123Dates() { DefaultContentMetadataCodec codec = new DefaultContentMetadataCodec(codecfactory); Date parsed = codec.parseExpires("Thu, 01 Dec 1994 16:00:00 GMT"); assertEquals(parsed, new Date(786297600000L)); }
public Date parseExpires(String expires) { try { return (expires != null) ? getExpiresDateCodec().toDate(expires) : null; } catch (IllegalArgumentException e) { logger.debug("Invalid Expires header (%s); should be in RFC-1123 format; treating as already expired: %s", expires, e.getMessage()); return new Date(0); } } }