OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library shelf.util; | 5 library shelf.util; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 /// | 33 /// |
34 /// For keys that are the same between [original] and [updates], the value in | 34 /// For keys that are the same between [original] and [updates], the value in |
35 /// [updates] is used. | 35 /// [updates] is used. |
36 /// | 36 /// |
37 /// If [updates] is `null` or empty, [original] is returned unchanged. | 37 /// If [updates] is `null` or empty, [original] is returned unchanged. |
38 Map updateMap(Map original, Map updates) { | 38 Map updateMap(Map original, Map updates) { |
39 if (updates == null || updates.isEmpty) return original; | 39 if (updates == null || updates.isEmpty) return original; |
40 | 40 |
41 return new Map.from(original)..addAll(updates); | 41 return new Map.from(original)..addAll(updates); |
42 } | 42 } |
| 43 |
| 44 /// Adds a header with [name] and [value] to [headers], which may be null. |
| 45 /// |
| 46 /// Returns a new map without modifying [headers]. |
| 47 Map<String, String> addHeader( |
| 48 Map<String, String> headers, String name, String value) { |
| 49 headers = headers == null ? {} : new Map.from(headers); |
| 50 headers[name] = value; |
| 51 return headers; |
| 52 } |
OLD | NEW |