Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpcaddyfile: Support single-line matchers #3263

Merged
merged 3 commits into from
May 5, 2020

Conversation

francislavoie
Copy link
Member

@francislavoie francislavoie commented Apr 14, 2020

I think this is a big win for readability. Almost identical implementation to #3228.

Caddyfile:

:80 {
    @matcher {
        method GET
    }
    respond @matcher "get"

    @matcher2 method POST
    respond @matcher2 "post"

    @matcher3 not method PUT
    respond @matcher3 "not put"
}

JSON:

{
  "apps": {
    "http": {
      "servers": {
        "srv0": {
          "listen": [
            ":80"
          ],
          "routes": [
            {
              "match": [
                {
                  "method": [
                    "GET"
                  ]
                }
              ],
              "handle": [
                {
                  "body": "get",
                  "handler": "static_response"
                }
              ]
            },
            {
              "match": [
                {
                  "method": [
                    "POST"
                  ]
                }
              ],
              "handle": [
                {
                  "body": "post",
                  "handler": "static_response"
                }
              ]
            },
            {
              "match": [
                {
                  "not": [
                    {
                      "method": [
                        "PUT"
                      ]
                    }
                  ]
                }
              ],
              "handle": [
                {
                  "body": "not put",
                  "handler": "static_response"
                }
              ]
            }
          ]
        }
      }
    }
  }
}

@mholt mholt added this to the 2.1 milestone Apr 14, 2020
@mholt mholt added the under review 🧐 Review is pending before merging label Apr 14, 2020
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still can't believe that works.

Let's see how it goes!

@mholt mholt merged commit 26e5596 into caddyserver:master May 5, 2020
@mholt mholt removed the under review 🧐 Review is pending before merging label May 5, 2020
@francislavoie francislavoie deleted the single-line-matchers branch May 5, 2020 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants