update
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||
import * as plugins from '../ts/plugins.js';
|
||||
import { SmartProxy } from '../ts/index.js';
|
||||
import { SmartProxy, SocketHandlers } from '../ts/index.js';
|
||||
|
||||
tap.test('should handle HTTP requests on port 80 for ACME challenges', async (tools) => {
|
||||
tools.timeout(10000);
|
||||
@ -17,22 +17,19 @@ tap.test('should handle HTTP requests on port 80 for ACME challenges', async (to
|
||||
path: '/.well-known/acme-challenge/*'
|
||||
},
|
||||
action: {
|
||||
type: 'static' as const,
|
||||
handler: async (context) => {
|
||||
type: 'socket-handler' as const,
|
||||
socketHandler: SocketHandlers.httpServer((req, res) => {
|
||||
handledRequests.push({
|
||||
path: context.path,
|
||||
method: context.method,
|
||||
headers: context.headers
|
||||
path: req.url,
|
||||
method: req.method,
|
||||
headers: req.headers
|
||||
});
|
||||
|
||||
// Simulate ACME challenge response
|
||||
const token = context.path?.split('/').pop() || '';
|
||||
return {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'text/plain' },
|
||||
body: `challenge-response-for-${token}`
|
||||
};
|
||||
}
|
||||
const token = req.url?.split('/').pop() || '';
|
||||
res.header('Content-Type', 'text/plain');
|
||||
res.send(`challenge-response-for-${token}`);
|
||||
})
|
||||
}
|
||||
}
|
||||
]
|
||||
@ -79,17 +76,18 @@ tap.test('should parse HTTP headers correctly', async (tools) => {
|
||||
ports: [18081]
|
||||
},
|
||||
action: {
|
||||
type: 'static' as const,
|
||||
handler: async (context) => {
|
||||
Object.assign(capturedContext, context);
|
||||
return {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
received: context.headers
|
||||
})
|
||||
};
|
||||
}
|
||||
type: 'socket-handler' as const,
|
||||
socketHandler: SocketHandlers.httpServer((req, res) => {
|
||||
Object.assign(capturedContext, {
|
||||
path: req.url,
|
||||
method: req.method,
|
||||
headers: req.headers
|
||||
});
|
||||
res.header('Content-Type', 'application/json');
|
||||
res.send(JSON.stringify({
|
||||
received: req.headers
|
||||
}));
|
||||
})
|
||||
}
|
||||
}
|
||||
]
|
||||
|
Reference in New Issue
Block a user