Skip to content

Commit db503d3

Browse files
committed
was/async/SimpleHandler: move struct SimpleResponse to a separate header
1 parent c97db1d commit db503d3

13 files changed

Lines changed: 54 additions & 26 deletions

demo/was/BadRequest.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// author: Max Kellermann <max.kellermann@ionos.com>
44

55
#include "was/async/CoRun.hxx"
6+
#include "was/async/SimpleResponse.hxx"
67
#include "was/ExceptionResponse.hxx"
78
#include "event/Loop.hxx"
89
#include "uri/MapQueryString.hxx"

demo/was/CoMirror.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// author: Max Kellermann <max.kellermann@ionos.com>
44

55
#include "was/async/CoRun.hxx"
6+
#include "was/async/SimpleResponse.hxx"
67
#include "event/Loop.hxx"
78
#include "util/PrintException.hxx"
89
#include "DefaultFifoBuffer.hxx"

demo/was/CoSleepMirror.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// author: Max Kellermann <max.kellermann@ionos.com>
44

55
#include "was/async/CoRun.hxx"
6+
#include "was/async/SimpleResponse.hxx"
67
#include "event/co/Sleep.hxx"
78
#include "event/Loop.hxx"
89
#include "util/PrintException.hxx"

demo/was/Json.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// author: Max Kellermann <max.kellermann@ionos.com>
44

55
#include "was/async/CoRun.hxx"
6+
#include "was/async/SimpleResponse.hxx"
67
#include "was/async/nlohmann_json/Read.hxx"
78
#include "was/async/nlohmann_json/Write.hxx"
89
#include "lib/nlohmann_json/ToDisposableBuffer.hxx"

demo/was/Mirror.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// author: Max Kellermann <max.kellermann@ionos.com>
44

55
#include "was/async/SimpleRun.hxx"
6+
#include "was/async/SimpleResponse.hxx"
67
#include "was/async/SimpleServer.hxx"
78
#include "event/Loop.hxx"
89
#include "util/PrintException.hxx"

src/was/async/CoHandler.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// author: Max Kellermann <max.kellermann@ionos.com>
44

55
#include "CoHandler.hxx"
6+
#include "SimpleResponse.hxx"
67
#include "SimpleServer.hxx"
78
#include "was/ExceptionResponse.hxx"
89
#include "co/InvokeTask.hxx"

src/was/async/CoRun.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "CoRun.hxx"
66
#include "CoHandler.hxx"
77
#include "SimpleRun.hxx"
8+
#include "SimpleResponse.hxx"
89

910
#include <functional>
1011

src/was/async/SimpleClient.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// author: Max Kellermann <max.kellermann@ionos.com>
44

55
#include "SimpleClient.hxx"
6+
#include "SimpleHandler.hxx"
67
#include "SimpleOutput.hxx"
78
#include "Socket.hxx"
89
#include "net/SocketProtocolError.hxx"

src/was/async/SimpleClient.hxx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#pragma once
66

7-
#include "SimpleHandler.hxx"
7+
#include "SimpleResponse.hxx"
88
#include "Control.hxx"
99
#include "Output.hxx"
1010
#include "SimpleInput.hxx"
@@ -16,6 +16,8 @@ struct WasSocket;
1616

1717
namespace Was {
1818

19+
struct SimpleRequest;
20+
1921
class SimpleClientHandler {
2022
public:
2123
virtual void OnWasError(std::exception_ptr error) noexcept = 0;

src/was/async/SimpleHandler.hxx

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#pragma once
66

77
#include "http/Method.hxx"
8-
#include "http/Status.hxx"
98
#include "util/DisposableBuffer.hxx"
109

1110
#include <map>
@@ -15,6 +14,9 @@ class CancellablePointer;
1514

1615
namespace Was {
1716

17+
struct SimpleResponse;
18+
class SimpleServer;
19+
1820
struct SimpleRequest {
1921
std::string remote_host;
2022
std::map<std::string, std::string, std::less<>> parameters;
@@ -32,29 +34,6 @@ struct SimpleRequest {
3234
bool IsContentType(const std::string_view expected) const noexcept;
3335
};
3436

35-
struct SimpleResponse {
36-
HttpStatus status = HttpStatus::OK;
37-
std::multimap<std::string, std::string, std::less<>> headers;
38-
DisposableBuffer body;
39-
40-
void SetTextPlain(std::string_view _body) noexcept {
41-
body = {ToNopPointer(_body.data()), _body.size()};
42-
headers.emplace("content-type", "text/plain");
43-
}
44-
45-
static SimpleResponse MethodNotAllowed(std::string allow) noexcept {
46-
return {
47-
HttpStatus::METHOD_NOT_ALLOWED,
48-
std::multimap<std::string, std::string, std::less<>>{
49-
{"allow", std::move(allow)},
50-
},
51-
nullptr,
52-
};
53-
}
54-
};
55-
56-
class SimpleServer;
57-
5837
class SimpleRequestHandler {
5938
public:
6039
/**

0 commit comments

Comments
 (0)