mirror of
https://github.com/danog/HTTPPayloads.git
synced 2024-11-26 11:54:39 +01:00
First public version
This commit is contained in:
commit
215bd3a6b8
73
build.xml
Normal file
73
build.xml
Normal file
@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||
<!-- the Compile on Save feature is turned off for the project. -->
|
||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||
<!-- in the project's Project Properties dialog box.-->
|
||||
<project name="HTTP" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project HTTP.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar: JAR building
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="HTTP-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
</project>
|
1420
nbproject/build-impl.xml
Normal file
1420
nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
8
nbproject/genfiles.properties
Normal file
8
nbproject/genfiles.properties
Normal file
@ -0,0 +1,8 @@
|
||||
build.xml.data.CRC32=773b98a1
|
||||
build.xml.script.CRC32=671e82ce
|
||||
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=773b98a1
|
||||
nbproject/build-impl.xml.script.CRC32=f3948ab1
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48
|
95
nbproject/project.properties
Normal file
95
nbproject/project.properties
Normal file
@ -0,0 +1,95 @@
|
||||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processors.list=
|
||||
annotation.processing.run.all.processors=true
|
||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||
application.title=HTTPPayloads
|
||||
application.vendor=Daniil Gentili
|
||||
auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml
|
||||
build.classes.dir=${build.dir}/classes
|
||||
build.classes.excludes=**/*.java,**/*.form
|
||||
# This directory is removed when the project is cleaned:
|
||||
build.dir=build
|
||||
build.generated.dir=${build.dir}/generated
|
||||
build.generated.sources.dir=${build.dir}/generated-sources
|
||||
# Only compile against the classpath explicitly listed here:
|
||||
build.sysclasspath=ignore
|
||||
build.test.classes.dir=${build.dir}/test/classes
|
||||
build.test.results.dir=${build.dir}/test/results
|
||||
# Uncomment to specify the preferred debugger connection transport:
|
||||
#debug.transport=dt_socket
|
||||
debug.classpath=\
|
||||
${run.classpath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
# Files in build.classes.dir which should be excluded from distribution jar
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/HTTP.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
endorsed.classpath=
|
||||
excludes=
|
||||
includes=**
|
||||
jar.archive.disabled=${jnlp.enabled}
|
||||
jar.compress=false
|
||||
jar.index=${jnlp.enabled}
|
||||
javac.classpath=
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
javac.external.vm=true
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
javac.source=1.8
|
||||
javac.target=1.8
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
javac.test.processorpath=\
|
||||
${javac.test.classpath}
|
||||
javadoc.additionalparam=
|
||||
javadoc.author=false
|
||||
javadoc.encoding=${source.encoding}
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
jnlp.codebase.type=no.codebase
|
||||
jnlp.descriptor=application
|
||||
jnlp.enabled=false
|
||||
jnlp.mixed.code=default
|
||||
jnlp.offline-allowed=false
|
||||
jnlp.signed=false
|
||||
jnlp.signing=
|
||||
jnlp.signing.alias=
|
||||
jnlp.signing.keystore=
|
||||
# Optional override of default Application-Library-Allowable-Codebase attribute identifying the locations where your signed RIA is expected to be found.
|
||||
manifest.custom.application.library.allowable.codebase=
|
||||
# Optional override of default Caller-Allowable-Codebase attribute identifying the domains from which JavaScript code can make calls to your RIA without security prompts.
|
||||
manifest.custom.caller.allowable.codebase=
|
||||
# Optional override of default Codebase manifest attribute, use to prevent RIAs from being repurposed
|
||||
manifest.custom.codebase=
|
||||
# Optional override of default Permissions manifest attribute (supported values: sandbox, all-permissions)
|
||||
manifest.custom.permissions=
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=true
|
||||
platform.active=default_platform
|
||||
project.license=gpl30
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
# Space-separated list of JVM arguments used when running the project.
|
||||
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||
run.jvmargs=
|
||||
run.test.classpath=\
|
||||
${javac.test.classpath}:\
|
||||
${build.test.classes.dir}
|
||||
source.encoding=UTF-8
|
||||
src.dir=src
|
||||
test.src.dir=test
|
15
nbproject/project.xml
Normal file
15
nbproject/project.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>HTTP</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
147
src/Payloads/Payload.java
Normal file
147
src/Payloads/Payload.java
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Daniil Gentili
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package Payloads;
|
||||
|
||||
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author root
|
||||
*/
|
||||
public abstract class Payload {
|
||||
|
||||
public Hashtable<String, String> headers = new Hashtable<>();
|
||||
protected String protocol;
|
||||
protected String protocolVersion;
|
||||
|
||||
protected String payload = "";
|
||||
protected Boolean keepalive = false;
|
||||
|
||||
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public String getProtocolVersion() {
|
||||
return protocolVersion;
|
||||
}
|
||||
|
||||
public String getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public Boolean shouldKeepAlive() {
|
||||
return keepalive;
|
||||
}
|
||||
|
||||
|
||||
public Payload setProtocolVersion(String protocolVersion) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Payload setProtocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Payload setPayload(String protocol) {
|
||||
this.protocol = protocol;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Payload shouldKeepAlive(Boolean keepalive) {
|
||||
this.keepalive = keepalive;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Method used for parsing first line, different for requests and responses
|
||||
* @param line
|
||||
*/
|
||||
protected abstract void parseFirstLine(String line);
|
||||
|
||||
/**
|
||||
* Method used for getting first line, different for requests and responses
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getFirstLine();
|
||||
|
||||
|
||||
/**
|
||||
* Constructor that parses request or response
|
||||
* @param input
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
protected void fromString(BufferedReader input) throws IOException {
|
||||
parseFirstLine(input.readLine());
|
||||
|
||||
String[] temp;
|
||||
String payloadtemp;
|
||||
int length;
|
||||
|
||||
while (!(payloadtemp = input.readLine()).isEmpty()) {
|
||||
temp = payloadtemp.split(":", 2);
|
||||
headers.put(temp[0].trim().toLowerCase(), temp[1].trim().toLowerCase());
|
||||
}
|
||||
|
||||
if (headers.containsKey("content-length")) {
|
||||
length = Integer.parseInt(headers.get("content-length"));
|
||||
char[] buffer = new char[length];
|
||||
input.read(buffer, 0, buffer.length);
|
||||
payload = String.copyValueOf(buffer);
|
||||
}
|
||||
if (headers.containsKey("connection")) {
|
||||
keepalive = "keep-alive".equals(headers.get("connection"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used for retrieving string version of request
|
||||
* @return Data to write to socket
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
String res = getFirstLine()+"\r\n";
|
||||
|
||||
headers.put("content-length", String.valueOf(payload.length()));
|
||||
headers.put("connection", keepalive ? "keep-alive" : "close");
|
||||
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
res += key+": "+value+"\r\n";
|
||||
}
|
||||
return res+"\r\n"+payload;
|
||||
}
|
||||
|
||||
public void write(BufferedWriter output) throws IOException {
|
||||
output.write(this.toString());
|
||||
output.flush();
|
||||
}
|
||||
|
||||
}
|
86
src/Payloads/RequestPayload.java
Normal file
86
src/Payloads/RequestPayload.java
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Daniil Gentili
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package Payloads;
|
||||
|
||||
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author root
|
||||
*/
|
||||
public class RequestPayload extends Payload {
|
||||
|
||||
private String URI;
|
||||
private String method;
|
||||
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
public String getURI() {
|
||||
return URI;
|
||||
}
|
||||
public Payload setMethod(String method) {
|
||||
this.method = method;
|
||||
return this;
|
||||
}
|
||||
public Payload setURI(String URI) {
|
||||
this.URI = URI;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public RequestPayload(BufferedReader input) throws IOException {
|
||||
fromString(input);
|
||||
}
|
||||
|
||||
public RequestPayload(String method, String URI, String payload) {
|
||||
this.protocol = "HTTP";
|
||||
this.protocolVersion = "1.1";
|
||||
this.keepalive = false;
|
||||
|
||||
this.method = method;
|
||||
this.URI = URI;
|
||||
this.payload = payload;
|
||||
}
|
||||
public RequestPayload(String method, String URI) {
|
||||
this.protocol = "HTTP";
|
||||
this.protocolVersion = "1.1";
|
||||
this.keepalive = false;
|
||||
|
||||
this.method = method;
|
||||
this.URI = URI;
|
||||
}
|
||||
|
||||
protected String getFirstLine() {
|
||||
return method+" "+URI+" "+protocol+"/"+protocolVersion;
|
||||
}
|
||||
protected void parseFirstLine(String line) {
|
||||
String[] temp;
|
||||
|
||||
temp = line.split(" ");
|
||||
method = temp[0].trim();
|
||||
URI = temp[1].trim();
|
||||
|
||||
temp = temp[2].trim().split("/");
|
||||
protocol = temp[0];
|
||||
protocolVersion = temp[1];
|
||||
}
|
||||
}
|
86
src/Payloads/ResponsePayload.java
Normal file
86
src/Payloads/ResponsePayload.java
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Daniil Gentili
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package Payloads;
|
||||
|
||||
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author root
|
||||
*/
|
||||
public class ResponsePayload extends Payload {
|
||||
private int responseCode;
|
||||
private String responseDescription;
|
||||
|
||||
public ResponsePayload(BufferedReader input) throws IOException {
|
||||
fromString(input);
|
||||
}
|
||||
|
||||
public ResponsePayload(int responseCode, String responseDescription) {
|
||||
this.protocol = "HTTP";
|
||||
this.protocolVersion = "1.1";
|
||||
this.keepalive = false;
|
||||
|
||||
this.responseCode = responseCode;
|
||||
this.responseDescription = responseDescription;
|
||||
|
||||
}
|
||||
public ResponsePayload(RequestPayload request, int responseCode, String responseDescription) {
|
||||
this.protocol = request.getProtocol();
|
||||
this.protocolVersion = request.getProtocolVersion();
|
||||
this.keepalive = request.shouldKeepAlive();
|
||||
|
||||
this.responseCode = responseCode;
|
||||
this.responseDescription = responseDescription;
|
||||
|
||||
}
|
||||
public ResponsePayload(RequestPayload request, int responseCode, String responseDescription, String responsePayload) {
|
||||
this.protocol = request.getProtocol();
|
||||
this.protocolVersion = request.getProtocolVersion();
|
||||
this.keepalive = request.shouldKeepAlive();
|
||||
|
||||
this.responseCode = responseCode;
|
||||
this.responseDescription = responseDescription;
|
||||
this.payload = responsePayload;
|
||||
}
|
||||
public Integer getResponseCode() {
|
||||
return responseCode;
|
||||
}
|
||||
public String getResponseDescription() {
|
||||
return responseDescription;
|
||||
}
|
||||
@Override
|
||||
protected String getFirstLine() {
|
||||
return protocol+"/"+protocolVersion+" "+responseCode+" "+responseDescription;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void parseFirstLine(String line) {
|
||||
String[] temp;
|
||||
|
||||
temp = line.split(" ", 3);
|
||||
responseCode = Integer.parseInt(temp[1].trim());
|
||||
responseDescription = temp[2];
|
||||
|
||||
temp = temp[0].trim().split("/");
|
||||
protocol = temp[0];
|
||||
protocolVersion = temp[1];
|
||||
}
|
||||
}
|
45
src/Payloads/ServerException.java
Normal file
45
src/Payloads/ServerException.java
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Daniil Gentili
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package Payloads;
|
||||
|
||||
import Payloads.RequestPayload;
|
||||
import Payloads.ResponsePayload;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author root
|
||||
*/
|
||||
public class ServerException extends Exception {
|
||||
private ResponsePayload response;
|
||||
public ServerException(RequestPayload request, int code, String description) {
|
||||
super(description);
|
||||
response = new ResponsePayload(request, code, description, description);
|
||||
}
|
||||
|
||||
public ServerException(RequestPayload request, int code, String description, String payload) {
|
||||
super(description);
|
||||
response = new ResponsePayload(request, code, description, payload);
|
||||
}
|
||||
|
||||
public ServerException(ResponsePayload response) {
|
||||
this.response = response;
|
||||
}
|
||||
public ResponsePayload getPayload() {
|
||||
return response;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user