Skip to content

Commit

Permalink
deploy: 0f1dcf4
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed May 18, 2024
1 parent 6af4f8b commit ca2e720
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@
</html>
</code></pre><h2 id="extending-endpoints-with-decorators" class="Styles-hoverBox">Extending Endpoints with Decorators<a href="#extending-endpoints-with-decorators" class="Styles-hoverLink"><i class="fa fa-link" aria-hidden="true"></i></a></h2>
<pre style="background-color: #f8f8f8"><code style="white-space:pre; background-color: #f8f8f8" class="scala">package app
object Decorated extends cask.MainRoutes{
class User{
object Decorated extends cask.MainRoutes {
class User {
override def toString = &quot;[haoyi]&quot;
}
class loggedIn extends cask.RawDecorator {
Expand All @@ -580,6 +580,21 @@
}
}

class withCustomHeader extends cask.RawDecorator {
def wrapFunction(request: cask.Request, delegate: Delegate) = {
request.headers.get(&quot;x-custom-header&quot;).map(_.head) match {
case Some(header) =&gt; delegate(Map(&quot;customHeader&quot; -&gt; header))
case None =&gt;
cask.router.Result.Success(
cask.model.Response(
s&quot;Request is missing required header: &#39;X-CUSTOM-HEADER&#39;&quot;,
400
)
)
}
}
}

@withExtra()
@cask.get(&quot;/hello/:world&quot;)
def hello(world: String)(extra: Int) = {
Expand All @@ -592,6 +607,12 @@
world + user
}

@withCustomHeader()
@cask.get(&quot;/echo&quot;)
def echoHeader(request: cask.Request)(customHeader: String) = {
customHeader
}

@withExtra()
@loggedIn()
@cask.get(&quot;/internal-extra/:world&quot;)
Expand Down

0 comments on commit ca2e720

Please sign in to comment.