chibenwa commented on a change in pull request #780:
URL: https://github.com/apache/james-project/pull/780#discussion_r764518001
##########
File path:
server/protocols/jmap-rfc-8621/src/main/scala/org/apache/james/jmap/core/JmapRfc8621Configuration.scala
##########
@@ -43,33 +44,44 @@ object JmapRfc8621Configuration {
val WEBSOCKET_URL_PREFIX_DEFAULT: String = "ws://localhost"
val UPLOAD_LIMIT_DEFAULT: MaxSizeUpload = MaxSizeUpload.of(Size.of(30L,
Size.Unit.M)).get
- val LOCALHOST_CONFIGURATION: JmapRfc8621Configuration =
JmapRfc8621Configuration(URL_PREFIX_DEFAULT, WEBSOCKET_URL_PREFIX_DEFAULT,
UPLOAD_LIMIT_DEFAULT)
+ val LOCALHOST_CONFIGURATION: JmapRfc8621Configuration =
JmapRfc8621Configuration(
+ urlPrefixString = URL_PREFIX_DEFAULT,
+ websocketPrefixString = WEBSOCKET_URL_PREFIX_DEFAULT,
+ maxUploadSize = UPLOAD_LIMIT_DEFAULT)
-
- def from(configuration: Configuration): JmapRfc8621Configuration = {
+ def from(configuration: Configuration): JmapRfc8621Configuration =
JmapRfc8621Configuration(
urlPrefixString =
Option(configuration.getString(URL_PREFIX_PROPERTY)).getOrElse(URL_PREFIX_DEFAULT),
websocketPrefixString =
Option(configuration.getString(WEBSOCKET_URL_PREFIX_PROPERTY)).getOrElse(WEBSOCKET_URL_PREFIX_DEFAULT),
+ dynamicJmapPrefixResolutionEnabled =
configuration.getBoolean(DYNAMIC_JMAP_PREFIX_RESOLUTION_ENABLED_PROPERTY,
false),
maxUploadSize = Option(configuration.getString(UPLOAD_LIMIT_PROPERTY,
null))
.map(Size.parse)
.map(MaxSizeUpload.of(_).get)
.getOrElse(UPLOAD_LIMIT_DEFAULT),
maxTimeoutSeconds =
Optional.ofNullable(configuration.getInteger(WEB_PUSH_MAX_TIMEOUT_SECONDS_PROPERTY,
null)).map(Integer2int).toScala,
maxConnections =
Optional.ofNullable(configuration.getInteger(WEB_PUSH_MAX_CONNECTIONS_PROPERTY,
null)).map(Integer2int).toScala)
- }
}
-case class JmapRfc8621Configuration(urlPrefixString: String,
websocketPrefixString: String,
+case class JmapRfc8621Configuration(urlPrefixString: String,
+ websocketPrefixString: String,
+ dynamicJmapPrefixResolutionEnabled:
Boolean = false,
maxUploadSize: MaxSizeUpload =
UPLOAD_LIMIT_DEFAULT,
maxTimeoutSeconds: Option[Int] = None,
maxConnections: Option[Int] = None) {
- val urlPrefix: URL = new URL(urlPrefixString)
- val apiUrl: URL = new URL(s"$urlPrefixString/jmap")
- val downloadUrl: URL = new URL(urlPrefixString +
"/download/{accountId}/{blobId}?type={type}&name={name}")
- val uploadUrl: URL = new URL(s"$urlPrefixString/upload/{accountId}")
- val eventSourceUrl: URL = new
URL(s"$urlPrefixString/eventSource?types={types}&closeAfter={closeafter}&ping={ping}")
- val webSocketUrl: URI = new URI(s"$websocketPrefixString/jmap/ws")
+ def getURLPrefix(urlPrefixRequest: Option[URL]): String =
Some(dynamicJmapPrefixResolutionEnabled)
+ .filter(enabled => enabled)
+ .flatMap(_ => urlPrefixRequest.map(_.toString))
+ .getOrElse(urlPrefixString)
+
+ def apiUrl(urlPrefixRequest: Option[URL] ): URL = new
URL(s"${getURLPrefix(urlPrefixRequest)}/jmap")
+
+ def downloadUrl(urlPrefixRequest: Option[URL]): URL = new
URL(s"${getURLPrefix(urlPrefixRequest)}/download/{accountId}/{blobId}?type={type}&name={name}")
+
+ def uploadUrl(urlPrefixRequest: Option[URL]): URL = new
URL(s"${getURLPrefix(urlPrefixRequest)}/upload/{accountId}")
+
+ val webSocketUrl: URI = new URI(s"$websocketPrefixString/jmap/ws")
+ val eventSourceUrl: URL = new
URL(s"$urlPrefixString/eventSource?types={types}&closeAfter={closeafter}&ping={ping}")
Review comment:
I think the two header approach is valid.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]