Skip to content

Commit

Permalink
Merge pull request #84 from yushijinhun/develop
Browse files Browse the repository at this point in the history
Release 1.1.32
  • Loading branch information
xfl03 authored Aug 27, 2020
2 parents 5397909 + c4a7692 commit 52c4f2b
Show file tree
Hide file tree
Showing 8 changed files with 506 additions and 569 deletions.
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ authlib-injector enables you to build a Minecraft authentication system offering
**[See the wiki](https://github.com/yushijinhun/authlib-injector/wiki) for documents and detailed descriptions.**

## Download
You can download the latest authlib-injector build from [here](https://authlib-injector.yushi.moe/~download/).
You can download the latest authlib-injector build from [here](https://authlib-injector.yushi.moe/).

## Build
Dependencies: Gradle, JDK 8+
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
**关于该项目的详细介绍见 [wiki](https://github.com/yushijinhun/authlib-injector/wiki)**

## 获取
您可以从[这里](https://authlib-injector.yushi.moe/~download/)获取最新的 authlib-injector。
您可以从[这里](https://authlib-injector.yushi.moe/)获取最新的 authlib-injector。

## 构建
构建依赖:Gradle、JDK 8+。
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/moe/yushi/authlibinjector/httpd/URLProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package moe.yushi.authlibinjector.httpd;

import static moe.yushi.authlibinjector.util.IOUtils.CONTENT_TYPE_TEXT;
import static moe.yushi.authlibinjector.util.IOUtils.transfer;
import static moe.yushi.authlibinjector.util.Logging.log;
import static moe.yushi.authlibinjector.util.Logging.Level.DEBUG;
Expand Down Expand Up @@ -131,7 +132,7 @@ public Response serve(IHTTPSession session) {
result = filter.handle(domain, path, session);
} catch (Throwable e) {
log(WARNING, "An error occurred while processing request [" + session.getUri() + "]", e);
return Response.newFixedLength(Status.INTERNAL_ERROR, MIME_PLAINTEXT, "Internal Server Error");
return Response.newFixedLength(Status.INTERNAL_ERROR, CONTENT_TYPE_TEXT, "Internal Server Error");
}

if (result.isPresent()) {
Expand All @@ -147,11 +148,11 @@ public Response serve(IHTTPSession session) {
return reverseProxy(session, target);
} catch (IOException e) {
log(WARNING, "Reverse proxy error", e);
return Response.newFixedLength(Status.BAD_GATEWAY, MIME_PLAINTEXT, "Bad Gateway");
return Response.newFixedLength(Status.BAD_GATEWAY, CONTENT_TYPE_TEXT, "Bad Gateway");
}
} else {
log(DEBUG, "No handler is found for [" + session.getUri() + "]");
return Response.newFixedLength(Status.NOT_FOUND, MIME_PLAINTEXT, "Not Found");
return Response.newFixedLength(Status.NOT_FOUND, CONTENT_TYPE_TEXT, "Not Found");
}
}
};
Expand All @@ -165,7 +166,7 @@ private Response reverseProxy(IHTTPSession session, String upstream) throws IOEx

String url = session.getQueryParameterString() == null ? upstream : upstream + "?" + session.getQueryParameterString();

Map<String, String> requestHeaders = session.getHeaders();
Map<String, String> requestHeaders = new LinkedHashMap<>(session.getHeaders());
ignoredHeaders.forEach(requestHeaders::remove);

InputStream clientIn = session.getInputStream();
Expand Down Expand Up @@ -218,11 +219,17 @@ public String getDescription() {
break;
}
}

Response response;
if (contentLength != -1) {
response = Response.newFixedLength(status, null, upstreamIn, contentLength);
if (contentLength == -1) {
if (conn.getHeaderField("transfer-encoding") == null) {
// no content
response = Response.newFixedLength(status, null, upstreamIn, 0);
} else {
response = Response.newChunked(status, null, upstreamIn);
}
} else {
response = Response.newChunked(status, null, upstreamIn);
response = Response.newFixedLength(status, null, upstreamIn, contentLength);
}
responseHeaders.forEach((name, values) -> values.forEach(value -> response.addHeader(name, value)));

Expand Down
Loading

0 comments on commit 52c4f2b

Please # to comment.