Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #324 Read HTTP response header

Set the string c to the (first) value of the header "cache-control" of the HTTP response res.

import requests
c = res.headers['cache-control']
import "net/http"
c := res.Header.Get("cache-control")
use HTTP::Tiny;
$resp = HTTP::Tiny->new->get($url); 

$cc = $resp->{'headers'}->{'cache-control'};
require 'open-uri'
c = URI.open(u) {|res| res.meta["cache-control"] }
use http::header::CACHE_CONTROL;
let c = res.headers()
    .get(CACHE_CONTROL)
    .expect("cache-control header exists")
    .to_str()
    .expect("cache-control header contains only visible ascii");

New implementation...
< >
programming-idioms.org