Skip to content
Permalink
Browse files

fix: server header (DSP-537) (#1691)

  • Loading branch information
subotic committed Aug 18, 2020
1 parent 1c39d4f commit 8d7bee8ad02e838a81a8fd7b9cdc8d38c7b9fe8d
@@ -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",
@@ -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"],
)
@@ -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.
*
@@ -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}"

@@ -0,0 +1,4 @@
#!/bin/bash

tag=$(awk '/BUILD_SCM_TAG/ {print $2}' "$1")
sed "s/{BUILD_TAG}/$tag/" "$2"
@@ -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(
@@ -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",
@@ -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",
@@ -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 {

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

def getServerVersionHeader() = ServerVersionHeader
def getServerVersionHeader(): Server = ServerVersionHeader
}
@@ -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",
@@ -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",
@@ -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"/>
@@ -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",
@@ -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)
}
}

0 comments on commit 8d7bee8

Please sign in to comment.