@Override protected Response<String> parseNetworkResponse(NetworkResponse response) { String parsed; try { parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); } catch (UnsupportedEncodingException e) { parsed = new String(response.data); } return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response)); } }
serverDate = parseDateAsEpoch(headerValue); serverExpires = parseDateAsEpoch(headerValue); lastModified = parseDateAsEpoch(headerValue);
@Override protected Response<byte[]> parseNetworkResponse(NetworkResponse response) { if (!isCanceled()) { callback.onDataReady(new ByteArrayInputStream(response.data)); } return Response.success(response.data, HttpHeaderParser.parseCacheHeaders(response)); }
/** * Returns the charset specified in the Content-Type of this header, * or the HTTP default (ISO-8859-1) if none can be found. */ public static String parseCharset(Map<String, String> headers) { return parseCharset(headers, HTTP.DEFAULT_CONTENT_CHARSET); } }
return Response.error(new ParseError(response)); } else { return Response.success(bitmap, HttpHeaderParser.parseCacheHeaders(response));
/** * Returns the charset specified in the Content-Type of this header, * or the HTTP default (ISO-8859-1) if none can be found. */ public static String parseCharset(Map<String, String> headers) { return parseCharset(headers, HTTP.DEFAULT_CONTENT_CHARSET); } }
@Override protected Response<String> parseNetworkResponse(NetworkResponse response) { String parsed; try { parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); } catch (UnsupportedEncodingException e) { parsed = new String(response.data); } return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response)); } }
return Response.error(new ParseError(response)); } else { return Response.success(bitmap, HttpHeaderParser.parseCacheHeaders(response));
/** * 全部转成默认UTF-8 * Returns the charset specified in the Content-Type of this header, * or the HTTP default (ISO-8859-1) if none can be found. */ public static String parseCharset(Map<String, String> headers) { //return parseCharset(headers, HTTP.DEFAULT_CONTENT_CHARSET); return parseCharset(headers, Request.DEFAULT_PARAMS_ENCODING); } }
serverDate = parseDateAsEpoch(headerValue); serverExpires = parseDateAsEpoch(headerValue); lastModified = parseDateAsEpoch(headerValue);
@Override protected Response<String> parseNetworkResponse(NetworkResponse response) { String parsed; try { parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); } catch (UnsupportedEncodingException e) { parsed = new String(response.data); } return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response)); } }
return Response.error(new ParseError(response)); } else { return Response.success(bitmap, HttpHeaderParser.parseCacheHeaders(response));
@Test public void parseCharset() { assertEquals("utf-8", HttpHeaderParser.parseCharset(headers)); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers, "ISO-8859-1")); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers)); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers)); assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers)); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers, "utf-8")); assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers)); assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers)); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers, "utf-8")); assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers));
serverDate = parseDateAsEpoch(headerValue); serverExpires = parseDateAsEpoch(headerValue); lastModified = parseDateAsEpoch(headerValue);
@Override protected Response<T> parseNetworkResponse(NetworkResponse response) { String parsed; try { parsed = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); } catch (UnsupportedEncodingException e) { parsed = new String(response.data); } T t = mGson.fromJson(parsed, mClazz); //TODO try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } return Response.success(t, HttpHeaderParser.parseCacheHeaders(response)); }
@Test public void parseCacheHeaders_cacheControlNoCache() { long now = System.currentTimeMillis(); headers.put("Date", rfc1123Date(now)); headers.put("Expires", rfc1123Date(now + ONE_HOUR_MILLIS)); headers.put("Cache-Control", "no-cache"); Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response); assertNull(entry); }
@Test public void parseCharset() { assertEquals("utf-8", HttpHeaderParser.parseCharset(headers)); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers, "ISO-8859-1")); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers)); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers)); assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers)); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers, "utf-8")); assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers)); assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers)); assertEquals("utf-8", HttpHeaderParser.parseCharset(headers, "utf-8")); assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers));
@Override protected Response<T> parseNetworkResponse(NetworkResponse response) { try { String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers)); TLog.d(TAG, "response ---> " + jsonString); return Response.success((T) mGson.fromJson(jsonString, mType), HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new VolleyError(e)); } }
@Test public void parseCacheHeaders_cacheControlNoCache() { long now = System.currentTimeMillis(); headers.put("Date", rfc1123Date(now)); headers.put("Expires", rfc1123Date(now + ONE_HOUR_MILLIS)); headers.put("Cache-Control", "no-cache"); Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response); assertNull(entry); }
/** * Returns the charset specified in the Content-Type of this header, * or the HTTP default (ISO-8859-1) if none can be found. */ public static String parseCharset(Map<String, String> headers) { return parseCharset(headers, HTTP.DEFAULT_CONTENT_CHARSET); } }