Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit dc2a42f

Browse files
committed
internal fixes
1 parent 308517b commit dc2a42f

File tree

4 files changed

+71
-17
lines changed

4 files changed

+71
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
<br>
2424

25-
> **Warning**
25+
> **Warning**:
2626
> simplehttpserver5 is not compatible with any previous version of [simplehttpserver](https://github.com/Ktt-Development/simplehttpserver)
2727
2828
🚧 WIP

src/main/java/dev/katsute/simplehttpserver/SimpleHttpServerImpl.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public synchronized void bind(final InetSocketAddress address) throws IOExceptio
7777
bind(address, null);
7878
}
7979

80+
@Override
8081
public synchronized void bind(final InetSocketAddress address, final int backlog) throws IOException {
8182
bind(address, (Integer) backlog);
8283
}
@@ -95,25 +96,26 @@ public final InetSocketAddress getAddress(){
9596
//
9697

9798
@Override
98-
public synchronized final void setExecutor(final Executor executor){
99-
server.setExecutor(executor);
99+
public synchronized final Executor getExecutor(){
100+
return server.getExecutor();
100101
}
101102

102103
@Override
103-
public final Executor getExecutor(){
104-
return server.getExecutor();
104+
public synchronized final void setExecutor(final Executor executor){
105+
server.setExecutor(executor);
105106
}
106107

108+
107109
//
108110

109111
@Override
110-
public synchronized final void setSessionHandler(final HttpSessionHandler sessionHandler){
111-
this.sessionHandler = sessionHandler;
112+
public synchronized final HttpSessionHandler getSessionHandler(){
113+
return sessionHandler;
112114
}
113115

114116
@Override
115-
public final HttpSessionHandler getSessionHandler(){
116-
return sessionHandler;
117+
public synchronized final void setSessionHandler(final HttpSessionHandler sessionHandler){
118+
this.sessionHandler = sessionHandler;
117119
}
118120

119121
@Override

src/main/java/dev/katsute/simplehttpserver/SimpleHttpsServerImpl.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public synchronized void bind(final InetSocketAddress address) throws IOExceptio
8989
bind(address, null);
9090
}
9191

92+
@Override
9293
public synchronized void bind(final InetSocketAddress address, final int backlog) throws IOException {
9394
bind(address, (Integer) backlog);
9495
}
@@ -107,25 +108,26 @@ public final InetSocketAddress getAddress(){
107108
//
108109

109110
@Override
110-
public synchronized final void setExecutor(final Executor executor){
111-
server.setExecutor(executor);
111+
public synchronized final Executor getExecutor(){
112+
return server.getExecutor();
112113
}
113114

114115
@Override
115-
public final Executor getExecutor(){
116-
return server.getExecutor();
116+
public synchronized final void setExecutor(final Executor executor){
117+
server.setExecutor(executor);
117118
}
118119

120+
119121
//
120122

121123
@Override
122-
public synchronized final void setSessionHandler(final HttpSessionHandler sessionHandler){
123-
this.sessionHandler = sessionHandler;
124+
public synchronized final HttpSessionHandler getSessionHandler(){
125+
return sessionHandler;
124126
}
125127

126128
@Override
127-
public final HttpSessionHandler getSessionHandler(){
128-
return sessionHandler;
129+
public synchronized final void setSessionHandler(final HttpSessionHandler sessionHandler){
130+
this.sessionHandler = sessionHandler;
129131
}
130132

131133
@Override
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (C) 2022 Katsute <https://github.com/Katsute>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License along
15+
* with this program; if not, write to the Free Software Foundation, Inc.,
16+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17+
*/
18+
19+
package dev.katsute.simplehttpserver.handler;
20+
21+
import com.sun.net.httpserver.HttpExchange;
22+
import com.sun.net.httpserver.HttpHandler;
23+
import dev.katsute.simplehttpserver.SimpleHttpExchange;
24+
import dev.katsute.simplehttpserver.SimpleHttpHandler;
25+
26+
import java.io.IOException;
27+
import java.util.function.Predicate;
28+
29+
public class SimplePredicateHandler implements SimpleHttpHandler {
30+
31+
private final HttpHandler T, F;
32+
private final Predicate<SimpleHttpExchange> predicate;
33+
34+
public SimplePredicateHandler(final Predicate<SimpleHttpExchange> predicate, final HttpHandler handlerIfTrue, HttpHandler handlerIfFalse){
35+
this.T = handlerIfTrue;
36+
this.F = handlerIfFalse;
37+
this.predicate = predicate;
38+
}
39+
40+
@Override
41+
public final void handle(final HttpExchange exchange) throws IOException{
42+
SimpleHttpHandler.super.handle(exchange);
43+
}
44+
45+
@Override
46+
public final void handle(final SimpleHttpExchange exchange) throws IOException{
47+
(predicate.test(exchange) ? T : F).handle(exchange);
48+
}
49+
50+
}

0 commit comments

Comments
 (0)