Exemple #1
0
func (t *TCPMessage) check100Continue() {
	if t.expectType != httpExpectNotSet || len(t.packets[0].Data) < 25 {
		return
	}

	if t.methodType != httpMethodWithBody {
		return
	}

	if t.seqMissing || t.headerPacket == -1 {
		return
	}

	last := t.packets[len(t.packets)-1]
	// reading last 4 bytes for double CRLF
	if !bytes.HasSuffix(last.Data, bEmptyLine) {
		return
	}

	var expectB []byte
	proto.ParseHeaders(t.packetsData(), func(header, value []byte) bool {
		if proto.HeadersEqual(header, bExpectHeader) {
			expectB = value
			return false
		}

		return true
	})

	if len(expectB) > 0 && bytes.Equal(bExpect100Value, expectB) {
		t.expectType = httpExpect100Continue
		return
	}

	t.expectType = httpExpectEmpty
}
Exemple #2
0
func (t *TCPMessage) updateBodyType() {
	// if there is cache
	if t.bodyType != httpBodyNotSet {
		return
	}

	// Headers not received
	if t.headerPacket == -1 {
		return
	}

	var lengthB, encB, connB []byte

	proto.ParseHeaders(t.packetsData(), func(header, value []byte) bool {
		if proto.HeadersEqual(header, []byte("Content-Length")) {
			lengthB = value
			return false
		}

		if proto.HeadersEqual(header, []byte("Transfer-Encoding")) {
			encB = value
			return false
		}

		if proto.HeadersEqual(header, []byte("Connection")) {
			connB = value
		}

		return true
	})

	switch t.methodType {
	case httpMethodNotFound:
		return
	case httpMethodWithoutBody:
		t.bodyType = httpBodyEmpty
		return
	case httpMethodWithBody:
		if len(lengthB) > 0 {
			t.contentLength, _ = strconv.Atoi(string(lengthB))

			if t.contentLength == 0 {
				t.bodyType = httpBodyEmpty
			} else {
				t.bodyType = httpBodyContentLength
			}
			return
		}

		if len(encB) > 0 {
			t.bodyType = httpBodyChunked
			return
		}

		if len(connB) > 0 && bytes.Equal(connB, []byte("close")) {
			t.bodyType = httpBodyConnectionClose
			return
		}
	}

	t.bodyType = httpBodyEmpty
}