Handle headers and json for us :3
547802
def get_json(uri):
    
    response = requests.get(API + uri, headers=HEADERS)

    limit = int(response.headers.get("x-ratelimit-remaining"))
    if limit == 0:
        sys.stdout.write("\n")
        message = "You have run out of GitHub request tokens. "

        if int(response.headers.get("x-ratelimit-limit")) == 60:
            message += "Set a GITHUB_TOKEN to increase your limit to 5000/hour. "

        wait_seconds = int(response.headers.get("x-ratelimit-reset")) - int(time.time())
        wait_minutes = math.ceil(wait_seconds / 60)
        message += "Try again in ~%d minutes. " % wait_minutes

        if "--wait-for-reset" in sys.argv:
            progress_message(message.replace("Try ", "Trying "))
            time.sleep(wait_seconds + 1)
            progress_message("Resuming")
            return get_json(uri)
        else:
            raise ValueError(message)

    progress()
    return response.json()
724486
def execute_internal(json_request, &block)

      if json_request.respond_to?(:headers) then
        # always required for posting to API
        json_request.headers["Content-Type"] = "application/json"
      end

      req = HTTPI::Request.new(:url => @uri, :body => json_request.to_wire)

      # add in extra headers if we have a SignedJsonRequest (or anything which has additional headers)
      if json_request.respond_to? :headers then
        req.headers.merge!(json_request.headers)
      end

      if block then
        # execute request with block
        req.on_body(&block)
        HTTPI.post(req)
        return JsonResponse.new("success")

      else
        # execute normal req, and return parsed response
        res = HTTPI.post(req).body
        return JsonResponse.from_json(res)
      end


    end
553977
def success(headers = None, data = ''):
    
    passed_headers = {} if headers is None else headers
    if isinstance(data, dict): data = json.dumps(data)
    ret_headers = {'status' : 'ok'}
    ret_headers.update(passed_headers)
    return server_responce(ret_headers, data)
687360
function(key, value) {
          const key2 = key.toLowerCase().replace(/[^a-z0-9]/ig, '');
          res.serverassist.headers[key]    = value;
          res.serverassist.headers2[key2]  = value;
        }
978366
def select_header_accept(accepts)
      if accepts.empty?
        return
      elsif accepts.any?{ |s| s.casecmp('application/json') == 0 }
        'application/json' # look for json data by default
      else
        accepts.join(',')
      end
    end
832453
def process_header(raw)
      # this util gives us arrays of values. We are only set up to handle one header value.
      WEBrick::HTTPUtils.parse_header(raw.strip).map.inject({}) do |h,(k,v)|
        h[k]=v.first; h
      end
    end
645621
def post(path, body = '', headers = {})
      headers = { 'Content-Type' => 'application/json' }.merge(headers)
      request(:post, path, body, merge_default_headers(headers))
    end
202665
function parseResponseHeaders (headers) {
  var parsed = {};

  if (headers) {
    headers.split('\n').forEach(function (line) {
      var separatorIndex = line.indexOf(':');
      var key = line.substr(0, separatorIndex).trim().toLowerCase();
      var value = line.substr(separatorIndex + 1).trim().toLowerCase();

      if (key) {
        parsed[key] = value;
      }
    });
  }

  return parsed;
}
890502
function setHeadersFromObject (res, headers) {
  var keys = Object.keys(headers)
  for (var i = 0; i < keys.length; i++) {
    var k = keys[i]
    if (k) res.setHeader(k, headers[k])
  }
}
567705
function evalheaders(json, type) {
		var id = json.$originalid || json.$instanceid;
		delete json.$instanceid;
		delete json.$originalid;
		if (id) {
			Object.defineProperty(type, "$originalid", gui.Property.nonenumerable({
				value: id
			}));
		}
	}
978930
function parseHeaders(headers) {
  var parsed = createMap(), i;

  function fillInParsed(key, val) {
    if (key) {
      parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
    }
  }

  if (isString(headers)) {
    forEach(headers.split('\n'), function(line) {
      i = line.indexOf(':');
      fillInParsed(lowercase(trim(line.substr(0, i))), trim(line.substr(i + 1)));
    });
  } else if (isObject(headers)) {
    forEach(headers, function(headerVal, headerKey) {
      fillInParsed(lowercase(headerKey), trim(headerVal));
    });
  }

  return parsed;
}
828264
function onHeaders(ev, status, newUrl, oldUrl, statusCode, method, referrer, headers, resourceType) {
    if (resourceType !== 'mainFrame') return;

    let headerArray = [];

    Object.keys(headers).forEach(name => {
      headers[name].forEach(value => {
        headerArray.push({ name, value });
      });
    });

    response = {
      url: newUrl,
      method,
      status: statusCode,
      contentType: headers['content-type'][0],
      headers: headerArray
    };

    notify([ 'header event', status, newUrl, oldUrl, statusCode, method, referrer, headers, resourceType ]);
  }
287110
def get_from_headers(request, key):
    
    value = request.headers.get(key)
    return to_native(value)
1022535
def handle_header_and_return(header, id)
      if header
        header = header_to_json(header)
        bytes = header[:bytes]

        # Read more bytes (the actual response body)
        res = @out.read(bytes.to_i)

        if header[:method] == "highlight"
          # Make sure we have a result back; else consider this an error.
          if res.nil?
            @log.warn "No highlight result back from mentos."
            stop "No highlight result back from mentos."
            raise MentosError, "No highlight result back from mentos."
          end

          # Remove the newline from Python
          res = res[0..-2]
          @log.info "Highlight in process."

          # Get the id's
          start_id = res[0..7]
          end_id = res[-8..-1]

          # Sanity check.
          if not (start_id == id and end_id == id)
            @log.error "ID's did not match. Aborting."
            stop "ID's did not match. Aborting."
            raise MentosError, "ID's did not match. Aborting."
          else
            # We're good. Remove the padding
            res = res[10..-11]
            @log.info "Highlighting complete."
            res
          end
        end
        res
      else
        @log.error "No header data back."
        stop "No header data back."
        raise MentosError, "No header received back."
      end
    end
458032
function formatUserJSHeader(metadata) {
  const JSmeta = JSON.parse(JSON.stringify(metadata)); // Local copy

  let header = '';
  header += '// ==UserScript==\n';

  Object.keys(userstyleSpec).forEach(prop => {
    const value = _safePropGet(prop, JSmeta);
    if (value && _isAllowedJSMetaProp(prop)) {
      if (prop === 'match') {
        value.forEach(include => {
          header += `// @${_padPropName('include', longestPropLength)} ${include}\n`;
        });
      } else {
        header += `// @${_padPropName(prop, longestPropLength)} ${JSmeta[prop]}\n`;
      }
    }
  });

  header += '// ==/UserScript==\n';
  return header;
}
1326951
function parse(headers) {
    var output = {}, i, p, k, v;
    headers = headers || '';
    headers = headers.replace('\r', '');
    headers = headers.split('\n');
    for(i = 0;i < headers.length;i++) {
      p = headers[i].indexOf(':');
      k = headers[i].substr(0, p);
      v = headers[i].substr(p + 1);
      if(k && v) {
        k = k.replace(/^\s+/, '').replace(/\s+$/, '');
        v = v.replace(/^\s+/, '').replace(/\s+$/, '');
        output[k.toLowerCase()] = v;
      }
    }
    return output;
  }
450666
function reqToJSON () {
  const {ip, method, url, headers} = this
  const userAgent = headers ? headers['user-agent'] : void (0)
  return {ip, method, url, userAgent}
}