Logo

Programming-Idioms

  • PHP
  • Python
  • Scheme
  • Pascal
  • JS
  • C#
  • Ruby

Idiom #324 Read HTTP response header

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

require 'open-uri'
c = URI.open(u) {|res| res.meta["cache-control"] }
import requests
c = res.headers['cache-control']

"requests" is a 3rd-party library
import "net/http"
c := res.Header.Get("cache-control")

http.Response.Header is an exported field

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