title: Reading and Setting Rails Response Headers
body: <p>I want to read the header of a request coming in to a Rails Controller...</p>
  
  <p>How can I read in the header of the request to see what the request expects/wants back (in terms of formats) and send back data in that format?</p>
  
  <p>example:</p>
  
  <pre><code>#in the controller receiving the request
  def receive_req
     request.head #read value from header
     #if req wants json, format to json else, format to html etc...
     res = response
     res.head = "set appropriate header values"
     res.body = "data to send back in the body"
  end
  
  
  #in the controller making the req
  def send_request
    Net::HTTP.post("/receive_req", "data", header_values)
    render #{response.body}
  end
  </code></pre>