GithubHelp home page GithubHelp logo

global19-atlassian-net / finatra-xheaders-filter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ncbi/finatra-xheaders-filter

0.0 1.0 0.0 14 KB

X-* header support filters for Finatra

License: Other

Scala 100.00%

finatra-xheaders-filter's Introduction

XHeaders Filter

Handles "X-Script-Name", "X-Forwarded-Host" and "X-Forwarded-Proto" headers within Finatra-based applications.

Supports Scala 2.11 and Finatra 2.9.0.

Configuration

  1. Add this finatra-xheaders-filter library into your project's build.sbt libraryDependencies list:
"gov.nih.nlm.ncbi" %% "finatra-xheaders-filter" % <version>
  1. Add XHeadersHttpResponseFilter to your server after the CommonFilters:
...
import gov.nih.nlm.ncbi.xheadersfilter.XHeadersHttpResponseFilter

class MyServer extends HttpServer{

  override def configureHttp(router: HttpRouter) {
    router
      ...
      .filter[TraceIdMDCFilter[Request, Response]]
      .filter[CommonFilters]
      .filter[XHeadersHttpResponseFilter[Request]]
      ...
  }

}

Note: It's very important to keep XHeadersHttpResponseFilter after CommonFilters since it overrides (therefore has to be executed before) HttpResponseFilter. In the future there might be NCBICommonFilters which will contain XHeadersHttpResponseFilter instead of HttpResponseFilter.

That's it. The filter will now extract all required headers from the incoming request and will update the response's location if necessary.

Ignoring "X-Script-Name"

Occasionally, you'll want to bypass "X-Script-Name", keeping it out of a c.t.f.Response's Location http header. To do so, use the fixLocation function from NCBIResponseUtils in your Controller:

...
import gov.nih.nlm.ncbi.xheadersfilter.NCBIResponseUtils.fixLocation

@Singleton
class MyController @Inject() extends Controller
{

  prefix("/cat") {

    get("/google/?", "Redirect to google") { request: Request =>
      fixLocation(response.movedPermanently.location("https://google.com")) }
    }

    get("/journals/123/?", "Redirect to some journal from another application") {request: Request =>
      fixLocation(response.movedPermanently.location("/journals/123"))
    }
  }
}

Questions? Comments? Concerns?

Contact: @anapana or @edwelker

finatra-xheaders-filter's People

Contributors

edwelker avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.