From daa640c5b0621258ad48b05413f35ad82adfacb9 Mon Sep 17 00:00:00 2001 From: Sebastian Seedorf Date: Sun, 6 Dec 2020 18:56:27 +0100 Subject: [PATCH] initial commit --- .gitignore | 109 ++++++++++++++++++++++++++ .idea/description.html | 1 + .idea/kotlinc.xml | 7 ++ .idea/misc.xml | 12 +++ .idea/modules.xml | 8 ++ .idea/project-template.xml | 3 + HttpHeaderTest.iml | 12 +++ src/de/sebse/httpheadertest/Main.java | 66 ++++++++++++++++ 8 files changed, 218 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/description.html create mode 100644 .idea/kotlinc.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/project-template.xml create mode 100644 HttpHeaderTest.iml create mode 100644 src/de/sebse/httpheadertest/Main.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d532a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,109 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/intellij +# Edit at https://www.toptal.com/developers/gitignore?templates=intellij + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +# End of https://www.toptal.com/developers/gitignore/api/intellij + diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..1c24f9a --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5d75313 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7aad4ef --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/project-template.xml b/.idea/project-template.xml new file mode 100644 index 0000000..1f08b88 --- /dev/null +++ b/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/HttpHeaderTest.iml b/HttpHeaderTest.iml new file mode 100644 index 0000000..d5c0743 --- /dev/null +++ b/HttpHeaderTest.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/de/sebse/httpheadertest/Main.java b/src/de/sebse/httpheadertest/Main.java new file mode 100644 index 0000000..538494d --- /dev/null +++ b/src/de/sebse/httpheadertest/Main.java @@ -0,0 +1,66 @@ +package de.sebse.httpheadertest; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Scanner; + +public class Main { + + public static void main(String[] args) { + while (true) { + System.out.print("Enter URL:"); + + Scanner in = new Scanner(System.in); + String input = in.next(); + URL parsedUrl; + try { + parsedUrl = new URL(input); + HttpURLConnection connection = openConnection(parsedUrl); + for (String cookie : + connection.getHeaderFields().get("Set-Cookie")) { + print(cookie); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /** + * Opens an {@link HttpURLConnection} with parameters. + * @param url + * @return an open connection + * @throws IOException + */ + private static HttpURLConnection openConnection(URL url) throws IOException { + HttpURLConnection connection = createConnection(url); + int timeoutMs = 10000; + connection.setConnectTimeout(timeoutMs); + connection.setReadTimeout(timeoutMs); + connection.setUseCaches(false); + connection.setDoInput(true); + connection.setInstanceFollowRedirects(false); + // use caller-provided custom SslSocketFactory, if any, for HTTPS + /*if ("https".equals(url.getProtocol()) && mSslSocketFactory != null) { + ((HttpsURLConnection)connection).setSSLSocketFactory(mSslSocketFactory); + }*/ + return connection; + } + + + /** + * Create an {@link HttpURLConnection} for the specified {@code url}. + */ + protected static HttpURLConnection createConnection(URL url) throws IOException { + return (HttpURLConnection) url.openConnection(); + } + + private static void print(String o) { + System.out.println(o); + } + + private static void print(int o) { + System.out.println(o); + } +}