Contents

Request headers

You can use mustache to render params, cookies and sessions in request headers.

Scenario: Setting headers for all requests to an API

  • Given I have the following templates/header_echo.html file
    The content-type you're requesting to the distant API is {{headers.requested_content_type}}.
  • And I have the following app.yml file
    routes:
      GET /header: "header_echo.html"
    
    pages:
      header_echo.html:
        headers:
          - "GET /headers"
    
    api_url: "http://localhost:8080"
    headers:
      Content-Type: "application/json"
  • Given I have the following API running
    ruby
    get "/headers" do
      if request.env["CONTENT_TYPE"]
        { requested_content_type: request.env["CONTENT_TYPE"] }.to_json
      else
        { requested_content_type: "unspecified" }.to_json
      end
    end
  • And I start a Chaplin server
  • When I send the request GET /header
  • Then I should get the following response
    The content-type you're requesting to the distant API is application/json.

Source: features/request_headers.feature at commit fe1da3d7, Chaplin (MIT license).