'Allow callers to configure the stub server using the /set_config URL.
The request should have POST data, such that:
Each POST parameter is the configuration key.
Each POST value is a JSON-encoded string value for the configuration.'

def do_PUT(self):

    if ((self.path == '/set_config') or (self.path == '/set_config/')):
        if (len(self.post_dict) > 0):
            for (key, value) in self.post_dict.iteritems():
                try:
                    key = unicode(key, 'utf-8')
                    value = unicode(value, 'utf-8')
                except UnicodeDecodeError:
                    self.log_message('Could    not    decode    request    params    as    UTF-8')
                self.log_message(u"Set    config    '{0}'    to    '{1}'".format(key, value))
                try:
                    value = json.loads(value)
                except ValueError:
                    self.log_message(u'Could    not    parse    JSON:    {0}'.format(value))
                    self.send_response(400)
                else:
                    self.server.config[key] = value
                    self.send_response(200)
        else:
            self.send_response(200)
    else:
        self.send_response(404)
