Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

26
LINES

< > BotCompany Repo | #1033324 // HandleProxyRequest

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (14441L/87K).

sclass HandleProxyRequest {
  HostAndPort hap;
  bool rewriteHost; // unused?
  bool rewritePort;
  NanoHTTPD.IHTTPSession session;
  IVF1<StandaloneHttpProxy.Request> customizeRequest;
  
  new StandaloneHttpProxy proxy;
  
  run ctex {
    S headers = windowsLineBreaks(lines(concatLists(
      ll(session.getMethod() + " " + session.getFullURI() + " " + session.getProtocolVersion()),
      withoutStartingWithIC("Host:", session.getHeaderLines())
    )));
    
    S domain = dropPortFromHost(mapGet(session.getHeaders(), "host"));
    
    proxy.rewriteHostHeader = rewritePort;
    proxy.forwardServerAndPort = req -> hap;
    proxy.takeOverIncomingSocket(domain, session.getSocket(),
      session.getInputStream(),
      session.getOutputStream(),
      toUtf8(printQuoted("HEADERS: ", headers)),
      customizeRequest);
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033324
Snippet name: HandleProxyRequest
Eternal ID of this version: #1033324/5
Text MD5: 8fa6b546515d66e4f4dc2173e11f6401
Transpilation MD5: 5997e857a0b54052cf39156ef0544432
Author: stefan
Category: javax / gazelle v
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-04-17 20:20:36
Source code size: 860 bytes / 26 lines
Pitched / IR pitched: No / No
Views / Downloads: 192 / 308
Version history: 4 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)