Skip to content

Commit b82ea3d

Browse files
oka1125jihoonl
authored andcommitted
fix multipart_stream.cpp HttpHeader values in order to solve DOMException(cross origin) CORS issue (#92)
1 parent 4ab9568 commit b82ea3d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/multipart_stream.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ void MultipartStream::sendInitialHeader() {
1616
"Server", "web_video_server").header("Cache-Control",
1717
"no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0").header(
1818
"Pragma", "no-cache").header("Content-type", "multipart/x-mixed-replace;boundary="+boundry_).header(
19-
"Access-Control-Allow-Origin", "*").write(connection_);
19+
"Access-Control-Allow-Origin", "*").header("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,HEAD,OPTIONS").header(
20+
"Access-Control-Allow-Headers", "Origin, Authorization, Accept, Content-Type").header("Access-Control-Max-Age", "3600").write(connection_);
2021
connection_->write("--"+boundry_+"\r\n");
2122
}
2223

@@ -27,6 +28,10 @@ void MultipartStream::sendPartHeader(const ros::Time &time, const std::string& t
2728
new std::vector<async_web_server_cpp::HttpHeader>());
2829
headers->push_back(async_web_server_cpp::HttpHeader("Content-type", type));
2930
headers->push_back(async_web_server_cpp::HttpHeader("X-Timestamp", stamp));
31+
headers->push_back(async_web_server_cpp::HttpHeader("Access-Control-Allow-Origin", "*"));
32+
headers->push_back(async_web_server_cpp::HttpHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,HEAD,OPTIONS"));
33+
headers->push_back(async_web_server_cpp::HttpHeader("Access-Control-Allow-Headers", "Origin, Authorization, Accept, Content-Type"));
34+
headers->push_back(async_web_server_cpp::HttpHeader("Access-Control-Max-Age", "3600"));
3035
headers->push_back(
3136
async_web_server_cpp::HttpHeader("Content-Length", boost::lexical_cast<std::string>(payload_size)));
3237
connection_->write(async_web_server_cpp::HttpReply::to_buffers(*headers), headers);

0 commit comments

Comments
 (0)