ฉันเริ่มใช้เซิร์ฟเวอร์ตัวอย่าง (ใน netty) เพื่อรองรับ 100 ดำเนินการต่อ ฉันสับสนเมื่ออ่านส่วน RCF2616 8.2.3 มันบอกว่า
เมื่อได้รับคำขอซึ่งรวมถึงฟิลด์ Expect request-header พร้อมด้วยความคาดหวัง "100-continue" เซิร์ฟเวอร์ต้นทางจะต้องตอบสนองด้วยสถานะ 100 (ดำเนินการต่อ) และอ่านต่อจากสตรีมอินพุต หรือตอบกลับด้วยรหัสสถานะสุดท้าย เซิร์ฟเวอร์ต้นทางจะต้องไม่รอเนื้อหาคำขอก่อนส่งการตอบกลับ 100 (ดำเนินการต่อ) หากตอบสนองด้วยรหัสสถานะสุดท้าย อาจปิดการเชื่อมต่อการขนส่งหรืออาจอ่านและละทิ้งคำขอส่วนที่เหลือต่อไป จะต้องไม่ดำเนินการตามที่ร้องขอหากส่งคืนรหัสสถานะสุดท้าย
เซิร์ฟเวอร์ต้นทางจะต้องไม่รอเนื้อหาคำขอก่อนที่จะส่งการตอบสนอง 100 (ดำเนินการต่อ) เซิร์ฟเวอร์ของฉันควรตรวจสอบส่วนหัวก่อนแล้วจึงส่งรหัสสถานะ 100 (ดำเนินการต่อ) หรือทันที ส่งรหัสสถานะ 100 ?
โปรดชี้แจงพฤติกรรมที่แท้จริงของเซิร์ฟเวอร์ http เพื่อรองรับ 100 ต่อไป
ขณะนี้นี่คือ channelRead
ของฉัน
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof HttpRequest) {
HttpRequest req = (HttpRequest) msg;
request = req;
if (req.getMethod() != HttpMethod.POST) {
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, METHOD_NOT_ALLOWED);
ctx.write(response).addListener(ChannelFutureListener.CLOSE);
} else {
boolean valid = false;
for (Map.Entry<String, String> header : req.headers()) {
if (header.getKey().equals("my-special-header")) {
valid = true;
break;
}
}
if (!valid) {
FullHttpResponse resp = new DefaultFullHttpResponse(HTTP_1_1, BAD_REQUEST);
ctx.write(resp).addListener(ChannelFutureListener.CLOSE);
} else {
if (HttpHeaders.is100ContinueExpected(request)) {
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE));
}
}
}
} else if (msg instanceof LastHttpContent && msg != LastHttpContent.EMPTY_LAST_CONTENT) {
DefaultLastHttpContent content = (DefaultLastHttpContent) msg;
System.out.println("content read");
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, content.content());
response.headers().set(CONTENT_TYPE, "text/plain");
response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
boolean keepAlive =HttpHeaders.isKeepAlive(request);
if (!keepAlive) {
ctx.write(response).addListener(ChannelFutureListener.CLOSE);
} else {
response.headers().set(CONNECTION, Values.KEEP_ALIVE);
ctx.write(response);
}
}
}
The origin server must not wait for the message body before sending the 100 (Continue) response.
ขณะนี้การใช้งานของฉันตรวจสอบส่วนหัวที่ถูกต้องและส่ง 100 หรือคำขอที่ไม่ถูกต้อง - person user392919   schedule 28.09.2015