Skip to content
This repository was archived by the owner on Jul 31, 2022. It is now read-only.

Commit d15bc78

Browse files
authored
Remove HTTPCode #112 (#113)
1 parent a96ae6b commit d15bc78

File tree

9 files changed

+18
-107
lines changed

9 files changed

+18
-107
lines changed

src/main/java/com/kttdevelopment/simplehttpserver/SimpleHttpExchange.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.kttdevelopment.simplehttpserver;
22

3-
import com.kttdevelopment.simplehttpserver.var.HttpCode;
43
import com.kttdevelopment.simplehttpserver.var.RequestMethod;
54
import com.sun.net.httpserver.*;
65

@@ -283,7 +282,7 @@ static SimpleHttpExchange create(final HttpExchange exchange){
283282
*
284283
* @return response code
285284
*
286-
* @see HttpCode
285+
* @see java.net.HttpURLConnection
287286
* @see #sendResponseHeaders(int, long)
288287
* @since 02.00.00
289288
* @author Ktt Development
@@ -354,7 +353,7 @@ static SimpleHttpExchange create(final HttpExchange exchange){
354353
* @throws IOException internal server error
355354
*
356355
* @see #getResponseHeaders()
357-
* @see HttpCode
356+
* @see java.net.HttpURLConnection
358357
* @since 02.00.00
359358
* @author Ktt Development
360359
*/

src/main/java/com/kttdevelopment/simplehttpserver/SimpleHttpExchangeImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,12 @@ public synchronized final void send(final int responseCode) throws IOException{
361361

362362
@Override
363363
public synchronized final void send(final byte[] response) throws IOException{
364-
send(response, HttpCode.HTTP_OK, false);
364+
send(response, HttpURLConnection.HTTP_OK, false);
365365
}
366366

367367
@Override
368368
public final void send(final byte[] response, final boolean gzip) throws IOException{
369-
send(response, HttpCode.HTTP_OK, gzip);
369+
send(response, HttpURLConnection.HTTP_OK, gzip);
370370
}
371371

372372
@Override
@@ -397,12 +397,12 @@ public final void send(final byte[] response, final int responseCode, final bool
397397

398398
@Override
399399
public synchronized final void send(final String response) throws IOException{
400-
send(response.getBytes(StandardCharsets.UTF_8), HttpCode.HTTP_OK, false);
400+
send(response.getBytes(StandardCharsets.UTF_8), HttpURLConnection.HTTP_OK, false);
401401
}
402402

403403
@Override
404404
public final void send(final String response, final boolean gzip) throws IOException{
405-
send(response.getBytes(StandardCharsets.UTF_8), HttpCode.HTTP_OK, gzip);
405+
send(response.getBytes(StandardCharsets.UTF_8), HttpURLConnection.HTTP_OK, gzip);
406406
}
407407

408408
@Override

src/main/java/com/kttdevelopment/simplehttpserver/handler/FileHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package com.kttdevelopment.simplehttpserver.handler;
22

33
import com.kttdevelopment.simplehttpserver.*;
4-
import com.kttdevelopment.simplehttpserver.var.HttpCode;
54
import com.sun.net.httpserver.HttpExchange;
65

76
import java.io.*;
7+
import java.net.HttpURLConnection;
88
import java.net.URLDecoder;
99
import java.nio.charset.StandardCharsets;
1010
import java.util.*;
1111
import java.util.concurrent.ConcurrentHashMap;
12-
import java.util.concurrent.atomic.AtomicBoolean;
1312
import java.util.function.Consumer;
1413

1514
/**
@@ -946,7 +945,7 @@ public final void handle(final HttpExchange exchange) throws IOException{
946945
* @author Ktt Development
947946
*/
948947
public void handle(final SimpleHttpExchange exchange, final File source, final byte[] bytes) throws IOException {
949-
exchange.send(bytes, HttpCode.HTTP_OK);
948+
exchange.send(bytes, HttpURLConnection.HTTP_OK);
950949
}
951950

952951
//

src/main/java/com/kttdevelopment/simplehttpserver/handler/RedirectHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.kttdevelopment.simplehttpserver.handler;
22

3-
import com.kttdevelopment.simplehttpserver.var.HttpCode;
43
import com.kttdevelopment.simplehttpserver.SimpleHttpExchange;
54
import com.kttdevelopment.simplehttpserver.SimpleHttpHandler;
65
import com.sun.net.httpserver.HttpExchange;
76

87
import java.io.IOException;
8+
import java.net.HttpURLConnection;
99

1010
/**
1111
* A request handler that redirects to a different URL without pushing to the history. The URL may not work correctly if it does not have a valid authority (<code>http</code>/<code>https</code>).
@@ -40,7 +40,7 @@ public final void handle(final HttpExchange exchange) throws IOException{
4040
@Override
4141
public final void handle(final SimpleHttpExchange exchange) throws IOException{
4242
exchange.getResponseHeaders().set("Location", link);
43-
exchange.send(HttpCode.HTTP_Found);
43+
exchange.send(HttpURLConnection.HTTP_OK);
4444
exchange.close();
4545
}
4646

src/main/java/com/kttdevelopment/simplehttpserver/handler/SSEHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import com.kttdevelopment.simplehttpserver.SimpleHttpExchange;
44
import com.kttdevelopment.simplehttpserver.SimpleHttpHandler;
5-
import com.kttdevelopment.simplehttpserver.var.HttpCode;
65
import com.kttdevelopment.simplehttpserver.var.RequestMethod;
76
import com.sun.net.httpserver.HttpExchange;
87

98
import java.io.IOException;
109
import java.io.OutputStream;
10+
import java.net.HttpURLConnection;
1111
import java.nio.charset.StandardCharsets;
1212
import java.util.*;
1313
import java.util.concurrent.TimeUnit;
@@ -42,7 +42,7 @@ public final void handle(final SimpleHttpExchange exchange) throws IOException{
4242
exchange.getResponseHeaders().add("Cache-Control","no-cache");
4343

4444
if(exchange.getRequestMethod() == RequestMethod.OPTIONS){
45-
exchange.sendResponseHeaders(HttpCode.HTTP_OK, 0);
45+
exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, 0);
4646
return;
4747
}
4848

src/main/java/com/kttdevelopment/simplehttpserver/var/HttpCode.java

Lines changed: 0 additions & 87 deletions
This file was deleted.

src/test/java/com/kttdevelopment/simplehttpserver/handlers/RedirectHandlerTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import com.kttdevelopment.simplehttpserver.*;
44
import com.kttdevelopment.simplehttpserver.handler.RedirectHandler;
5-
import com.kttdevelopment.simplehttpserver.var.HttpCode;
65
import org.junit.jupiter.api.Assertions;
76
import org.junit.jupiter.api.Test;
87

98
import java.io.IOException;
9+
import java.net.HttpURLConnection;
1010
import java.net.URI;
1111
import java.net.http.*;
1212
import java.util.concurrent.ExecutionException;
@@ -36,7 +36,7 @@ public final void redirectToGoogle() throws IOException, ExecutionException, Int
3636
final int response = client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
3737
.thenApply(HttpResponse::statusCode).get();
3838

39-
Assertions.assertEquals(HttpCode.HTTP_OK, response, "Client responded with redirect code (302 HTTP FOUND) not 200 HTTP OK");
39+
Assertions.assertEquals(HttpURLConnection.HTTP_OK, response, "Client responded with redirect code (302 HTTP FOUND) not 200 HTTP OK");
4040

4141
server.stop();
4242
}

src/test/java/com/kttdevelopment/simplehttpserver/simplehttpexchange/SimpleHttpExchangeReadTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.kttdevelopment.simplehttpserver.simplehttpexchange;
22

33
import com.kttdevelopment.simplehttpserver.*;
4-
import com.kttdevelopment.simplehttpserver.var.HttpCode;
54
import com.sun.net.httpserver.HttpContext;
65
import org.junit.jupiter.api.Assertions;
76
import org.junit.jupiter.api.Test;
87

98
import java.io.IOException;
9+
import java.net.HttpURLConnection;
1010
import java.net.URI;
1111
import java.net.http.*;
1212
import java.util.concurrent.ExecutionException;
@@ -65,7 +65,7 @@ public final void read() throws IOException, InterruptedException, ExecutionExce
6565
Assertions.assertFalse(exchange.hasGet(), "Client did not send a GET request");
6666
Assertions.assertFalse(exchange.hasPost(), "Client did not send a POST request");
6767

68-
Assertions.assertEquals(HttpCode.HTTP_OK, exchange.getResponseCode(), "Successful exchange should've sent 200 HTTP OK");
68+
Assertions.assertEquals(HttpURLConnection.HTTP_OK, exchange.getResponseCode(), "Successful exchange should've sent 200 HTTP OK");
6969

7070
Assertions.assertTrue(exchange.getCookies().isEmpty(), "Client did not send any cookies");
7171

src/test/java/com/kttdevelopment/simplehttpserver/simplehttpexchange/io/SimpleHttpExchangeSendTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import com.kttdevelopment.simplehttpserver.SimpleHttpHandler;
44
import com.kttdevelopment.simplehttpserver.SimpleHttpServer;
5-
import com.kttdevelopment.simplehttpserver.var.HttpCode;
65
import org.junit.jupiter.api.Assertions;
76
import org.junit.jupiter.api.Test;
87
import org.junit.jupiter.api.io.TempDir;
98

109
import java.io.File;
1110
import java.io.IOException;
11+
import java.net.HttpURLConnection;
1212
import java.net.URI;
1313
import java.net.http.*;
1414
import java.nio.file.Files;
@@ -27,7 +27,7 @@ public final void sendTest() throws IOException{
2727
final SimpleHttpServer server = SimpleHttpServer.create(port);
2828
final String context = "";
2929

30-
final int testCode = HttpCode.HTTP_Accepted;
30+
final int testCode = HttpURLConnection.HTTP_ACCEPTED;
3131
final String testContent = String.valueOf(System.currentTimeMillis());
3232

3333
server.createContext("code", (SimpleHttpHandler) exchange -> {

0 commit comments

Comments
 (0)