-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added utility methods for base URL (#12)
- Loading branch information
Showing
21 changed files
with
466 additions
and
34 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
group=de.kamillionlabs | ||
name=hateoflux | ||
version=0.10.0 | ||
version=0.11.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/de/kamillionlabs/hateoflux/linkbuilder/BaseUrlExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2024 kamillion-suite contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* @since 17.10.2024 | ||
*/ | ||
|
||
package de.kamillionlabs.hateoflux.linkbuilder; | ||
|
||
import org.springframework.http.server.reactive.ServerHttpRequest; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.web.server.ServerWebExchange; | ||
|
||
import java.net.URI; | ||
|
||
/** | ||
* Utility class for extracting the base URL from a server web exchange or HTTP request. | ||
* | ||
* @author Younes El Ouarti | ||
*/ | ||
public class BaseUrlExtractor { | ||
|
||
private BaseUrlExtractor() { | ||
} | ||
|
||
/** | ||
* Extracts the base URL from the given {@link ServerWebExchange}. | ||
* | ||
* @param exchange | ||
* the server web exchange | ||
* @return the base URL as a string | ||
*/ | ||
public static String extractBaseUrl(@NonNull ServerWebExchange exchange) { | ||
return extractBaseUrl(exchange.getRequest()); | ||
} | ||
|
||
/** | ||
* Extracts the base URL from the given {@link ServerHttpRequest}. | ||
* | ||
* @param request | ||
* the server HTTP request | ||
* @return the base URL as a string | ||
*/ | ||
public static String extractBaseUrl(@NonNull ServerHttpRequest request) { | ||
URI uri = request.getURI(); | ||
|
||
String scheme = uri.getScheme(); | ||
String host = uri.getHost(); | ||
int port = uri.getPort(); | ||
|
||
boolean includePort = (port != -1 && ((scheme.equals("http") && port != 80) | ||
|| (scheme.equals("https") && port != 443))); | ||
String portPart = includePort ? ":" + port : ""; | ||
|
||
return scheme + "://" + host + portPart; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.