Beispiel #1
0
// WriteHeader is used to set the HTTP status code.
func (s *ResponseStream) WriteHeader(code int) {
	if s.unidirectional {
		log.Println("Error: Stream is unidirectional.")
		return
	}

	if s.wroteHeader {
		log.Println("Error: Multiple calls to ResponseWriter.WriteHeader.")
		return
	}

	s.wroteHeader = true
	s.responseCode = code
	s.header.Set("status", strconv.Itoa(code))
	s.header.Set("version", "HTTP/1.1")

	// Create the response SYN_REPLY.
	synReply := new(frames.SYN_REPLY)
	synReply.StreamID = s.streamID
	synReply.Header = common.CloneHeader(s.header)

	// Clear the headers that have been sent.
	for name := range synReply.Header {
		s.header.Del(name)
	}

	// These responses have no body, so close the stream now.
	if code == 204 || code == 304 || code/100 == 1 {
		synReply.Flags = common.FLAG_FIN
		s.state.CloseHere()
	}

	s.output <- synReply
}
Beispiel #2
0
// writeHeader is used to send HTTP headers to
// the client.
func (p *PushStream) writeHeader() {
	if len(p.header) == 0 || p.closed() {
		return
	}

	header := new(frames.HEADERS)
	header.StreamID = p.streamID
	header.Header = common.CloneHeader(p.header)
	for name := range header.Header {
		p.header.Del(name)
	}
	p.output <- header
}
Beispiel #3
0
// writeHeader is used to flush HTTP headers.
func (s *ResponseStream) writeHeader() {
	if len(s.header) == 0 || s.unidirectional {
		return
	}

	// Create the HEADERS frame.
	header := new(frames.HEADERS)
	header.StreamID = s.streamID
	header.Header = common.CloneHeader(s.header)

	// Clear the headers that have been sent.
	for name := range header.Header {
		s.header.Del(name)
	}

	s.output <- header
}