openhab/openhab — pull request #1371 by spali (2014-08-27 20:10:15+00:00)
Title: add optional headers functionality to http binding cache items in the main configuration file.

I know this is more a feature than a bug, but I would wish it on a stable code base, it can be used as soon as possible.
My use case is, that I need to send a login cookie in a HTTP request. Because I need several items with the same request, it makes sense to cache that, to be sure the box will won't explode due to many requests ;)

I made it with as less changes as possible, that's the reason why the ```parseHttpHeaders``` function now exists twice in the binding.
Let me know if I should change that and were you would like to have the public static ```parseHttpHeaders``` function in that case.

**One side note:**
I have seen that in the current code, ```Matcher``` is always used like this:
```
Matcher matcher = EXTRACT_CACHE_CONFIG_PATTERN.matcher(key);

if (!matcher.matches()) {
logger.error("given config key '"
+ key
+ "' does not follow the expected pattern '.'");
continue;
}
matcher.reset();
matcher.find();

String cacheId = matcher.group(1);
```
but in my opinion the following would do the same:
```
Matcher matcher = EXTRACT_CACHE_CONFIG_PATTERN.matcher(key);

if (!matcher.matches()) {
logger.error("given config key '"
+ key
+ "' does not follow the expected pattern '.'");
continue;
}

String cacheId = matcher.group(1);
```
What me confused, was that I sometimes hat trouble with the first example, but didn't find a good reason why. In my opinion both should work, but the first has a bit overhead.
Maybe I can learn something new and get an explanation, because I'm not a full time java developer :)

Let me know if i should change anything and would be great if this pull request would find the way to master to (or do I need to pull it there too?)

**A second side note:**
If I find the time to extend this a bit more, I would also suggest to allow REGEX in the cache item, so the retrieved string could be stripped down to the minimum required in the cache to save memory. Because if you rely heavily on cache item from damn big ugly html sites, than this would consume a lot of memory, especially for embedded devices.