Skip to content

Commit

Permalink
Merge pull request #475 from yanzhenjie/dev
Browse files Browse the repository at this point in the history
Release v2.1.11.
  • Loading branch information
yanzhenjie authored Jan 29, 2023
2 parents d0edcd1 + ca9cfaa commit 3960fd7
Show file tree
Hide file tree
Showing 21 changed files with 91 additions and 208 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ buildscript {
}
dependencies {
classpath 'com.yanzhenjie.andserver:plugin:2.1.10'
classpath 'com.yanzhenjie.andserver:plugin:2.1.11'
...
}
}
Expand All @@ -148,8 +148,8 @@ apply plugin: 'com.yanzhenjie.andserver'
...
dependencies {
implementation 'com.yanzhenjie.andserver:api:2.1.10'
annotationProcessor 'com.yanzhenjie.andserver:processor:2.1.10'
implementation 'com.yanzhenjie.andserver:api:2.1.11'
annotationProcessor 'com.yanzhenjie.andserver:processor:2.1.11'
...
}
```
Expand All @@ -163,7 +163,7 @@ Before submitting pull requests, contributors must abide by the [agreement](./CO
## License

```text
Copyright 2021 Zhenjie Yan
Copyright Zhenjie Yan
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion annotation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ compileJava {
targetCompatibility = JavaVersion.VERSION_1_8
}

apply from: '../publish.gradle'
apply from: publishScript
3 changes: 1 addition & 2 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apply plugin: plugin.androidLibrary

android {
compileSdkVersion androidBuild.compileSdkVersion
buildToolsVersion androidBuild.buildToolsVersion

defaultConfig {
minSdkVersion androidBuild.libraryMinSdkVersion
Expand Down Expand Up @@ -33,4 +32,4 @@ dependencies {
compileOnly deps.android.annotation
}

apply from: '../publish.gradle'
apply from: publishScript
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public boolean isRepeatable() {
return true;
}

@Override
public boolean isChunked() {
return false;
}

@Override
public long contentLength() {
return mBody.length();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
public class StreamBody implements ResponseBody {

private InputStream mStream;
private boolean mChunked;
private long mLength;
private MediaType mMediaType;

Expand All @@ -45,11 +46,16 @@ public StreamBody(InputStream stream, long length) {
}

public StreamBody(InputStream stream, MediaType mediaType) {
this(stream, 0, mediaType);
this(stream, true, 0, mediaType);
}

public StreamBody(InputStream stream, long length, MediaType mediaType) {
this(stream, false, length, mediaType);
}

public StreamBody(InputStream stream, boolean chunked, long length, MediaType mediaType) {
this.mStream = stream;
this.mChunked = chunked;
this.mLength = length;
this.mMediaType = mediaType;
}
Expand All @@ -59,6 +65,11 @@ public boolean isRepeatable() {
return false;
}

@Override
public boolean isChunked() {
return mChunked;
}

@Override
public long contentLength() {
if (mLength == 0 && mStream instanceof FileInputStream) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public boolean isRepeatable() {
return true;
}

@Override
public boolean isChunked() {
return false;
}

@Override
public long contentLength() {
return mBody.length;
Expand Down
10 changes: 10 additions & 0 deletions api/src/main/java/com/yanzhenjie/andserver/http/ResponseBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public interface ResponseBody {
*/
boolean isRepeatable();

/**
* Tells about chunked encoding for this entity.
* <p>
* The behavior of wrapping entities is implementation dependent, but should respect the primary purpose.
* </p>
*
* @return {@code true} if chunked encoding is preferred for this entity, or {@code false} if it is not
*/
boolean isChunked();

/**
* Get the content-length of the message body, if the length is unknown, return a negative value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ private BodyToEntity(ResponseBody body) {

@Override
public boolean isRepeatable() {
return false;
return mBody.isRepeatable();
}

@Override
public boolean isChunked() {
return false;
return mBody.isChunked();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*/
public abstract class BasicServer<T extends BasicServer.Builder> implements Server {

static final int BUFFER = 8 * 1024;
// static final int BUFFER = 8 * 1024;

protected final InetAddress mInetAddress;
protected final int mPort;
Expand Down Expand Up @@ -88,9 +88,9 @@ public void run() {
.setSoReuseAddress(true)
.setTcpNoDelay(true)
.setSoTimeout(mTimeout)
.setBacklogSize(BUFFER)
.setRcvBufSize(BUFFER)
.setSndBufSize(BUFFER)
// .setBacklogSize(BUFFER)
// .setRcvBufSize(BUFFER)
// .setSndBufSize(BUFFER)
.setSoLinger(0)
.build()
)
Expand Down
19 changes: 10 additions & 9 deletions api/src/main/java/com/yanzhenjie/andserver/server/ProxyServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ protected void afterExecute(Runnable r, Throwable t) {
private ServerSocket mServerSocket;

public HttpServer(InetAddress inetAddress, int port, int timeout, ServerSocketFactory socketFactory,
SSLSocketInitializer sslSocketInitializer, HttpRequestHandler handler) {
SSLSocketInitializer sslSocketInitializer, HttpRequestHandler handler) {
this.mInetAddress = inetAddress;
this.mPort = port;
this.mTimeout = timeout;
Expand All @@ -255,8 +255,9 @@ public HttpServer(InetAddress inetAddress, int port, int timeout, ServerSocketFa
public void startServer() throws IOException {
mServerSocket = mSocketFactory.createServerSocket();
mServerSocket.setReuseAddress(true);
mServerSocket.bind(new InetSocketAddress(mInetAddress, mPort), BUFFER);
mServerSocket.setReceiveBufferSize(BUFFER);
// mServerSocket.bind(new InetSocketAddress(mInetAddress, mPort), BUFFER);
// mServerSocket.setReceiveBufferSize(BUFFER);
mServerSocket.bind(new InetSocketAddress(mInetAddress, mPort));
if (mSSLSocketInitializer != null && mServerSocket instanceof SSLServerSocket) {
mSSLSocketInitializer.onCreated((SSLServerSocket) mServerSocket);
}
Expand All @@ -280,7 +281,7 @@ public void stopServer() {
}

Set<Worker> workers = mWorkerSet.keySet();
for (Worker worker : workers) {
for (Worker worker: workers) {
HttpServerConnection conn = worker.getServerConn();
try {
conn.shutdown();
Expand All @@ -297,14 +298,14 @@ public void run() {
socket.setSoTimeout(mTimeout);
socket.setKeepAlive(true);
socket.setTcpNoDelay(true);
socket.setReceiveBufferSize(BUFFER);
socket.setSendBufferSize(BUFFER);
// socket.setReceiveBufferSize(BUFFER);
// socket.setSendBufferSize(BUFFER);
socket.setSoLinger(true, 0);

DefaultBHttpServerConnection serverConn = new DefaultBHttpServerConnection(BUFFER);
DefaultBHttpServerConnection serverConn = new DefaultBHttpServerConnection(8192);
serverConn.bind(socket);

DefaultBHttpClientConnection clientConn = new DefaultBHttpClientConnection(BUFFER);
DefaultBHttpClientConnection clientConn = new DefaultBHttpClientConnection(8192);
Worker worker = new Worker(mHttpService, serverConn, clientConn);

mWorkerExecutor.execute(worker);
Expand All @@ -321,7 +322,7 @@ private static class Worker implements Runnable {
private final DefaultBHttpClientConnection mClientConn;

public Worker(HttpService httpservice,
DefaultBHttpServerConnection serverConn, DefaultBHttpClientConnection clientConn) {
DefaultBHttpServerConnection serverConn, DefaultBHttpClientConnection clientConn) {
this.mHttpService = httpservice;
this.mServerConn = serverConn;
this.mClientConn = clientConn;
Expand Down
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ buildscript {

dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.yanzhenjie.andserver:plugin:2.1.10'
classpath 'com.yanzhenjie.andserver:plugin:2.1.11'
}
}

allprojects {
repositories {
mavenLocal()
google()
jcenter()
mavenCentral()
}
}
Expand Down
18 changes: 7 additions & 11 deletions config.gradle
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
ext {
publishScript = 'https://raw.githubusercontent.com/yanzhenjie/GradleToMaven/master/publish.gradle'

plugin = [
java : 'java',
javaLibrary : 'java-library',
javaPlugin : 'java-gradle-plugin',
android : 'com.android.application',
androidLibrary: 'com.android.library',
androidMaven : 'com.github.dcendents.android-maven',
andServer : 'com.yanzhenjie.andserver'
]

androidBuild = [
applicationId : 'com.yanzhenjie.andserver.sample',
compileSdkVersion : 29,
buildToolsVersion : '29.0.3',
compileSdkVersion : 30,

libraryMinSdkVersion : 9,
libraryTargetSdkVersion: 29,
libraryTargetSdkVersion: 30,
sampleMinSdkVersion : 14,
sampleTargetSdkVersion : 22,

versionCode : 25,
versionName : '2.1.2'
sampleTargetSdkVersion : 30
]

deps = [
Expand All @@ -32,9 +28,9 @@ ext {
],

apache : [
lang : 'org.apache.commons:commons-lang3:3.9',
lang : 'org.apache.commons:commons-lang3:3.12.0',
collections: 'org.apache.commons:commons-collections4:4.4',
httpcore : "com.yanzhenjie.apache:httpcore:4.4.14.1",
httpcore : "com.yanzhenjie.apache:httpcore:4.4.16",
fileupload : "com.yanzhenjie.apache:fileupload:1.4",
],

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
android.useAndroidX=true

POM_GROUP_ID=com.yanzhenjie.andserver
POM_VERSION=2.1.10
POM_VERSION=2.1.11

POM_DESCRIPTION=Android web server.

Expand Down
2 changes: 1 addition & 1 deletion plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ dependencies {
implementation deps.poet
}

apply from: '../publish.gradle'
apply from: publishScript
2 changes: 1 addition & 1 deletion processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ dependencies {
implementation deps.apache.collections
}

apply from: '../publish.gradle'
apply from: publishScript
Loading

0 comments on commit 3960fd7

Please sign in to comment.