Created
April 29, 2021 00:43
-
-
Save chadselph/a5af9ce660c7cdb73390db54301ec346 to your computer and use it in GitHub Desktop.
ugly ftp2http server
This file contains hidden or 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
package com.goswiftly.http2ftp; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import java.net.URL; | |
import java.util.Base64; | |
import static spark.Spark.*; | |
public class Server { | |
private static final Logger logger = LoggerFactory.getLogger(Server.class); | |
public static void main(String[] args) { | |
get("/*", (req, res) -> | |
{ | |
res.header("Content-Type", "application/zip"); | |
String url = "ftp:/" + getAuthString(req.headers("Authentication")) + req.pathInfo(); | |
logger.info("Fetching {}", url); | |
return new URL(url).openStream().readAllBytes(); | |
} | |
); | |
} | |
static String getAuthString(String authHeader) { | |
if (authHeader == null) return ""; | |
else return new String(Base64.getDecoder().decode(authHeader)) + "@"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment