Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: server header (DSP-537) (#1691)
  • Loading branch information
subotic committed Aug 18, 2020
1 parent 1c39d4f commit 8d7bee8
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 29 deletions.
2 changes: 1 addition & 1 deletion third_party/dependencies.bzl
Expand Up @@ -143,7 +143,7 @@ def dependencies():
)

ALL_WEBAPI_MAIN_DEPENDENCIES = [
"//tools/buildstamp:version_info_jar",
"//tools/version_info",
"//webapi/src/main/scala/org/knora/webapi",
"//webapi/src/main/scala/org/knora/webapi/app",
"//webapi/src/main/scala/org/knora/webapi/core",
Expand Down
16 changes: 0 additions & 16 deletions tools/buildstamp/BUILD.bazel
Expand Up @@ -15,19 +15,3 @@ filegroup(
name = "srcs",
srcs = glob(["**"]),
)

# Generates a scala source file that includes version information
load("//tools/buildstamp:gen_version_info.bzl", "gen_version_info")
gen_version_info(
name = "version_info_src",
scala_version = SCALA_VERSION,
akka_version = AKKA_VERSION,
akka_http_version = AKKA_HTTP_VERSION,
sipi_version = SIPI_VERSION,
fuseki_version = FUSEKI_VERSION,
)

scala_library(
name = "version_info_jar",
srcs = [":version_info_src"],
)
38 changes: 38 additions & 0 deletions tools/version_info/BUILD.bazel
@@ -0,0 +1,38 @@
package(default_visibility = ["//visibility:public"])

# bring our version constants in
load("//third_party:versions.bzl", "SCALA_VERSION", "AKKA_VERSION", "AKKA_HTTP_VERSION", "SIPI_VERSION", "FUSEKI_VERSION")
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library")

filegroup(
name = "srcs",
srcs = glob(["**"]),
)

# Generates a scala source file that includes version information
# The generated intermediate file is missing the BUILD_TAG, which is
# add by the version_info genrule
load("//tools/version_info:gen_version_info.bzl", "gen_version_info")
gen_version_info(
name = "version_info_without_build_tag",
scala_version = SCALA_VERSION,
akka_version = AKKA_VERSION,
akka_http_version = AKKA_HTTP_VERSION,
sipi_version = SIPI_VERSION,
fuseki_version = FUSEKI_VERSION,
)

# Adds the missing build tag and emits the final scala object
genrule(
name = "version_info_with_build_tag",
srcs = [":version_info_without_build_tag"],
outs = ["version_info.scala"],
local = 1,
tools = [":add_build_tag.sh"],
cmd = '$(location add_build_tag.sh) bazel-out/volatile-status.txt "$<" > "$@"',
)

scala_library(
name = "version_info",
srcs = [":version_info_with_build_tag"],
)
@@ -1,5 +1,5 @@
/*
* Copyright © 2015-2020 the contributors (see Contributors.md).
* Copyright © 2015-2018 the contributors (see Contributors.md).
*
* This file is part of Knora.
*
Expand All @@ -21,12 +21,12 @@ package org.knora.webapi.http.version

import scala.Predef._

/** This object was generated by //tools/buildstamp:version.bzl. */
/** This object was generated by //tools/version_info. */
case object VersionInfo {

val name: String = "webapi"

val version: String = "{BUILD_SCM_TAG}"
val version: String = "{BUILD_TAG}"

val scalaVersion: String = "{SCALA_VERSION}"

Expand Down
4 changes: 4 additions & 0 deletions tools/version_info/add_build_tag.sh
@@ -0,0 +1,4 @@
#!/bin/bash

tag=$(awk '/BUILD_SCM_TAG/ {print $2}' "$1")
sed "s/{BUILD_TAG}/$tag/" "$2"
Expand Up @@ -4,7 +4,7 @@ content during the analysis phase.
"""

# Label of the template file to use.
_TEMPLATE = "//tools/buildstamp:VersionInfoTemplate.scala"
_TEMPLATE = "//tools/version_info:VersionInfoTemplate.scala"

def _gen_version_info_impl(ctx):
ctx.actions.expand_template(
Expand Down
2 changes: 1 addition & 1 deletion webapi/BUILD.bazel
Expand Up @@ -39,7 +39,7 @@ scala_library(
"@maven//:org_slf4j_log4j_over_slf4j",
],
deps = [
"//tools/buildstamp:version_info_jar",
"//tools/version_info",
"//webapi/src/main/scala/org/knora/webapi",
"//webapi/src/main/scala/org/knora/webapi/core",
"//webapi/src/main/scala/org/knora/webapi/exceptions",
Expand Down
Expand Up @@ -7,7 +7,7 @@ scala_library(
srcs = glob(["*.scala"]),
unused_dependency_checker_mode = "warn",
deps = [
"//tools/buildstamp:version_info_jar",
"//tools/version_info",
"@maven//:com_typesafe_akka_akka_actor_2_12",
"@maven//:com_typesafe_akka_akka_http_2_12",
"@maven//:com_typesafe_akka_akka_http_core_2_12",
Expand Down
Expand Up @@ -19,13 +19,13 @@

package org.knora.webapi.http.version

import akka.http.scaladsl.model.HttpResponse
import akka.http.scaladsl.model.headers.Server
import akka.http.scaladsl.server.Directives.respondWithHeader
import akka.http.scaladsl.server.Route

/**
* This object provides methods that can be used to add the [[Server]] header to an [[HttpResponse]].
* This object provides methods that can be used to add the [[Server]] header
* to an [[akka.http.scaladsl.model.HttpResponse]].
*/
object ServerVersion {

Expand All @@ -36,5 +36,5 @@ object ServerVersion {
route
}

def getServerVersionHeader() = ServerVersionHeader
def getServerVersionHeader(): Server = ServerVersionHeader
}
Expand Up @@ -9,7 +9,6 @@ scala_library(
deps = [
"@maven//:com_typesafe_scala_logging_scala_logging_2_12",
"@maven//:org_slf4j_slf4j_api",
"@maven//:commons_io_commons_io",
"@maven//:org_scala_lang_scala_library",
"@maven//:org_scala_lang_scala_reflect",
"@maven//:io_kamon_kamon_core_2_12",
Expand Down
2 changes: 1 addition & 1 deletion webapi/src/main/scala/org/knora/webapi/routing/BUILD.bazel
Expand Up @@ -7,7 +7,7 @@ scala_library(
srcs = glob(["**/*.scala"]),
unused_dependency_checker_mode = "warn",
deps = [
"//tools/buildstamp:version_info_jar",
"//tools/version_info",
"//webapi/src/main/scala/org/knora/webapi",
"//webapi/src/main/scala/org/knora/webapi/annotation",
"//webapi/src/main/scala/org/knora/webapi/exceptions",
Expand Down
1 change: 1 addition & 0 deletions webapi/src/test/resources/logback-test.xml
Expand Up @@ -116,6 +116,7 @@

<!-- http -->
<logger name="org.knora.webapi.e2e.CORSSupportE2ESpec" level="DEBUG"/>
<logger name="org.knora.webapi.http.ServerVersionE2ESpec" level="DEBUG"/>

<!-- V1 -->
<logger name="org.knora.webapi.responders.v1.ListsResponderV1Spec" level="INFO"/>
Expand Down
6 changes: 6 additions & 0 deletions webapi/src/test/scala/org/knora/webapi/http/BUILD.bazel
Expand Up @@ -15,6 +15,12 @@ scala_test(
],
jvm_flags = ["-Dconfig.resource=fuseki.conf"],
# unused_dependency_checker_mode = "warn",
runtime_deps = [
"@maven//:ch_qos_logback_logback_classic",
"@maven//:ch_qos_logback_logback_core",
"@maven//:com_typesafe_akka_akka_slf4j_2_12",
"@maven//:org_slf4j_log4j_over_slf4j",
],
deps = ALL_WEBAPI_MAIN_DEPENDENCIES + [
"//webapi:main_library",
"//webapi:test_library",
Expand Down
Expand Up @@ -43,8 +43,13 @@ class ServerVersionE2ESpec extends E2ESpec(ServerVersionE2ESpec.config) {
"return the custom 'Server' header with every response" in {
val request = Get(baseApiUrl + s"/admin/projects")
val response: HttpResponse = singleAwaitingRequest(request)
// logger.debug(s"response: ${response.toString}")
response.headers should contain (ServerVersion.getServerVersionHeader())
response.headers.find(_.name == "Server") match {
case Some(serverHeader: HttpHeader) =>
serverHeader.value() should include ("webapi/")
serverHeader.value() should include ("akka-http/")
case None => fail("no server header found")
}
response.status should be(StatusCodes.OK)
}
}
Expand Down

0 comments on commit 8d7bee8

Please sign in to comment.