Class KHTTPServerThread
java.lang.Object
java.lang.Thread
ch.k43.util.KSocketServerThread
ch.k43.util.KHTTPServerThread
- All Implemented Interfaces:
AutoCloseable,Runnable
- Direct Known Subclasses:
KHTTPServerThreadSample
Class to handle user HTTP connections accepted by KSocketServerListener. The user class needs to override the default implementations
for the HTTP methods get(), put(), etc.
The HTTP response headers Date, Server, Content-Type, Content-Length and Connection are automatically provided unless overridden
thru setResponseHeaders().
- Since:
- 2025.04.13
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Method Summary
Modifier and TypeMethodDescriptionvoidHTTP CONNECT method.voidHTTP DELETE method.voidHTTP GET method.intGet maximum size of payload to be read.Get HTTP request headers.voidHTTP HEAD method.voidHTTP OPTIONS method.voidHTTP PATCH method.voidHTTP POST method.voidHTTP PUT method.voidrun()Thread main entry point (called by KSocketServerListener).booleanSend file.booleanSend file.booleanSend HTML string.booleanSend text string.booleanSend text string.voidsetMaxPayloadSize(int argMaxSize) Set maximum payload size to be read (default is 50 MiB).voidsetResponseHeaders(Properties argHeaders) Set additional headers to be sent in HTTP response.toString()String representation of object.voidHTTP TRACE method.Methods inherited from class ch.k43.util.KSocketServerThread
close, getAuthenticatedClient, getAuthenticatedClientCN, getCiphers, getLastError, getProtocol, isConnected, isDataAvailable, isSecuredConnection, read, readLine, write, write, write, writeLineMethods inherited from class java.lang.Thread
activeCount, checkAccess, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, threadId, yield
-
Method Details
-
delete
HTTP DELETE method. Override this method to implement it.- Parameters:
argURL- Passed URL e.g. "/test/s=any"argPayload- HTTP payload passed with HTTP request
-
get
HTTP GET method. Override this method to implement it.- Parameters:
argURL- Passed URL e.g. "/test/s=any"
-
getMaxPayloadSize
public int getMaxPayloadSize()Get maximum size of payload to be read.- Returns:
- Size of maximum payload
-
getRequestHeaders
-
head
HTTP HEAD method. Override this method to implement it.- Parameters:
argURL- Passed URL e.g. "/test/s=any"
-
options
HTTP OPTIONS method. Override this method to implement it.- Parameters:
argURL- Passed URL e.g. "/test/s=any"argPayload- HTTP payload passed with HTTP request
-
connect
HTTP CONNECT method. Override this method to implement it.- Parameters:
argURL- Passed URL e.g. "/test/s=any"argPayload- HTTP payload passed with HTTP request
-
patch
HTTP PATCH method. Override this method to implement it.- Parameters:
argURL- Passed URL e.g. "/test/s=any"argPayload- HTTP payload passed with HTTP request
-
post
HTTP POST method. Override this method to implement it.- Parameters:
argURL- Passed URL e.g. "/test/s=any"argPayload- HTTP payload passed with HTTP request
-
put
HTTP PUT method. Override this method to implement it.- Parameters:
argURL- Passed URL e.g. "/test/s=any"argPayload- HTTP payload passed with HTTP request
-
run
public void run()Thread main entry point (called by KSocketServerListener).- Specified by:
runin interfaceRunnable- Overrides:
runin classKSocketServerThread
-
sendFile
Send file.- Parameters:
argFileName- Name (and path) of file to be sent.- Returns:
- True for success, false otherwise
-
sendFile
Send file.- Parameters:
argFileName- Name (and path) of file to be sentargDownload- Tell client (browser) to locally save the file- Returns:
- True for success, false otherwise
-
sendHTML
-
sendText
-
sendText
-
setMaxPayloadSize
public void setMaxPayloadSize(int argMaxSize) Set maximum payload size to be read (default is 50 MiB).- Parameters:
argMaxSize- Maximum payload size
-
setResponseHeaders
Set additional headers to be sent in HTTP response.- Parameters:
argHeaders- HTTP response header(s)
-
toString
String representation of object.- Overrides:
toStringin classKSocketServerThread
-
trace
HTTP TRACE method. Override this method to implement it.- Parameters:
argURL- Passed URL e.g. "/test/s=any"argPayload- HTTP payload passed with HTTP request
-