Fix Protobuf support - HTTP headers already written
Prior to this commit, the `ProtobufHttpMessageConverter` would call `outputMessage.getBody()` at the beginning of the `writeInternal` method, thus writing HTTP headers. Since this method is trying to write "x-protobuf" headers after that, protobuf support wasn't working properly for the default "x-protobuf" media type. Thanks Toshiaki Maki for the repro project! Also fixed: * improve `MockHttpOutputMessage` behavior to reproduce the read-only state of HTTP headers once they've been written. Issue: SPR-12229
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,17 +32,21 @@ public class MockHttpOutputMessage implements HttpOutputMessage {
|
||||
|
||||
private final ByteArrayOutputStream body = spy(new ByteArrayOutputStream());
|
||||
|
||||
private boolean headersWritten = false;
|
||||
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
return headers;
|
||||
return (this.headersWritten ? HttpHeaders.readOnlyHttpHeaders(this.headers) : this.headers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getBody() throws IOException {
|
||||
this.headersWritten = true;
|
||||
return body;
|
||||
}
|
||||
|
||||
public byte[] getBodyAsBytes() {
|
||||
this.headersWritten = true;
|
||||
return body.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user