HttpDefaultHeaders class
Default header configuration.
class HttpDefaultHeaders { static String _defaultContentType = 'application/json;charset=utf-8'; Map _headers = { 'COMMON': { 'Accept': 'application/json, text/plain, */*' }, 'POST' : { 'Content-Type': _defaultContentType }, 'PUT' : { 'Content-Type': _defaultContentType }, 'PATCH' : { 'Content-Type': _defaultContentType } }; _applyHeaders(method, ucHeaders, headers) { if (!_headers.containsKey(method)) return; _headers[method].forEach((k, v) { if (!ucHeaders.contains(k.toUpperCase())) { headers[k] = v; } }); } /** * Called from [Http], this method sets default headers on [headers] */ setHeaders(Map<String, String> headers, String method) { assert(headers != null); var ucHeaders = headers.keys.map((x) => x.toUpperCase()).toSet(); _applyHeaders('COMMON', ucHeaders, headers); _applyHeaders(method.toUpperCase(), ucHeaders, headers); } /** * Returns the default header [Map] for a method. You can then modify * the map. * * Passing 'common' as [method] will return a Map that contains headers * common to all operations. */ operator[](method) { return _headers[method.toUpperCase()]; } }
Operators
Methods
dynamic setHeaders(Map<String, String> headers, String method) #
Called from Http, this method sets default headers on headers
setHeaders(Map<String, String> headers, String method) { assert(headers != null); var ucHeaders = headers.keys.map((x) => x.toUpperCase()).toSet(); _applyHeaders('COMMON', ucHeaders, headers); _applyHeaders(method.toUpperCase(), ucHeaders, headers); }