Logo

Programming-Idioms

  • Pascal
  • Go

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 "net/http"
c := res.Header.Get("cache-control")

http.Response.Header is an exported field
use HTTP::Tiny;
$resp = HTTP::Tiny->new->get($url); 

$cc = $resp->{'headers'}->{'cache-control'};

This is a simplistic example devoid of error checking. Minimally the response should be checked to make sure the get() succeeded otherwise this could generate a run time error.

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